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