Saturday 16 March 2019

How to convert a PostGIS geometry stored as text back into a geometry?


I have a geometry column stored as text e.g.:


'010100002091080000000000804D624041000000C066735741' 


in PostgreSQL db with PostGIS. This for a point geometry with the EPSG:2193.


How do I convert this text column to a geometry column?


I have seen this question which is essentially the same, but the answer does not work.



Answer



Simply:


ALTER TABLE opr_records ALTER COLUMN geom TYPE Geometry USING geom::Geometry;

Or this if you're using a specific geometry (the post you linked to was using point) and SRID (4326 here):


ALTER TABLE opr_records ALTER COLUMN geom TYPE Geometry(POINT, 4326) USING ST_SetSRID(geom::Geometry,4326);

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