I have a shapefile with coordinates listed in Easting and Northing in the attribute table. Is it possible to create two new fields called lat and long and populate them with values corresponding to easting and northing using ogr2ogr?
The idea is to try and get this to work without having to use a specialist GIS software and of course automation.
Answer
if you don't already have lat long coordinates in you table you can compute them using the -sql option and the sqlite dialect:
ogr2ogr centroid.shp input.shp -dialect sqlite -sql "SELECT ST_X(ST_Centroid(geometry)) as long, ST_Y(ST_Centroid(geometry)) as lat, ST_Centroid(geometry) FROM input"
If they aready exist and you just want to rename them or add them, use a similar SQL statement and alter the column name.
eg:
ogr2ogr centroid.shp input.shp -dialect sqlite -sql "SELECT easting_col as long, northing_col as lat, geometry FROM input"
No comments:
Post a Comment