Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert java.lang.String geometry to jts Geometry

Tags:

jts

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?

like image 246
user1120946 Avatar asked Dec 21 '22 04:12

user1120946


1 Answers

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);
like image 180
Lars Avatar answered Feb 04 '23 02:02

Lars