Search in sources :

Example 1 with LineString

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

Example 2 with LineString

use of com.vividsolutions.jts.geom.LineString 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));
}
Also used : CoordinatesBuilder(org.elasticsearch.common.geo.builders.CoordinatesBuilder) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) ElasticsearchGeoAssertions.assertMultiLineString(org.elasticsearch.test.hamcrest.ElasticsearchGeoAssertions.assertMultiLineString) ElasticsearchGeoAssertions.assertPolygon(org.elasticsearch.test.hamcrest.ElasticsearchGeoAssertions.assertPolygon) ElasticsearchGeoAssertions.assertMultiPolygon(org.elasticsearch.test.hamcrest.ElasticsearchGeoAssertions.assertMultiPolygon) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 3 with LineString

use of com.vividsolutions.jts.geom.LineString in project elasticsearch-jdbc by jprante.

the class GeoJSONShapeSerializer method serializePolygonCoordinates.

/**
     * Serializes the actual coordinates of the given {@link Polygon}
     *
     * @param polygon Polygon whose coordinates will be serialized
     * @param builder XContentBuilder it will be serialized to
     * @throws IOException Thrown if an error occurs while writing to the XContentBuilder
     */
private static void serializePolygonCoordinates(Polygon polygon, XContentBuilder builder) throws IOException {
    // start outer ring
    builder.startArray();
    for (Coordinate coordinate : polygon.getExteriorRing().getCoordinates()) {
        serializeCoordinate(coordinate, builder);
    }
    // end outer ring
    builder.endArray();
    for (int i = 0; i < polygon.getNumInteriorRing(); i++) {
        LineString interiorRing = polygon.getInteriorRingN(i);
        builder.startArray();
        for (Coordinate coordinate : interiorRing.getCoordinates()) {
            serializeCoordinate(coordinate, builder);
        }
        builder.endArray();
    }
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) Point(com.vividsolutions.jts.geom.Point)

Example 4 with LineString

use of com.vividsolutions.jts.geom.LineString in project series-rest-api by 52North.

the class GeoJSONEncoder method encode.

protected ObjectNode encode(MultiLineString geometry, int parentSrid) {
    ObjectNode json = jsonFactory.objectNode();
    ArrayNode list = json.put(JSONConstants.TYPE, JSONConstants.MULTI_LINE_STRING).putArray(JSONConstants.COORDINATES);
    for (int i = 0; i < geometry.getNumGeometries(); ++i) {
        list.add(encodeCoordinates((LineString) geometry.getGeometryN(i)));
    }
    encodeCRS(json, geometry, parentSrid);
    return json;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint)

Example 5 with LineString

use of com.vividsolutions.jts.geom.LineString in project series-rest-api by 52North.

the class GeoJSONTest method testLineStringWithZCoordinate.

@Test
public void testLineStringWithZCoordinate() {
    LineString geometry = randomLineString(CRSUtils.EPSG_WGS84);
    geometry.apply(new RandomZCoordinateFilter());
    geometry.geometryChanged();
    readWriteTest(geometry);
}
Also used : LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) Test(org.junit.Test)

Aggregations

LineString (com.vividsolutions.jts.geom.LineString)26 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)15 Point (com.vividsolutions.jts.geom.Point)12 Coordinate (com.vividsolutions.jts.geom.Coordinate)9 Geometry (com.vividsolutions.jts.geom.Geometry)7 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)7 Polygon (com.vividsolutions.jts.geom.Polygon)7 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 GeometryCollection (com.vividsolutions.jts.geom.GeometryCollection)3 LineStringType (ogc.schema.opengis.gml.v_2_1_2.LineStringType)3 MultiLineStringType (ogc.schema.opengis.gml.v_2_1_2.MultiLineStringType)3 CoordinatesBuilder (org.elasticsearch.common.geo.builders.CoordinatesBuilder)3 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)3 ElasticsearchGeoAssertions.assertMultiLineString (org.elasticsearch.test.hamcrest.ElasticsearchGeoAssertions.assertMultiLineString)3 ElasticsearchGeoAssertions.assertMultiPolygon (org.elasticsearch.test.hamcrest.ElasticsearchGeoAssertions.assertMultiPolygon)3 ElasticsearchGeoAssertions.assertPolygon (org.elasticsearch.test.hamcrest.ElasticsearchGeoAssertions.assertPolygon)3 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)2 ParseException (com.vividsolutions.jts.io.ParseException)2 MultiCurveType (net.opengis.gml.v_3_2_1.MultiCurveType)2