Skip to content

GeoConverters does not convert inner rings of GeoJsonPolygon #4104

Closed
@lennertdefeyter

Description

@lennertdefeyter

Hi,

I noticed that the GeojsonPolygonconvertor does not convert the inner rings. If you want to convert a polygon with holes. It only looks at the outer ring.

This is very apparent in the code in line 759 of GeoConverters.java.
static GeoJsonPolygon toGeoJsonPolygon(List dbList) { return new GeoJsonPolygon(toListOfPoint((List) dbList.get(0))); }

As you can see, it only looks at the first item in the list of rings (e.g. the outer ring).

I've already fixed it with a custom convertor (see attachment, although this is for multipolygons), but it might be nice to have this in the core.

I think that in order to fix it, the toGeoJsonPolygon(List dbList) function in GeoConverters.java needs to change to:

static GeoJsonPolygon toGeoJsonPolygon(List dbList) { Iterator<GeoJsonLineString> it = ((List) dbList).iterator(); GeoJsonPolygon g = new GeoJsonPolygon(toListOfPoint((List) it.next())); while (it.hasNext()) g = g.withInnerRing(toListOfPoint((List) it.next())); return g; }

GeoJsonMultiPolygonDeserializer.java.txt
.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions