I have a geometry in java.lang.String format. I mean i take it directly from DB in as a java.lang.String which is stored in a variable. I want to convert it to jts Geometry type somehow. Is there any way to do it or what i'm trying to do is just a foolish approach?
I assume that your geometry has the WKT (Well Known Text) format. If not, you can get it in the WKT format by using the ST_AsText
method (requires spatial DB, which I assume you are using).
A simple example of how to get a geometry from a WKT String:
String wktString = "LINESTRING (0 0, 0 10)";
WKTReader reader = new WKTReader();
Geometry geom = reader.read(wktString);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With