Lucene Geo spatial3d - Failure creating a 3 dot polygon


I'm trying to create a polygon from 3 GeoPoints, but I get this exception:

java.lang.IllegalArgumentException: Convex polygon has a side that is more than 180 degrees
at org.apache.lucene.spatial3d.geom.GeoConvexPolygon.done(
at org.apache.lucene.spatial3d.geom.GeoConvexPolygon.(
at org.apache.lucene.spatial3d.geom.GeoPolygonFactory.findConvexPolygon(
at org.apache.lucene.spatial3d.geom.GeoPolygonFactory.buildPolygonShape(
at org.apache.lucene.spatial3d.geom.GeoPolygonFactory.generateGeoPolygon(
at org.apache.lucene.spatial3d.geom.GeoPolygonFactory.makeGeoPolygon(
at org.apache.lucene.spatial3d.geom.GeoPolygonFactory.makeGeoPolygon(

Same points on an older Lucene version (5.5.2) did create a convex polygon without any problem.

This is the code to recreate:

        ArrayList<GeoPoint> geoPoints = new ArrayList<>();
        GeoPoint A = new GeoPoint(0.018666906832587843, -0.734685195457333, 0.6775208545943724);
        GeoPoint B = new GeoPoint(0.02114286423885716, -0.7361764416720697, 0.6758386402661503);
        GeoPoint C = new GeoPoint(0.021142824333297772, -0.7361763954440932, 0.6758386915242299);
        GeoPolygon polygon =  GeoPolygonFactory.makeGeoPolygon(PlanetModel.WGS84, geoPoints, null);

The last line is where the exception happens.

My goal is to measure distance between a GeoPoint and the convex polygon. for example, if I continue the code snippet from above:

        Pair<Double,Double> location = new Pair<>(1.0, 1.0);
        GeoPoint locationGeoPoint = new GeoPoint(PlanetModel.WGS84, location.fst * Math.PI / 180, location.snd * Math.PI / 180);
        double distance = polygon.computeOutsideDistance(DistanceStyle.NORMAL, locationGeoPoint) * Math.pow(180/Math.PI, 2);
        System.out.println("distance from polygon: " + distance);

Thanks in advance,

Forgive my obliviousness, but are you asking how to do this in Elasticsearch?

Hi Mark.

No, I'm doing some post processing on my app after fetching from ES.
I'm creating multiple Polygons (clustering several close points) & measure the distance between a given point and all other polygons.

Can you help?

I can't sorry, I was just trying to understand a bit better what it's about to see if I could!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.