jts
jts copied to clipboard
GeoJsonWriter produces invalid GeoJSON when serializing LinearRing (or other subclasses of LineString)
LinearRing linearRing = new GeometryFactory().createLinearRing(new Coordinate[] { new Coordinate(0, 0),
new Coordinate(1, 0), new Coordinate(1, 1), new Coordinate(0, 0)});
String json = new GeoJsonWriter().write(linearRing);
new GeoJsonReader().read(json);
GeoJsonWriter uses the getGeometryType method of Geometry to specify the type used in the GeoJSON. But, for subclasses of LineString, this returns their actual class (e.g. LinearRing) and not 'LineString'. This produces invalid GeoJSON, and so, in this case, the GeoJsonReader can not read the json produced by the GeoJsonWriter for these geometries.
i reproduce the error ,GeoJsonReader can not support type "LinearRing"
i reproduce the error ,GeoJsonReader can not support type "LinearRing"
#796
Since GeoJSON does not support a LinearRing
geometry type, the fix seems to be to emit LinearRings as GeoJSON LineStrings.
@pascalriquier Do you agree with this?
Seems like the logical thing to do indeed. Maybe make sure the fix does not only cover LinearRing but all subclasses of LineString?