use of org.locationtech.spatial4j.shape.jts.JtsPoint 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 org.locationtech.spatial4j.shape.jts.JtsPoint in project crate by crate.
the class GeoJSONUtilsTest method testPoint2Map.
@Test
public void testPoint2Map() throws Exception {
Point point = GEOMETRY_FACTORY.createPoint(new Coordinate(0.0, 0.0));
Shape shape = new JtsPoint(point, JtsSpatialContext.GEO);
Map<String, Object> map = GeoJSONUtils.shape2Map(shape);
assertThat(map, hasEntry("type", (Object) "Point"));
assertThat(map.get("coordinates").getClass().isArray(), is(true));
assertThat(((double[]) map.get("coordinates")).length, is(2));
}
use of org.locationtech.spatial4j.shape.jts.JtsPoint 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 org.locationtech.spatial4j.shape.jts.JtsPoint 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 org.locationtech.spatial4j.shape.jts.JtsPoint in project elasticsearch by elastic.
the class GeoJSONShapeParserTests method testParseSimplePoint.
public void testParseSimplePoint() throws IOException {
XContentBuilder pointGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Point").startArray("coordinates").value(100.0).value(0.0).endArray().endObject();
Point expected = GEOMETRY_FACTORY.createPoint(new Coordinate(100.0, 0.0));
assertGeometryEquals(new JtsPoint(expected, SPATIAL_CONTEXT), pointGeoJson);
}
Aggregations