Tuesday, 13 December 2016

Add X, Y column to a ESRI shapefile using ogr2ogr


I've a point ESRI shapefile in ESPG32632 spatial reference.



I need to add X and Y column to it and I'd like to use something from command line like ogr2ogr but I don't know the syntax.


Any example?



Answer



Use the OGR SQL http://www.gdal.org/ogr_sql.html and add X and Y columns with


ogrinfo foo.shp -sql "alter table foo add column X double" 
ogrinfo foo.shp -sql "alter table foo add column Y double"

Then switch to SQLite dialect http://www.gdal.org/ogr_sql_sqlite.html


ogrinfo foo.shp -dialect SQLite -sql "update foo set X=ST_X(geometry)"
ogrinfo foo.shp -dialect SQLite -sql "update foo set Y=ST_Y(geometry)"

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...