Skip to content
Advertisement

Conversion of wkt to wkb in postgresql

I have a column named wkt_geometry in a table in Postgres with data converted from latitude and longitude. But I want to convert the wkt_geometry to wkb_geometry using sql commands.
If I convert it directly from Lat and long it would even better.
Also I have seen the ST_AsBinary(geometry) but I dont understand the parameters involved.

Advertisement

Answer

WKT and WKT are two formats that represent Geometry (or Geography) type.

To convert between various formats, you need to construct Geometry type and then export it to desired format. In this case ST_AsBinary(ST_GeomFromText(wkt_text)) should generally work.

If you want to produce WKB directly from lat/lng – something like ST_AsBinary(ST_MakePoint(lng, lat)) should work too. Pay attention to argument order, SQL functions use lng / lat order.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement