Search code examples
postgresqlgeometrypostgispoint

How to get lat long from HEXEWKB PostGis?


I'm making query and want get from this format points again. Is this possible? How i can do it?

UPDATE  geo2 SET geometry = ST_AsHEXEWKB(ST_GeomFromText('POLYGON((-15.66486 27.91996,-15.60610 27.91820, -15.60359 27.97169, -15.66586 27.97144,-15.66486 27.91996))',4326)) where options->>'koatuu' = '0110392101' ;

Solution

  • Yes, It's possible. You should just cast it to a geometry type with:

    SELECT ST_AsHEXEWKB(ST_GeomFromText('POLYGON((-15.66486 27.91996,-15.60610 27.91820, -15.60359 27.97169, -15.66586 27.97144,-15.66486 27.91996))',4326))::geometry FROM geo2 WHERE ....
    

    and you can get lat/long by using ST_X, ST_Y

    SELECT ST_X(your_column::geometry) as long, ST_Y(your_column::geometry) as lat FROM geo2