How to handle self-intersecting GeoJson polygons in Elastic search

Viewed 841

We are indexing geo-json polygons using the shape data type in Elastic Search. The polygons are provided to us from an external source. When indexing, some of the polygons fail with the following message.

"Unable to Tessellate shape [[12.775555, 61.54487] [12.797356, 61.53186] [12.795639, 61.549286] [12.832375, 61.54536] [12.775555, 61.54487] ]. Possible malformed shape detected."

We believe the issue is related to self-intersecting polygons. The polygons seem to be valid, according to e.g https://geojsonlint.com. Below is an example of a self-intersecting polygon:

{
        "type": "Polygon",
        "coordinates": [
          [
            [
              12.775554656982422,
              61.54486837329203
            ],
            [
              12.797355651855469,
              61.53186079051699
            ],
            [
              12.795639038085938,
              61.54928480379444
            ],
            [
              12.832374572753906,
              61.54535911881558
            ],
            [
              12.775554656982422,
              61.54486837329203
            ]
          ]
        ]
      }

This stack-overflow post seems to indicate that the correct way is to split the self-intersecting polygons into several polygons so that the above polygon would be split into 2 triangles. However the above post also uncovered a bug in Lucene, so we are a little confused about what to expect.

So, our question is, what is the suggested way to index self-intersecting polygons in Elasticsearch?

Thanks in advance!

1 Answers

what is the suggested way to index self-intersecting polygons in Elasticsearch?

You cannot index self-intersecting polygons. They need to be valid following OGC specification (http://portal.opengeospatial.org/files/?artifact_id=25355).

In addition, the polygon you shared makes me wonder if there is an issue in the way you are generating those. Before splitting such a polygon into two triangles, I would try to understand why such shapes are being generated?

Related