Search in sources :

Example 6 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project elasticsearch by elastic.

the class ElasticsearchGeoAssertions method fixedOrderedRing.

private static Coordinate[] fixedOrderedRing(Coordinate[] points, boolean direction) {
    final int top = top(points);
    final int next = next(top, points);
    final int prev = prev(top, points);
    final boolean orientation = points[next].x < points[prev].x;
    if (orientation != direction) {
        List<Coordinate> asList = Arrays.asList(points);
        Collections.reverse(asList);
        return fixedOrderedRing(asList, direction);
    } else {
        if (top > 0) {
            Coordinate[] aligned = new Coordinate[points.length];
            System.arraycopy(points, top, aligned, 0, points.length - top - 1);
            System.arraycopy(points, 0, aligned, points.length - top - 1, top);
            aligned[aligned.length - 1] = aligned[0];
            return aligned;
        } else {
            return points;
        }
    }
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) GeoPoint(org.elasticsearch.common.geo.GeoPoint) JtsPoint(org.locationtech.spatial4j.shape.jts.JtsPoint) MultiPoint(com.vividsolutions.jts.geom.MultiPoint)

Example 7 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project elasticsearch by elastic.

the class GeoShapeQueryBuilderTests method testThatXContentSerializationInsideOfArrayWorks.

// see #3878
public void testThatXContentSerializationInsideOfArrayWorks() throws Exception {
    EnvelopeBuilder envelopeBuilder = ShapeBuilders.newEnvelope(new Coordinate(0, 0), new Coordinate(10, 10));
    GeoShapeQueryBuilder geoQuery = QueryBuilders.geoShapeQuery("searchGeometry", envelopeBuilder);
    JsonXContent.contentBuilder().startArray().value(geoQuery).endArray();
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) EnvelopeBuilder(org.elasticsearch.common.geo.builders.EnvelopeBuilder)

Example 8 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project elasticsearch by elastic.

the class GeoJSONShapeParserTests method testParseLineString.

public void testParseLineString() throws IOException {
    XContentBuilder lineGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "LineString").startArray("coordinates").startArray().value(100.0).value(0.0).endArray().startArray().value(101.0).value(1.0).endArray().endArray().endObject();
    List<Coordinate> lineCoordinates = new ArrayList<>();
    lineCoordinates.add(new Coordinate(100, 0));
    lineCoordinates.add(new Coordinate(101, 1));
    LineString expected = GEOMETRY_FACTORY.createLineString(lineCoordinates.toArray(new Coordinate[lineCoordinates.size()]));
    assertGeometryEquals(jtsGeom(expected), lineGeoJson);
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) ArrayList(java.util.ArrayList) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 9 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project elasticsearch by elastic.

the class GeoJSONShapeParserTests method testThatParserExtractsCorrectTypeAndCoordinatesFromArbitraryJson.

public void testThatParserExtractsCorrectTypeAndCoordinatesFromArbitraryJson() throws IOException {
    XContentBuilder pointGeoJson = XContentFactory.jsonBuilder().startObject().startObject("crs").field("type", "name").startObject("properties").field("name", "urn:ogc:def:crs:OGC:1.3:CRS84").endObject().endObject().field("bbox", "foobar").field("type", "point").field("bubu", "foobar").startArray("coordinates").value(100.0).value(0.0).endArray().startObject("nested").startArray("coordinates").value(200.0).value(0.0).endArray().endObject().startObject("lala").field("type", "NotAPoint").endObject().endObject();
    Point expected = GEOMETRY_FACTORY.createPoint(new Coordinate(100.0, 0.0));
    assertGeometryEquals(new JtsPoint(expected, SPATIAL_CONTEXT), pointGeoJson);
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) JtsPoint(org.locationtech.spatial4j.shape.jts.JtsPoint) Point(com.vividsolutions.jts.geom.Point) JtsPoint(org.locationtech.spatial4j.shape.jts.JtsPoint) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 10 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project elasticsearch by elastic.

the class ShapeBuilderTests method testNewPolygon_coordinates.

public void testNewPolygon_coordinates() {
    Polygon polygon = ShapeBuilders.newPolygon(new CoordinatesBuilder().coordinates(new Coordinate(-45, 30), new Coordinate(45, 30), new Coordinate(45, -30), new Coordinate(-45, -30), new Coordinate(-45, 30))).toPolygon();
    LineString exterior = polygon.getExteriorRing();
    assertEquals(exterior.getCoordinateN(0), new Coordinate(-45, 30));
    assertEquals(exterior.getCoordinateN(1), new Coordinate(45, 30));
    assertEquals(exterior.getCoordinateN(2), new Coordinate(45, -30));
    assertEquals(exterior.getCoordinateN(3), new Coordinate(-45, -30));
}
Also used : CoordinatesBuilder(org.elasticsearch.common.geo.builders.CoordinatesBuilder) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) ElasticsearchGeoAssertions.assertMultiLineString(org.elasticsearch.test.hamcrest.ElasticsearchGeoAssertions.assertMultiLineString) ElasticsearchGeoAssertions.assertPolygon(org.elasticsearch.test.hamcrest.ElasticsearchGeoAssertions.assertPolygon) ElasticsearchGeoAssertions.assertMultiPolygon(org.elasticsearch.test.hamcrest.ElasticsearchGeoAssertions.assertMultiPolygon) Polygon(com.vividsolutions.jts.geom.Polygon)

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