final WKTReader wktReader = new WKTReader();
String geomString = "MULTILINESTRING ((-98.753985 34.63093, -98.7555568 34.63093))";
MultiLineString geom = (MultiLineString)wktReader.read(geomString);
LineString newGeom = new GeometryFactory().createLineString(geom.getCoordinates());
Polygon envelope = (Polygon) newGeom.getEnvelope();
Such code results with ClassCastException(). However, when I'm changing y value of any of coordinates, e.g. first one to 34.63094, I don't get any error.
I am using org.locationtech.jts-1.17
.
What would I like to achieve is to cast it to Polygon without this Exception. Or, the exception is actually valid and I shouldn't be able to cast any two-coordinate LineString to Polygon?