Sunday 25 December 2016

latitude longitude - Populate lat/long using ogr2ogr


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

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...