Reputation: 41
I want to convert a wkt geography into a jts geometry.
I tried using jts wkt reader like this.
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.io.WKTReader;
Geometry geometry = wktReader.read(wktString);
Here the problem is wkt is of the format (longitude latitude) . The geometry which gets created out of this is not the expected one.
If the input would have been of the format (latitude longitude), it would have solved the problem.
One way that I could think of is that , take the interior rings and the shell. For each ring swap the lat and long and create a new ring. After swapping for the rings , I will create a new geometry.
Is there any other way to convert the wkt from x,y to y,x before creating the geometry ?
Upvotes: 4
Views: 5873
Reputation: 99
You can cast it and then get geometry object:
JtsGeometry shape = (JtsGeometry) wkt(ctx, "POLYGON((0 0, 10 0, 5 5, 0 0))");
Then
shape.getGeom()
It will return the Geometry object that you can use for further operations like intersection etc:
shape.getGeom().intersection(otherGeometryShape);
Upvotes: 1
Reputation: 1136
JTS is completely agnostic when it comes to coordinate systems. It will read your data as you present it. This means there is no latitude or longitude, just x and y as in your WKT input.
See How to Swap Coordinates of jts.geom.Geometry object from Lat, Long to Long,Lat in JTS for some ideas to solve your problem.
Upvotes: -1