use of com.vividsolutions.jts.geom.LineString in project elasticsearch by elastic.
the class GeoJSONShapeParserTests method testParseMultiDimensionShapes.
public void testParseMultiDimensionShapes() throws IOException {
// multi dimension point
XContentBuilder pointGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Point").startArray("coordinates").value(100.0).value(0.0).value(15.0).value(18.0).endArray().endObject();
Point expectedPt = GEOMETRY_FACTORY.createPoint(new Coordinate(100.0, 0.0));
assertGeometryEquals(new JtsPoint(expectedPt, SPATIAL_CONTEXT), pointGeoJson);
// multi dimension linestring
XContentBuilder lineGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "LineString").startArray("coordinates").startArray().value(100.0).value(0.0).value(15.0).endArray().startArray().value(101.0).value(1.0).value(18.0).value(19.0).endArray().endArray().endObject();
List<Coordinate> lineCoordinates = new ArrayList<>();
lineCoordinates.add(new Coordinate(100, 0));
lineCoordinates.add(new Coordinate(101, 1));
LineString expectedLS = GEOMETRY_FACTORY.createLineString(lineCoordinates.toArray(new Coordinate[lineCoordinates.size()]));
assertGeometryEquals(jtsGeom(expectedLS), lineGeoJson);
}
use of com.vividsolutions.jts.geom.LineString in project elasticsearch by elastic.
the class GeoJSONShapeParserTests method testParseGeometryCollection.
public void testParseGeometryCollection() throws IOException {
XContentBuilder geometryCollectionGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "GeometryCollection").startArray("geometries").startObject().field("type", "LineString").startArray("coordinates").startArray().value(100.0).value(0.0).endArray().startArray().value(101.0).value(1.0).endArray().endArray().endObject().startObject().field("type", "Point").startArray("coordinates").value(102.0).value(2.0).endArray().endObject().endArray().endObject();
Shape[] expected = new Shape[2];
LineString expectedLineString = GEOMETRY_FACTORY.createLineString(new Coordinate[] { new Coordinate(100, 0), new Coordinate(101, 1) });
expected[0] = jtsGeom(expectedLineString);
Point expectedPoint = GEOMETRY_FACTORY.createPoint(new Coordinate(102.0, 2.0));
expected[1] = new JtsPoint(expectedPoint, SPATIAL_CONTEXT);
//equals returns true only if geometries are in the same order
assertGeometryEquals(shapeCollection(expected), geometryCollectionGeoJson);
}
use of com.vividsolutions.jts.geom.LineString in project elasticsearch by elastic.
the class ShapeBuilderTests method testNewPolygon_coordinate.
public void testNewPolygon_coordinate() {
Polygon polygon = ShapeBuilders.newPolygon(new CoordinatesBuilder().coordinate(new Coordinate(-45, 30)).coordinate(new Coordinate(45, 30)).coordinate(new Coordinate(45, -30)).coordinate(new Coordinate(-45, -30)).coordinate(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));
}
use of com.vividsolutions.jts.geom.LineString in project series-rest-api by 52North.
the class GeoJSONTest method randomLineString.
private LineString randomLineString(int srid) {
LineString geometry = geometryFactory.createLineString(new Coordinate[] { randomCoordinate(), randomCoordinate(), randomCoordinate() });
geometry.setSRID(srid);
return geometry;
}
use of com.vividsolutions.jts.geom.LineString in project series-rest-api by 52North.
the class GeoJSONDecoder method decodeMultiLineString.
protected MultiLineString decodeMultiLineString(JsonNode node, GeometryFactory fac) throws GeoJSONException {
JsonNode coordinates = requireCoordinates(node);
LineString[] lineStrings = new LineString[coordinates.size()];
for (int i = 0; i < coordinates.size(); ++i) {
JsonNode coords = coordinates.get(i);
lineStrings[i] = fac.createLineString(decodeCoordinates(coords));
}
return fac.createMultiLineString(lineStrings);
}
Aggregations