0

How can I convert a WKT string to a WKB byte[] in Java using PostGIS functions? I need to save that WKT string in a PostGIS database (geometry column.

1

http://postgis.net/docs/manual-1.5/ch04.html#OpenGISWKBWKT

says that you can convert it like that in both ways:

bytea WKB = ST_AsBinary(geometry);
text WKT = ST_AsText(geometry);
geometry = ST_GeomFromWKB(bytea WKB, SRID);
geometry = ST_GeometryFromText(text WKT, SRID);
  • You want the last of these, just use ST_GeometryFromText and let the database handle the text to binary conversion for you implicitly. – Paul Ramsey Dec 4 '13 at 19:23
0

If you need to save WKT in geometry column, you can do this in pure SQL using ST_GeomFromText function. Look at the docs to see the possible options.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.