Search in sources :

Example 1 with Coordinate

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

the class CoordinatesBuilder method close.

/**
     * Makes a closed ring out of the current coordinates by adding the starting point as the end point.
     * Will have no effect of starting and end point are already the same coordinate.
     */
public CoordinatesBuilder close() {
    Coordinate start = points.get(0);
    Coordinate end = points.get(points.size() - 1);
    if (start.x != end.x || start.y != end.y) {
        points.add(start);
    }
    return this;
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate)

Example 2 with Coordinate

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

the class LineStringBuilder method close.

/**
     * Closes the current lineString by adding the starting point as the end point.
     * This will have no effect if starting and end point are already the same.
     */
public LineStringBuilder close() {
    Coordinate start = coordinates.get(0);
    Coordinate end = coordinates.get(coordinates.size() - 1);
    if (start.x != end.x || start.y != end.y) {
        coordinates.add(start);
    }
    return this;
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate)

Example 3 with Coordinate

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

the class MultiPointBuilder method build.

@Override
public Shape build() {
    //Could wrap JtsGeometry but probably slower due to conversions to/from JTS in relate()
    //MultiPoint geometry = FACTORY.createMultiPoint(points.toArray(new Coordinate[points.size()]));
    List<Point> shapes = new ArrayList<>(coordinates.size());
    for (Coordinate coord : coordinates) {
        shapes.add(SPATIAL_CONTEXT.makePoint(coord.x, coord.y));
    }
    XShapeCollection<Point> multiPoints = new XShapeCollection<>(shapes, SPATIAL_CONTEXT);
    multiPoints.setPointsOnly(true);
    return multiPoints;
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) XShapeCollection(org.elasticsearch.common.geo.XShapeCollection) ArrayList(java.util.ArrayList) Point(org.locationtech.spatial4j.shape.Point)

Example 4 with Coordinate

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

the class ShapeBuilder method intersections.

/**
     * Calculate all intersections of line segments and a vertical line. The
     * Array of edges will be ordered asc by the y-coordinate of the
     * intersections of edges.
     *
     * @param dateline
     *            x-coordinate of the dateline
     * @param edges
     *            set of edges that may intersect with the dateline
     * @return number of intersecting edges
     */
protected static int intersections(double dateline, Edge[] edges) {
    int numIntersections = 0;
    assert !Double.isNaN(dateline);
    for (int i = 0; i < edges.length; i++) {
        Coordinate p1 = edges[i].coordinate;
        Coordinate p2 = edges[i].next.coordinate;
        assert !Double.isNaN(p2.x) && !Double.isNaN(p1.x);
        edges[i].intersect = Edge.MAX_COORDINATE;
        double position = intersection(p1, p2, dateline);
        if (!Double.isNaN(position)) {
            edges[i].intersection(position);
            numIntersections++;
        }
    }
    Arrays.sort(edges, INTERSECTION_ORDER);
    return numIntersections;
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate)

Example 5 with Coordinate

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

the class ShapeBuilder method parseCoordinates.

/**
     * Recursive method which parses the arrays of coordinates used to define
     * Shapes
     *
     * @param parser
     *            Parser that will be read from
     * @return CoordinateNode representing the start of the coordinate tree
     * @throws IOException
     *             Thrown if an error occurs while reading from the
     *             XContentParser
     */
private static CoordinateNode parseCoordinates(XContentParser parser) throws IOException {
    XContentParser.Token token = parser.nextToken();
    // Base cases
    if (token != XContentParser.Token.START_ARRAY && token != XContentParser.Token.END_ARRAY && token != XContentParser.Token.VALUE_NULL) {
        double lon = parser.doubleValue();
        token = parser.nextToken();
        double lat = parser.doubleValue();
        token = parser.nextToken();
        while (token == XContentParser.Token.VALUE_NUMBER) {
            token = parser.nextToken();
        }
        return new CoordinateNode(new Coordinate(lon, lat));
    } else if (token == XContentParser.Token.VALUE_NULL) {
        throw new IllegalArgumentException("coordinates cannot contain NULL values)");
    }
    List<CoordinateNode> nodes = new ArrayList<>();
    while (token != XContentParser.Token.END_ARRAY) {
        nodes.add(parseCoordinates(parser));
        token = parser.nextToken();
    }
    return new CoordinateNode(nodes);
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) ArrayList(java.util.ArrayList) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

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