Tuesday 20 June 2017

postgis - Extract lat, lon Points from Polygon



I have PostGIS database, and want to extract lat, lon pairs sequence from Polygons (and MultiPolygons). As a very fresh PostGIS user, I'm able to just extract the Polygons:


SELECT st_astext("GEOMETRY"::geometry) FROM my_postgisdb;


which outputs Polygons and MultiPoligons.


How should I extract x, y pairs from these structures?



Answer



You can use ST_DumpPoints to get the points and then ST_AsLatLonText to get nicely readable coordinate output. It doesn't care if the geometries are multi* or not.


Alternatively, you could use ST_Boundary to get the polygon vertices, but you'd need to use ST_Dump first for this to work for multipolygons too.


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