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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations