Search in sources :

Example 6 with Polygon

use of org.apache.lucene.geo.Polygon in project lucene-solr by apache.

the class Geo3DUtil method fromPolygon.

/**
    * Convert a set of Polygon objects into a GeoPolygon.
    * @param polygons are the Polygon objects.
    * @return the GeoPolygon.
    */
static GeoPolygon fromPolygon(final Polygon... polygons) {
    //System.err.println("Creating polygon...");
    if (polygons.length < 1) {
        throw new IllegalArgumentException("need at least one polygon");
    }
    final GeoPolygon shape;
    if (polygons.length == 1) {
        final GeoPolygon component = fromPolygon(polygons[0]);
        if (component == null) {
            // Polygon is degenerate
            shape = new GeoCompositePolygon();
        } else {
            shape = component;
        }
    } else {
        final GeoCompositePolygon poly = new GeoCompositePolygon();
        for (final Polygon p : polygons) {
            final GeoPolygon component = fromPolygon(p);
            if (component != null) {
                poly.addShape(component);
            }
        }
        shape = poly;
    }
    return shape;
//System.err.println("...done");
}
Also used : GeoCompositePolygon(org.apache.lucene.spatial3d.geom.GeoCompositePolygon) GeoPolygon(org.apache.lucene.spatial3d.geom.GeoPolygon) Polygon(org.apache.lucene.geo.Polygon) GeoPolygon(org.apache.lucene.spatial3d.geom.GeoPolygon) GeoCompositePolygon(org.apache.lucene.spatial3d.geom.GeoCompositePolygon)

Example 7 with Polygon

use of org.apache.lucene.geo.Polygon in project lucene-solr by apache.

the class TestGeo3DPoint method testComplexPolygons.

public void testComplexPolygons() {
    final PlanetModel pm = PlanetModel.WGS84;
    // Pick a random pole
    final GeoPoint randomPole = new GeoPoint(pm, toRadians(GeoTestUtil.nextLatitude()), toRadians(GeoTestUtil.nextLongitude()));
    int iters = atLeast(100);
    for (int i = 0; i < iters; i++) {
        // Create a polygon that's less than 180 degrees
        final Polygon clockWise = makePoly(pm, randomPole, true, true);
    }
    iters = atLeast(100);
    for (int i = 0; i < iters; i++) {
        // Create a polygon that's greater than 180 degrees
        final Polygon counterClockWise = makePoly(pm, randomPole, false, true);
    }
}
Also used : GeoPoint(org.apache.lucene.spatial3d.geom.GeoPoint) PlanetModel(org.apache.lucene.spatial3d.geom.PlanetModel) GeoPolygon(org.apache.lucene.spatial3d.geom.GeoPolygon) Polygon(org.apache.lucene.geo.Polygon) GeoPoint(org.apache.lucene.spatial3d.geom.GeoPoint)

Aggregations

Polygon (org.apache.lucene.geo.Polygon)7 GeoPolygon (org.apache.lucene.spatial3d.geom.GeoPolygon)5 ArrayList (java.util.ArrayList)3 GeoPoint (org.apache.lucene.spatial3d.geom.GeoPoint)3 GeoCompositePolygon (org.apache.lucene.spatial3d.geom.GeoCompositePolygon)2 LatLonPoint (org.apache.lucene.document.LatLonPoint)1 MatchNoDocsQuery (org.apache.lucene.search.MatchNoDocsQuery)1 Query (org.apache.lucene.search.Query)1 GeoPolygonFactory (org.apache.lucene.spatial3d.geom.GeoPolygonFactory)1 PlanetModel (org.apache.lucene.spatial3d.geom.PlanetModel)1 GeoPoint (org.elasticsearch.common.geo.GeoPoint)1 GeoPointFieldType (org.elasticsearch.index.mapper.GeoPointFieldMapper.GeoPointFieldType)1 MappedFieldType (org.elasticsearch.index.mapper.MappedFieldType)1