I have a CSV with many points and attributes that I'm trying to convert into a shapefile but I'm having no luck. I have installed gdal-bin and can use my terminal environment to create a shapefile with ogr2ogr
, but I'm not getting the desired outcome. I'm running the following:
ogr2ogr -f "ESRI Shapefile" 5_2834k2-25_FAST.shp 5_2834K2-25_DataCompiled_K2.csv -progress -skipfailures -a_srs EPSG:4326 -nlt POINT
And I get:
"5_2834k2-25_FAST.prj" 1 KB
"5_2834k2-25_FAST.shp" 8 KB
"5_2834k2-25_FAST.shx" 6 KB
"5_2834k2-25_FAST.dbf" 7,625 KB
but despite having all my objects and all the features, my SHP has no geometry. It's extent is 0 and recalculating gives me NaN errors in Arc. Now my source CSV does have a lat and lon column (two separate columns) and I've tried to glean from other answers how to get ogr2ogr to see and interpret these values but I cannot.
For example, perhaps using this bit of sqlite to choose the columns:
-dialect sqlite -sql "SELECT easting_col as long, northing_col as lat, geometry FROM input"
and "SELECT lon as long [...]" from input where input is my CSV... but nope. I tried a two-step cheat, thinking I could provide the dbf or shp from the incomplete output of the first as that input in the second but no...
I've tried as well GEOMETRY=AS_XY
and I'm reading the man pages, the --long-usage
help file as well as the GDAL ogr2ogr page but I just can't come up with the proper syntax.
How can I do this? I'm very frustrated because my columns don't have elaborate names ('Lat' and 'Lon') so I figured it would be very straightforward.
"SELECT *, MakePoint(<e_col>, <n_col>) AS geometry FROM <input>"
(from the CSV).Starting with GDAL 2.1, accordingly with the GeoCSV specification, the "CoordX" or "Point(X)" type can be used to specify a column with longitude/easting values, "CoordY" or "Point(Y)" for latitude/northing values and "WKT" for geometries encoded in WKT
. Other also documented alternatives are to tell X and Y fields with open options of to write a VRT file that takes care of mapping.IDRndX latLonKey Lat Lon nomCat 1966-08-17_DS1036 1966-08-17_DS1037 1972-09-21_Landsat1 2001 -9.44507 -60.7239 Forest F F F
latLonKey Lat
is sometimes empty. it is the lat multiplied by the lon, nothing fancy. I definitely got the impression there was some auto detection of geometry @ThingumaBob, and I was trying to fulfill those requirements but obviously falling short. I'll look into a cvst file for sure, since my layout should be fairly static, thanks @AndreJ.