I have some CSV files that need to be converted to ESRI shapefile. These files are built like explained in the section "Building line geometries" from the GDAL documentation. For example one file can be like this:
> head river_xy2.csv way_id,pt_id,x,y 1,1,11.836,44.829 1,2,11.827,44.829 1,3,11.818,44.829 1,4,11.809,44.838 1,5,11.8,44.847 1,6,11.791,44.856 1,7,11.782,44.856 1,8,11.773,44.856 1,9,11.764,44.856
GDAL understands this, for example I can do:
ogrinfo river_xy2.csv -dialect SQLite -sql "SELECT way_id, MakeLine(MakePoint(CAST(x AS float),CAST(y AS float))) FROM river_xy2 GROUP BY way_id"
And I get a nice list of OGRFeatures in output. However, how can I save that to a shapefile? If I try to use GDAL_translate:
> gdal_translate -of "ESRI Shapefile" -a_srs EPSG:4326 river_xy2.csv river_xy2.shp ERROR 4: `river_xy2.csv' not recognized as a supported file format.
While if I remove the first row I get an error after the first feature:
ERROR 1: Ungridded dataset: At line 549, change of Y direction
EDIT: It looks like I can do:
ogr2ogr -dialect SQLite -sql "SELECT way_id, MakeLine(MakePoint(CAST(x AS float),CAST(y AS float))) FROM river_xy GROUP BY way_id" -a_srs EPSG:4326 river_xy.shp river_xy.csv