use of com.vividsolutions.jts.geom.Coordinate in project elasticsearch by elastic.
the class EnvelopeBuilderTests method createRandomShape.
static EnvelopeBuilder createRandomShape() {
Rectangle box = RandomShapeGenerator.xRandomRectangle(random(), RandomShapeGenerator.xRandomPoint(random()));
EnvelopeBuilder envelope = new EnvelopeBuilder(new Coordinate(box.getMinX(), box.getMaxY()), new Coordinate(box.getMaxX(), box.getMinY()));
return envelope;
}
use of com.vividsolutions.jts.geom.Coordinate in project elasticsearch by elastic.
the class LineStringBuilderTests method mutate.
static LineStringBuilder mutate(LineStringBuilder original) throws IOException {
LineStringBuilder mutation = (LineStringBuilder) copyShape(original);
Coordinate[] coordinates = original.coordinates(false);
Coordinate coordinate = randomFrom(coordinates);
if (randomBoolean()) {
if (coordinate.x != 0.0) {
coordinate.x = coordinate.x / 2;
} else {
coordinate.x = randomDoubleBetween(-180.0, 180.0, true);
}
} else {
if (coordinate.y != 0.0) {
coordinate.y = coordinate.y / 2;
} else {
coordinate.y = randomDoubleBetween(-90.0, 90.0, true);
}
}
return mutation.coordinates(coordinates);
}
use of com.vividsolutions.jts.geom.Coordinate in project elasticsearch by elastic.
the class GeoJSONShapeParserTests method testParsePolygonWithHole.
public void testParsePolygonWithHole() throws IOException {
XContentBuilder polygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Polygon").startArray("coordinates").startArray().startArray().value(100.0).value(1.0).endArray().startArray().value(101.0).value(1.0).endArray().startArray().value(101.0).value(0.0).endArray().startArray().value(100.0).value(0.0).endArray().startArray().value(100.0).value(1.0).endArray().endArray().startArray().startArray().value(100.2).value(0.8).endArray().startArray().value(100.2).value(0.2).endArray().startArray().value(100.8).value(0.2).endArray().startArray().value(100.8).value(0.8).endArray().startArray().value(100.2).value(0.8).endArray().endArray().endArray().endObject();
// add 3d point to test ISSUE #10501
List<Coordinate> shellCoordinates = new ArrayList<>();
shellCoordinates.add(new Coordinate(100, 0, 15.0));
shellCoordinates.add(new Coordinate(101, 0));
shellCoordinates.add(new Coordinate(101, 1));
shellCoordinates.add(new Coordinate(100, 1, 10.0));
shellCoordinates.add(new Coordinate(100, 0));
List<Coordinate> holeCoordinates = new ArrayList<>();
holeCoordinates.add(new Coordinate(100.2, 0.2));
holeCoordinates.add(new Coordinate(100.8, 0.2));
holeCoordinates.add(new Coordinate(100.8, 0.8));
holeCoordinates.add(new Coordinate(100.2, 0.8));
holeCoordinates.add(new Coordinate(100.2, 0.2));
LinearRing shell = GEOMETRY_FACTORY.createLinearRing(shellCoordinates.toArray(new Coordinate[shellCoordinates.size()]));
LinearRing[] holes = new LinearRing[1];
holes[0] = GEOMETRY_FACTORY.createLinearRing(holeCoordinates.toArray(new Coordinate[holeCoordinates.size()]));
Polygon expected = GEOMETRY_FACTORY.createPolygon(shell, holes);
assertGeometryEquals(jtsGeom(expected), polygonGeoJson);
}
use of com.vividsolutions.jts.geom.Coordinate in project elasticsearch by elastic.
the class GeoJSONShapeParserTests method testParseMultiLineString.
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();
MultiLineString expected = GEOMETRY_FACTORY.createMultiLineString(new LineString[] { GEOMETRY_FACTORY.createLineString(new Coordinate[] { new Coordinate(100, 0), new Coordinate(101, 1) }), GEOMETRY_FACTORY.createLineString(new Coordinate[] { new Coordinate(102, 2), new Coordinate(103, 3) }) });
assertGeometryEquals(jtsGeom(expected), multilinesGeoJson);
}
use of com.vividsolutions.jts.geom.Coordinate in project elasticsearch by elastic.
the class ShapeBuilderTests method testNewRectangle.
public void testNewRectangle() {
Rectangle rectangle = ShapeBuilders.newEnvelope(new Coordinate(-45, 30), new Coordinate(45, -30)).build();
assertEquals(-45D, rectangle.getMinX(), 0.0d);
assertEquals(-30D, rectangle.getMinY(), 0.0d);
assertEquals(45D, rectangle.getMaxX(), 0.0d);
assertEquals(30D, rectangle.getMaxY(), 0.0d);
}
Aggregations