I’m not used to work with shapefile format and I have a bunch I’d like to process for a geologic map.
There are actually 8 file formats associated to the data :
.cpg
.dbf
.lyr
.prj
.sbn
.sbx
.shp
.shx
I think only shp and shx are useful for GMT, the others being for ArcGIS, I suspect. Again, I’m not sure… I don’t even know how to extract information properly from those.
gmt info file_2154.shp
file_2154.shp: N = 24303 <84725.096698/1201589.26104> <6032821.09236/7106074.34002>
As you can see, the units are in meter (UTM). From the documentation I know that the projection is Lambert II extended (-Jl) centred at {3ºE ; 46º30’N} (or 700000/6600000) , using Clarke-1880-IGN ellipsoïd.
In order to have a better grip on GMT, I’d like to convert the file to full WGS84 lon/lat system. When I explore the mapproject module, I got a bunch of errors, either because of the units (-R[...]+u1) or because of the projection
area="-R-22841.3905/1712212.6192/1087335.9605/2703971.1254+u1"
projection="-Jl700000/6600000/44/49/1:50000"
gmt mapproject $area $projection $data -C -E -I -F --PROJ_ELLIPSOID=Clarke-1880-IGN > test.txt
Option -R: The +u<unit> modifier only applies to projected coordinates. Your unit 1 is ignored
Ultimately, I’d like to plot all the files, associated colours to strata and everything. But for that, I need to understand how to deal with them.
Any help ?
I can provide some files if needed (shp ~20Mb , shx ~20Kb)
I tried, it doesn’t solve the issue. My text file has a first column filed with 80-ish values and a second column of zeros.
I think GMT does that under the hood.
I’m currently able to plot the shape file “as is”, but I don’t know how to handle the informations / values and so on, so I can’t associate a colour to specific entries
You can do the projection change with GDAL also. It will get the input projection information from the shapefile data automatically. Look at the options for “ogr2ogr” that can both project and convert to GMT vectors.
it’ll show layer names. then run the ogrinfo with the layer name appended to get that layer metadata. -so means “summary only”, without it ogrinfo will dump all the file/layer content on your terminal.
There should be something else right under the layer projection info, a list of contour feature parameters (set at some values for every contour).
Can be easier to run ogr2ogr exactly as gmt does under the hood and study the header of the output file and few first records. ogr2ogr -mapFieldType Integer64=Integer -skipfailures -f "OGR_GMT" "gmt_ogr_5387.gmt" "file_2154.shp"
Now you actually need to check documentation hopefully accompanying your shapefile data. Otherwise it is going to be very hard to guess the meaning of all these parameters: CODE|DESCR|TERRE_MER|CODE_LEG|NOM_SYMB|WT_SYMB|C_SYMB|M_SYMB|J_SYMB|N_SYMB
Well, DESCR must be some sort of description string. Others are not clear. Every contour header should have all these parameters set to some values (according to the value types). Once you know what exactly you want, you can extract it with something like ogr2ogr -where CODE_LEG=some_value -f GMT "gmt_ogr_5387.gmt" "file_2154.shp"
Thanks @mkononets
The doc talk about the structure of the database, but not so much about the parameters themselves. Hopefully the “description” will help !
Ok ! So another file contains actual polygons (surfaces) with explicit names. There’s a code associated starting with @ (e.g. @Dq3).
Is it possible to list all those then use [..] -where CODE=@Dq3 [...] to split the file into small bricks ?
I think you need to exclude @D, which indicates the beginning of the parameter list
try -where CODE=123 if CODE is a number (type real or integer) or -where CODE='123' if CODE is a string type
I switched to an easier test. Using ogrinfo -so I’ve isolated this one :
TERRE_MER: String (1.0)
Which has “T” or “M” as value
ogr2ogr -where TERRE_MER='T' -f GMT "file_2154.gmt" "file_2154.shp"
ERROR 1: "T" not recognised as an available field.
ERROR 1: SetAttributeFilter(TERRE_MER=T) on layer 'file_2154' failed.
gmt uses -mapFieldType Integer64=Integer to avoid Integer64 to Real conversion warnings
there’s also -skipfailures but this might not let you see if something went radically wrong.
BTW you do not necessarily have to convert to GMT format. If you leave it out and give some other .shp output filename, the result will also be in .shp format (with no potentially incompatible type conversions). However .gmt files are human-readable, which is helpful sometimes.