Search in sources :

Example 1 with JtsPoint

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);
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) JtsPoint(org.locationtech.spatial4j.shape.jts.JtsPoint) Point(com.vividsolutions.jts.geom.Point) JtsPoint(org.locationtech.spatial4j.shape.jts.JtsPoint) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 2 with JtsPoint

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));
}
Also used : Shape(org.locationtech.spatial4j.shape.Shape) Coordinate(org.locationtech.jts.geom.Coordinate) JtsPoint(org.locationtech.spatial4j.shape.jts.JtsPoint) Point(org.locationtech.jts.geom.Point) JtsPoint(org.locationtech.spatial4j.shape.jts.JtsPoint) LineString(org.locationtech.jts.geom.LineString) Test(org.junit.Test)

Example 3 with JtsPoint

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);
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) JtsPoint(org.locationtech.spatial4j.shape.jts.JtsPoint) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) ArrayList(java.util.ArrayList) Point(com.vividsolutions.jts.geom.Point) JtsPoint(org.locationtech.spatial4j.shape.jts.JtsPoint) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 4 with JtsPoint

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);
}
Also used : Shape(org.locationtech.spatial4j.shape.Shape) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) Coordinate(com.vividsolutions.jts.geom.Coordinate) JtsPoint(org.locationtech.spatial4j.shape.jts.JtsPoint) Point(com.vividsolutions.jts.geom.Point) JtsPoint(org.locationtech.spatial4j.shape.jts.JtsPoint) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 5 with JtsPoint

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);
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) JtsPoint(org.locationtech.spatial4j.shape.jts.JtsPoint) Point(com.vividsolutions.jts.geom.Point) JtsPoint(org.locationtech.spatial4j.shape.jts.JtsPoint) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Aggregations

JtsPoint (org.locationtech.spatial4j.shape.jts.JtsPoint)5 Coordinate (com.vividsolutions.jts.geom.Coordinate)4 Point (com.vividsolutions.jts.geom.Point)4 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)4 LineString (com.vividsolutions.jts.geom.LineString)2 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)2 Shape (org.locationtech.spatial4j.shape.Shape)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 Coordinate (org.locationtech.jts.geom.Coordinate)1 LineString (org.locationtech.jts.geom.LineString)1 Point (org.locationtech.jts.geom.Point)1