Search in sources :

Example 6 with MultiPoint

use of org.opensearch.geometry.MultiPoint in project OpenSearch by opensearch-project.

the class GeoJsonParserTests method testParseMultiPoint.

@Override
public void testParseMultiPoint() throws IOException {
    XContentBuilder multiPointGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "MultiPoint").startArray("coordinates").startArray().value(100.0).value(0.0).endArray().startArray().value(101.0).value(1.0).endArray().endArray().endObject();
    assertGeometryEquals(new MultiPoint(Arrays.asList(new Point(100, 0), new Point(101, 1))), multiPointGeoJson);
}
Also used : MultiPoint(org.opensearch.geometry.MultiPoint) Point(org.opensearch.geometry.Point) MultiPoint(org.opensearch.geometry.MultiPoint) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Example 7 with MultiPoint

use of org.opensearch.geometry.MultiPoint in project OpenSearch by opensearch-project.

the class GeometryTestUtils method randomMultiPoint.

public static MultiPoint randomMultiPoint(boolean hasAlt) {
    int size = OpenSearchTestCase.randomIntBetween(3, 10);
    List<Point> points = new ArrayList<>();
    for (int i = 0; i < size; i++) {
        points.add(randomPoint(hasAlt));
    }
    return new MultiPoint(points);
}
Also used : MultiPoint(org.opensearch.geometry.MultiPoint) ArrayList(java.util.ArrayList) Point(org.opensearch.geometry.Point) MultiPoint(org.opensearch.geometry.MultiPoint) Point(org.opensearch.geometry.Point) MultiPoint(org.opensearch.geometry.MultiPoint)

Example 8 with MultiPoint

use of org.opensearch.geometry.MultiPoint in project OpenSearch by opensearch-project.

the class WellKnownText method parseMultiPoint.

private MultiPoint parseMultiPoint(StreamTokenizer stream) throws IOException, ParseException {
    String token = nextEmptyOrOpen(stream);
    if (token.equals(EMPTY)) {
        return MultiPoint.EMPTY;
    }
    ArrayList<Double> lats = new ArrayList<>();
    ArrayList<Double> lons = new ArrayList<>();
    ArrayList<Double> alts = new ArrayList<>();
    ArrayList<Point> points = new ArrayList<>();
    parseCoordinates(stream, lats, lons, alts);
    for (int i = 0; i < lats.size(); i++) {
        if (alts.isEmpty()) {
            points.add(new Point(lons.get(i), lats.get(i)));
        } else {
            points.add(new Point(lons.get(i), lats.get(i), alts.get(i)));
        }
    }
    return new MultiPoint(Collections.unmodifiableList(points));
}
Also used : MultiPoint(org.opensearch.geometry.MultiPoint) ArrayList(java.util.ArrayList) Point(org.opensearch.geometry.Point) MultiPoint(org.opensearch.geometry.MultiPoint) Point(org.opensearch.geometry.Point) MultiPoint(org.opensearch.geometry.MultiPoint)

Example 9 with MultiPoint

use of org.opensearch.geometry.MultiPoint in project OpenSearch by opensearch-project.

the class GeoWKTShapeParserTests method testParseMultiPoint.

@Override
public void testParseMultiPoint() throws IOException, ParseException {
    int numPoints = randomIntBetween(0, 100);
    List<Coordinate> coordinates = new ArrayList<>(numPoints);
    for (int i = 0; i < numPoints; ++i) {
        coordinates.add(new Coordinate(GeoTestUtil.nextLongitude(), GeoTestUtil.nextLatitude()));
    }
    List<org.opensearch.geometry.Point> points = new ArrayList<>(numPoints);
    for (int i = 0; i < numPoints; ++i) {
        Coordinate c = coordinates.get(i);
        points.add(new org.opensearch.geometry.Point(c.x, c.y));
    }
    Geometry expectedGeom;
    MultiPointBuilder actual;
    if (numPoints == 0) {
        expectedGeom = MultiPoint.EMPTY;
        actual = new MultiPointBuilder();
    } else if (numPoints == 1) {
        expectedGeom = points.get(0);
        actual = new MultiPointBuilder(coordinates);
    } else {
        expectedGeom = new MultiPoint(points);
        actual = new MultiPointBuilder(coordinates);
    }
    assertExpected(expectedGeom, actual, false);
    assertMalformed(actual);
    assumeTrue("JTS test path cannot handle empty multipoints", numPoints > 1);
    Shape[] shapes = new Shape[numPoints];
    for (int i = 0; i < numPoints; ++i) {
        Coordinate c = coordinates.get(i);
        shapes[i] = SPATIAL_CONTEXT.makePoint(c.x, c.y);
    }
    ShapeCollection<?> expected = shapeCollection(shapes);
    assertExpected(expected, new MultiPointBuilder(coordinates), true);
}
Also used : MultiPoint(org.opensearch.geometry.MultiPoint) Shape(org.locationtech.spatial4j.shape.Shape) ArrayList(java.util.ArrayList) MultiPoint(org.opensearch.geometry.MultiPoint) JtsPoint(org.locationtech.spatial4j.shape.jts.JtsPoint) Point(org.locationtech.jts.geom.Point) MultiPointBuilder(org.opensearch.common.geo.builders.MultiPointBuilder) MultiPoint(org.opensearch.geometry.MultiPoint) JtsPoint(org.locationtech.spatial4j.shape.jts.JtsPoint) Point(org.locationtech.jts.geom.Point) Geometry(org.opensearch.geometry.Geometry) Coordinate(org.locationtech.jts.geom.Coordinate)

Example 10 with MultiPoint

use of org.opensearch.geometry.MultiPoint in project OpenSearch by opensearch-project.

the class GeometryIO method readMultiPoint.

private static MultiPoint readMultiPoint(StreamInput in) throws IOException {
    int size = in.readVInt();
    List<Point> points = new ArrayList<>(size);
    for (int i = 0; i < size; i++) {
        double lon = in.readDouble();
        double lat = in.readDouble();
        double alt = readAlt(in);
        points.add(new Point(lon, lat, alt));
    }
    return new MultiPoint(points);
}
Also used : MultiPoint(org.opensearch.geometry.MultiPoint) ArrayList(java.util.ArrayList) Point(org.opensearch.geometry.Point) MultiPoint(org.opensearch.geometry.MultiPoint) Point(org.opensearch.geometry.Point) MultiPoint(org.opensearch.geometry.MultiPoint)

Aggregations

MultiPoint (org.opensearch.geometry.MultiPoint)11 Point (org.opensearch.geometry.Point)7 ArrayList (java.util.ArrayList)5 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)3 Geometry (org.opensearch.geometry.Geometry)3 Coordinate (org.locationtech.jts.geom.Coordinate)2 MultiPointBuilder (org.opensearch.common.geo.builders.MultiPointBuilder)2 Point (org.locationtech.jts.geom.Point)1 Point (org.locationtech.spatial4j.shape.Point)1 Shape (org.locationtech.spatial4j.shape.Shape)1 JtsPoint (org.locationtech.spatial4j.shape.jts.JtsPoint)1 OpenSearchParseException (org.opensearch.OpenSearchParseException)1 SearchPhaseExecutionException (org.opensearch.action.search.SearchPhaseExecutionException)1 XShapeCollection (org.opensearch.common.geo.XShapeCollection)1 Circle (org.opensearch.geometry.Circle)1 GeometryCollection (org.opensearch.geometry.GeometryCollection)1 Line (org.opensearch.geometry.Line)1 MultiLine (org.opensearch.geometry.MultiLine)1 ShapeType (org.opensearch.geometry.ShapeType)1