Lucene Geo spatial3d - Failure creating a 3 dot polygon


(Lior) #1

Hi,

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(GeoConvexPolygon.java:237)
at org.apache.lucene.spatial3d.geom.GeoConvexPolygon.(GeoConvexPolygon.java:114)
at org.apache.lucene.spatial3d.geom.GeoPolygonFactory.findConvexPolygon(GeoPolygonFactory.java:1294)
at org.apache.lucene.spatial3d.geom.GeoPolygonFactory.buildPolygonShape(GeoPolygonFactory.java:817)
at org.apache.lucene.spatial3d.geom.GeoPolygonFactory.generateGeoPolygon(GeoPolygonFactory.java:278)
at org.apache.lucene.spatial3d.geom.GeoPolygonFactory.makeGeoPolygon(GeoPolygonFactory.java:116)
at org.apache.lucene.spatial3d.geom.GeoPolygonFactory.makeGeoPolygon(GeoPolygonFactory.java:67)

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);
        geoPoints.add(A);
        geoPoints.add(B);
        geoPoints.add(C);
        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,
Lior


(Mark Walkom) #2

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


(Lior) #3

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?


(Mark Walkom) #4

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


(system) #5

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