jts icon indicating copy to clipboard operation
jts copied to clipboard

GeoJsonWriter produces invalid GeoJSON when serializing LinearRing (or other subclasses of LineString)

Open pascalriquier opened this issue 3 years ago • 4 comments

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.

pascalriquier avatar Aug 03 '21 12:08 pascalriquier

i reproduce the error ,GeoJsonReader can not support type "LinearRing"

mrpan avatar Nov 02 '21 06:11 mrpan

i reproduce the error ,GeoJsonReader can not support type "LinearRing"

#796

mrpan avatar Nov 02 '21 08:11 mrpan

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?

dr-jts avatar Nov 02 '21 17:11 dr-jts

Seems like the logical thing to do indeed. Maybe make sure the fix does not only cover LinearRing but all subclasses of LineString?

pascalriquier avatar Nov 02 '21 17:11 pascalriquier