Search in sources :

Example 11 with Coordinate

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;
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) Rectangle(org.locationtech.spatial4j.shape.Rectangle)

Example 12 with Coordinate

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);
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate)

Example 13 with Coordinate

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);
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) ArrayList(java.util.ArrayList) LinearRing(com.vividsolutions.jts.geom.LinearRing) Polygon(com.vividsolutions.jts.geom.Polygon) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 14 with Coordinate

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);
}
Also used : MultiLineString(com.vividsolutions.jts.geom.MultiLineString) Coordinate(com.vividsolutions.jts.geom.Coordinate) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 15 with Coordinate

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);
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) Rectangle(org.locationtech.spatial4j.shape.Rectangle)

Aggregations

Coordinate (com.vividsolutions.jts.geom.Coordinate)336 LineString (com.vividsolutions.jts.geom.LineString)70 Geometry (com.vividsolutions.jts.geom.Geometry)67 ArrayList (java.util.ArrayList)65 Test (org.junit.Test)60 Point (com.vividsolutions.jts.geom.Point)52 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)48 Polygon (com.vividsolutions.jts.geom.Polygon)30 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)27 SimpleFeature (org.opengis.feature.simple.SimpleFeature)23 LinearRing (com.vividsolutions.jts.geom.LinearRing)22 Vertex (org.opentripplanner.routing.graph.Vertex)22 Envelope (com.vividsolutions.jts.geom.Envelope)21 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)20 Edge (org.opentripplanner.routing.graph.Edge)19 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)19 CoordinateSequence (com.vividsolutions.jts.geom.CoordinateSequence)14 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)13 File (java.io.File)11 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)11