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.

2 Answers 2



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. Commented Dec 4, 2013 at 19:23

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 and acknowledge you have read our privacy policy.

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