Search in sources :

Example 16 with GeoPoint

use of org.apache.lucene.spatial3d.geom.GeoPoint in project lucene-solr by apache.

the class TestGeo3DPoint method convertToPoints.

protected static List<GeoPoint> convertToPoints(final PlanetModel pm, final GeoPoint pole, final double[] angles, final double[] arcDistances) {
    // To do the point rotations, we need the sine and cosine of the pole latitude and longitude.  Get it here for performance.
    final double sinLatitude = Math.sin(pole.getLatitude());
    final double cosLatitude = Math.cos(pole.getLatitude());
    final double sinLongitude = Math.sin(pole.getLongitude());
    final double cosLongitude = Math.cos(pole.getLongitude());
    final List<GeoPoint> rval = new ArrayList<>();
    for (int i = 0; i < angles.length; i++) {
        rval.add(createPoint(pm, angles[i], arcDistances[i], sinLatitude, cosLatitude, sinLongitude, cosLongitude));
    }
    return rval;
}
Also used : GeoPoint(org.apache.lucene.spatial3d.geom.GeoPoint) ArrayList(java.util.ArrayList) GeoPoint(org.apache.lucene.spatial3d.geom.GeoPoint)

Example 17 with GeoPoint

use of org.apache.lucene.spatial3d.geom.GeoPoint in project lucene-solr by apache.

the class TestGeo3DPoint method testEncodeDecodeCeil.

public void testEncodeDecodeCeil() throws Exception {
    // just for testing quantization error
    final double ENCODING_TOLERANCE = Geo3DUtil.DECODE;
    int iters = atLeast(10000);
    for (int iter = 0; iter < iters; iter++) {
        GeoPoint point = new GeoPoint(PlanetModel.WGS84, toRadians(GeoTestUtil.nextLatitude()), toRadians(GeoTestUtil.nextLongitude()));
        double xEnc = Geo3DUtil.decodeValue(Geo3DUtil.encodeValue(point.x));
        assertEquals("x=" + point.x + " xEnc=" + xEnc + " diff=" + (point.x - xEnc), point.x, xEnc, ENCODING_TOLERANCE);
        double yEnc = Geo3DUtil.decodeValue(Geo3DUtil.encodeValue(point.y));
        assertEquals("y=" + point.y + " yEnc=" + yEnc + " diff=" + (point.y - yEnc), point.y, yEnc, ENCODING_TOLERANCE);
        double zEnc = Geo3DUtil.decodeValue(Geo3DUtil.encodeValue(point.z));
        assertEquals("z=" + point.z + " zEnc=" + zEnc + " diff=" + (point.z - zEnc), point.z, zEnc, ENCODING_TOLERANCE);
    }
    // check edge/interesting cases explicitly
    double planetMax = PlanetModel.WGS84.getMaximumMagnitude();
    for (double value : new double[] { 0.0, -planetMax, planetMax }) {
        assertEquals(value, Geo3DUtil.decodeValue(Geo3DUtil.encodeValue(value)), ENCODING_TOLERANCE);
    }
}
Also used : GeoPoint(org.apache.lucene.spatial3d.geom.GeoPoint) GeoPoint(org.apache.lucene.spatial3d.geom.GeoPoint)

Example 18 with GeoPoint

use of org.apache.lucene.spatial3d.geom.GeoPoint in project lucene-solr by apache.

the class Geo3dRptTest method testFailureLucene6535.

@Test
public void testFailureLucene6535() throws IOException {
    setupStrategy();
    final List<GeoPoint> points = new ArrayList<>();
    points.add(new GeoPoint(PlanetModel.SPHERE, 18 * DEGREES_TO_RADIANS, -27 * DEGREES_TO_RADIANS));
    points.add(new GeoPoint(PlanetModel.SPHERE, -57 * DEGREES_TO_RADIANS, 146 * DEGREES_TO_RADIANS));
    points.add(new GeoPoint(PlanetModel.SPHERE, 14 * DEGREES_TO_RADIANS, -180 * DEGREES_TO_RADIANS));
    points.add(new GeoPoint(PlanetModel.SPHERE, -15 * DEGREES_TO_RADIANS, 153 * DEGREES_TO_RADIANS));
    final GeoPoint[] pathPoints = new GeoPoint[] { new GeoPoint(PlanetModel.SPHERE, 55.0 * DEGREES_TO_RADIANS, -26.0 * DEGREES_TO_RADIANS), new GeoPoint(PlanetModel.SPHERE, -90.0 * DEGREES_TO_RADIANS, 0.0), new GeoPoint(PlanetModel.SPHERE, 54.0 * DEGREES_TO_RADIANS, 165.0 * DEGREES_TO_RADIANS), new GeoPoint(PlanetModel.SPHERE, -90.0 * DEGREES_TO_RADIANS, 0.0) };
    final GeoShape path = GeoPathFactory.makeGeoPath(PlanetModel.SPHERE, 29 * DEGREES_TO_RADIANS, pathPoints);
    final Shape shape = new Geo3dShape(path, ctx);
    final Rectangle rect = ctx.makeRectangle(131, 143, 39, 54);
    testOperation(rect, SpatialOperation.Intersects, shape, true);
}
Also used : GeoPoint(org.apache.lucene.spatial3d.geom.GeoPoint) GeoShape(org.apache.lucene.spatial3d.geom.GeoShape) Shape(org.locationtech.spatial4j.shape.Shape) GeoShape(org.apache.lucene.spatial3d.geom.GeoShape) ArrayList(java.util.ArrayList) Rectangle(org.locationtech.spatial4j.shape.Rectangle) Test(org.junit.Test)

Example 19 with GeoPoint

use of org.apache.lucene.spatial3d.geom.GeoPoint in project lucene-solr by apache.

the class TestGeo3DPoint method testEncodeDecodeRoundsDown.

/** make sure values always go down: this is important for edge case consistency */
public void testEncodeDecodeRoundsDown() throws Exception {
    int iters = atLeast(1000);
    for (int iter = 0; iter < iters; iter++) {
        final double latBase = GeoTestUtil.nextLatitude();
        final double lonBase = GeoTestUtil.nextLongitude();
        // test above the value
        double lat = latBase;
        double lon = lonBase;
        for (int i = 0; i < 1000; i++) {
            lat = Math.min(90, Math.nextUp(lat));
            lon = Math.min(180, Math.nextUp(lon));
            GeoPoint point = new GeoPoint(PlanetModel.WGS84, toRadians(lat), toRadians(lon));
            GeoPoint pointEnc = new GeoPoint(Geo3DUtil.decodeValueFloor(Geo3DUtil.encodeValue(point.x)), Geo3DUtil.decodeValueFloor(Geo3DUtil.encodeValue(point.y)), Geo3DUtil.decodeValueFloor(Geo3DUtil.encodeValue(point.z)));
            assertTrue(pointEnc.x <= point.x);
            assertTrue(pointEnc.y <= point.y);
            assertTrue(pointEnc.z <= point.z);
        }
        // test below the value
        lat = latBase;
        lon = lonBase;
        for (int i = 0; i < 1000; i++) {
            lat = Math.max(-90, Math.nextDown(lat));
            lon = Math.max(-180, Math.nextDown(lon));
            GeoPoint point = new GeoPoint(PlanetModel.WGS84, toRadians(lat), toRadians(lon));
            GeoPoint pointEnc = new GeoPoint(Geo3DUtil.decodeValueFloor(Geo3DUtil.encodeValue(point.x)), Geo3DUtil.decodeValueFloor(Geo3DUtil.encodeValue(point.y)), Geo3DUtil.decodeValueFloor(Geo3DUtil.encodeValue(point.z)));
            assertTrue(pointEnc.x <= point.x);
            assertTrue(pointEnc.y <= point.y);
            assertTrue(pointEnc.z <= point.z);
        }
    }
}
Also used : GeoPoint(org.apache.lucene.spatial3d.geom.GeoPoint) GeoPoint(org.apache.lucene.spatial3d.geom.GeoPoint)

Aggregations

GeoPoint (org.apache.lucene.spatial3d.geom.GeoPoint)19 ArrayList (java.util.ArrayList)9 GeoShape (org.apache.lucene.spatial3d.geom.GeoShape)6 Test (org.junit.Test)5 Polygon (org.apache.lucene.geo.Polygon)3 GeoBBox (org.apache.lucene.spatial3d.geom.GeoBBox)3 GeoPolygon (org.apache.lucene.spatial3d.geom.GeoPolygon)3 XYZBounds (org.apache.lucene.spatial3d.geom.XYZBounds)3 HashSet (java.util.HashSet)2 GeoPath (org.apache.lucene.spatial3d.geom.GeoPath)2 Rectangle (org.locationtech.spatial4j.shape.Rectangle)2 Shape (org.locationtech.spatial4j.shape.Shape)2 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Document (org.apache.lucene.document.Document)1 NumericDocValuesField (org.apache.lucene.document.NumericDocValuesField)1 IndexReader (org.apache.lucene.index.IndexReader)1 IndexWriter (org.apache.lucene.index.IndexWriter)1 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)1