# # This program splits segments of CPRM files converted with ogr2ogr into different files by lithology type. It creates a folder containing the different lithology files ready to plot with GMT. # The same program can be used to split the files corresponding to structures, hydrography, etc. # # To download the geology vectorial files, go to: # http://geobank.sa.cprm.gov.br/ # then click on DOWNLOADS and download the vectorial files that you need. # # Requires to have the command ogr2ogr installed. In order to istall this (GDAL package), type on a terminal (Ubuntu): # % sudo add-apt-repository ppa:ubuntugis/ppa && sudo apt-get update # % sudo apt-get install gdal-bin ###################### # # To convert your downloaded .shp file into a GMT-readable ascii file, type: # % ogr2ogr -f "GMT" "TEMP.GMT" # # Then copy this script into the folder with your TEMP.GMT file and type: # % awk -f split.awk TEMP.GMT # # # MB @ 29-10-2013 # ## Plotting the ploygone... # An example of a line that plots a polygon with psxy in GMT can be: # psxy -J -R -K -O -m -W -Gp200/44:FblueBlightblue NP2ljc.xy >>$ps ## Do not forget the -m option, as it tells the program that the input poygon file contains multiple segments separated by a record whose first character is '>' BEGIN { ## Initial Block # Configuration options FOLDER="lito_gmt"; ## Don't change from here ## Make the outputfolder cmd=sprintf("mkdir -p \"%s\"",FOLDER); system(cmd); ## Set the separator and initialize the filename FS="|"; OFS="|"; filename=""; } { ## Process block ## Process a new line segment if ((NF>3) && (substr($0,3,2)=="@D")) { ## End the block if (filename != "") { printf "%05d\n",NR-1; } # Fetch a new filename description=$1; gsub("[\# @D]","",description); gsub(",","_",description); gsub(" ","_",description); gsub("ò|ó|ô|õ|ö","o",description) gsub("é|è|ẽ|ê|ë","e",description); gsub("í|ì|î|ĩ|ï","i",description); gsub("á|à|ã|â|ä","a",description); gsub("ú|ù|û|ũ|ü","a",description); gsub("ç","c",description); gsub("[\(|)]","_",description); gsub("[\:]","",description); gsub("[\"]","",description); filename=sprintf("%s/%s.xy",FOLDER,description); # Some debuging on the screen printf "From Line %05d ... (%s) ... ",NR,filename; # GMT line separator print ">" >> filename; } ## Add the content of the current line to the filename if (filename != "" ) { print $0 >> filename; } } END { ## End Block if (filename != "") { printf "%05d\n",NR-1; } }