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);
}
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);
}
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));
}
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);
}
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);
}
Aggregations