use of org.opensearch.geometry.MultiLine in project OpenSearch by opensearch-project.
the class GeoJsonParserTests method testParseMultiLineString.
@Override
public void testParseMultiLineString() throws IOException {
XContentBuilder multilinesGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "MultiLineString").startArray("coordinates").startArray().startArray().value(100.0).value(0.0).endArray().startArray().value(101.0).value(1.0).endArray().endArray().startArray().startArray().value(102.0).value(2.0).endArray().startArray().value(103.0).value(3.0).endArray().endArray().endArray().endObject();
MultiLine expected = new MultiLine(Arrays.asList(new Line(new double[] { 100.0, 101.0 }, new double[] { 0.0, 1.0 }), new Line(new double[] { 102.0, 103.0 }, new double[] { 2.0, 3.0 })));
assertGeometryEquals(expected, multilinesGeoJson);
}
use of org.opensearch.geometry.MultiLine in project OpenSearch by opensearch-project.
the class GeometryTestUtils method randomMultiLine.
public static MultiLine randomMultiLine(boolean hasAlt) {
int size = OpenSearchTestCase.randomIntBetween(3, 10);
List<Line> lines = new ArrayList<>();
for (int i = 0; i < size; i++) {
lines.add(randomLine(hasAlt));
}
return new MultiLine(lines);
}
use of org.opensearch.geometry.MultiLine in project OpenSearch by opensearch-project.
the class GeoWKTShapeParserTests method testParseMultiLineString.
@Override
public void testParseMultiLineString() throws IOException, ParseException {
int numLineStrings = randomIntBetween(0, 8);
List<LineString> lineStrings = new ArrayList<>(numLineStrings);
MultiLineStringBuilder builder = new MultiLineStringBuilder();
for (int j = 0; j < numLineStrings; ++j) {
List<Coordinate> lsc = randomLineStringCoords();
Coordinate[] coords = lsc.toArray(new Coordinate[lsc.size()]);
lineStrings.add(GEOMETRY_FACTORY.createLineString(coords));
builder.linestring(new LineStringBuilder(lsc));
}
List<Line> lines = new ArrayList<>(lineStrings.size());
for (int j = 0; j < lineStrings.size(); ++j) {
Coordinate[] c = lineStrings.get(j).getCoordinates();
lines.add(new Line(Arrays.stream(c).mapToDouble(i -> i.x).toArray(), Arrays.stream(c).mapToDouble(i -> i.y).toArray()));
}
Geometry expectedGeom;
if (lines.isEmpty()) {
expectedGeom = GeometryCollection.EMPTY;
} else if (lines.size() == 1) {
expectedGeom = new Line(lines.get(0).getX(), lines.get(0).getY());
} else {
expectedGeom = new MultiLine(lines);
}
assertExpected(expectedGeom, builder, false);
assertMalformed(builder);
MultiLineString expected = GEOMETRY_FACTORY.createMultiLineString(lineStrings.toArray(new LineString[lineStrings.size()]));
assumeTrue("JTS test path cannot handle empty multilinestrings", numLineStrings > 1);
assertExpected(jtsGeom(expected), builder, true);
}
use of org.opensearch.geometry.MultiLine in project OpenSearch by opensearch-project.
the class GeometryIndexerTests method testLine.
public void testLine() {
Line line = new Line(new double[] { 3, 4 }, new double[] { 1, 2 });
Geometry indexed = line;
assertEquals(indexed, indexer.prepareForIndexing(line));
line = new Line(new double[] { 160, 200 }, new double[] { 10, 20 });
indexed = new MultiLine(Arrays.asList(new Line(new double[] { 160, 180 }, new double[] { 10, 15 }), new Line(new double[] { -180, -160 }, new double[] { 15, 20 })));
assertEquals(indexed, indexer.prepareForIndexing(line));
line = new Line(new double[] { 200, 160 }, new double[] { 10, 20 });
indexed = new MultiLine(Arrays.asList(new Line(new double[] { -160, -180 }, new double[] { 10, 15 }), new Line(new double[] { 180, 160 }, new double[] { 15, 20 })));
assertEquals(indexed, indexer.prepareForIndexing(line));
line = new Line(new double[] { 160, 200, 160 }, new double[] { 0, 10, 20 });
indexed = new MultiLine(Arrays.asList(new Line(new double[] { 160, 180 }, new double[] { 0, 5 }), new Line(new double[] { -180, -160, -180 }, new double[] { 5, 10, 15 }), new Line(new double[] { 180, 160 }, new double[] { 15, 20 })));
assertEquals(indexed, indexer.prepareForIndexing(line));
line = new Line(new double[] { 0, 720 }, new double[] { 0, 20 });
indexed = new MultiLine(Arrays.asList(new Line(new double[] { 0, 180 }, new double[] { 0, 5 }), new Line(new double[] { -180, 180 }, new double[] { 5, 15 }), new Line(new double[] { -180, 0 }, new double[] { 15, 20 })));
assertEquals(indexed, indexer.prepareForIndexing(line));
line = new Line(new double[] { 160, 180, 180, 200, 160, 140 }, new double[] { 0, 10, 20, 30, 30, 40 });
indexed = new MultiLine(Arrays.asList(new Line(new double[] { 160, 180 }, new double[] { 0, 10 }), new Line(new double[] { -180, -180, -160, -180 }, new double[] { 10, 20, 30, 30 }), new Line(new double[] { 180, 160, 140 }, new double[] { 30, 30, 40 })));
assertEquals(indexed, indexer.prepareForIndexing(line));
line = new Line(new double[] { -70, 180, 900 }, new double[] { 0, 0, 4 });
indexed = new MultiLine(Arrays.asList(new Line(new double[] { -70, 180 }, new double[] { 0, 0 }), new Line(new double[] { -180, 180 }, new double[] { 0, 2 }), new Line(new double[] { -180, 180 }, new double[] { 2, 4 })));
assertEquals(indexed, indexer.prepareForIndexing(line));
line = new Line(new double[] { 160, 200, 160, 200, 160, 200 }, new double[] { 0, 10, 20, 30, 40, 50 });
indexed = new MultiLine(Arrays.asList(new Line(new double[] { 160, 180 }, new double[] { 0, 5 }), new Line(new double[] { -180, -160, -180 }, new double[] { 5, 10, 15 }), new Line(new double[] { 180, 160, 180 }, new double[] { 15, 20, 25 }), new Line(new double[] { -180, -160, -180 }, new double[] { 25, 30, 35 }), new Line(new double[] { 180, 160, 180 }, new double[] { 35, 40, 45 }), new Line(new double[] { -180, -160 }, new double[] { 45, 50 })));
assertEquals(indexed, indexer.prepareForIndexing(line));
}
use of org.opensearch.geometry.MultiLine in project OpenSearch by opensearch-project.
the class GeometryIO method readMultiLine.
private static MultiLine readMultiLine(StreamInput in) throws IOException {
int size = in.readVInt();
List<Line> lines = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
lines.add(readLine(in));
}
return new MultiLine(lines);
}
Aggregations