1

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?

3
  • 1
    What have you tried? Placing your best effort in the question allows other to identify your mistake, not create a potentially inappropriate example. Please edit the question to specify the topology type of the source shapefile.
    – Vince
    Apr 12 '17 at 19:07
  • Sorry @Vince for the generic question ... I've a point shapefile in EPSG32632 ... I know how to do it for example in spatialite but I've to do it using something from command line so I've thought to ogr2ogr ...
    – Cesare
    Apr 12 '17 at 19:10
  • 1
    Please edit the question in response to requests for clarification. It's not fair to those who would answer your question to have to min the comments for critical information. Even though you've been here a while, you still haven't take the Tour, which explains your responsibilities as someone asking a question.
    – Vince
    Apr 12 '17 at 19:43
4

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)"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.