Search in sources :

Example 11 with LineString

use of com.vividsolutions.jts.geom.LineString in project ddf by codice.

the class WfsFilterDelegate method createLineString.

private JAXBElement<LineStringType> createLineString(Geometry geometry) {
    JAXBElement<LineStringType> jaxbElement = null;
    try {
        String gml = Wfs10JTStoGML200Converter.convertGeometryToGML(geometry);
        LineStringType lineStringType = (LineStringType) Wfs10JTStoGML200Converter.convertGMLToGeometryType(gml, Wfs10Constants.LINESTRING);
        jaxbElement = (JAXBElement<LineStringType>) Wfs10JTStoGML200Converter.convertGeometryTypeToJAXB(lineStringType);
    } catch (JAXBException jbe) {
        LOGGER.debug("Unable to create LineString with geometry: [{}]", geometry);
    }
    return jaxbElement;
}
Also used : JAXBException(javax.xml.bind.JAXBException) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) MultiLineStringType(ogc.schema.opengis.gml.v_2_1_2.MultiLineStringType) LineStringType(ogc.schema.opengis.gml.v_2_1_2.LineStringType)

Example 12 with LineString

use of com.vividsolutions.jts.geom.LineString in project ddf by codice.

the class WfsFilterDelegate method createGeometryOperand.

private JAXBElement<? extends AbstractGeometryType> createGeometryOperand(String wkt) {
    String convertedWkt = wkt;
    Geometry wktGeometry = null;
    try {
        wktGeometry = getGeometryFromWkt(convertedWkt);
    } catch (ParseException e) {
        throw new IllegalArgumentException("Unable to parse WKT Geometry [" + convertedWkt + "]", e);
    }
    if (wktGeometry instanceof Polygon) {
        if (isGeometryOperandSupported(Wfs10Constants.POLYGON)) {
            return createPolygon(convertedWkt);
        } else {
            throw new IllegalArgumentException("The Polygon operand is not supported.");
        }
    } else if (wktGeometry instanceof Point) {
        if (isGeometryOperandSupported(Wfs10Constants.POINT)) {
            return createPoint(convertedWkt);
        } else {
            throw new IllegalArgumentException("The Point operand is not supported.");
        }
    } else if (wktGeometry instanceof LineString) {
        if (isGeometryOperandSupported(Wfs10Constants.LINESTRING)) {
            return createLineString(wktGeometry);
        } else {
            throw new IllegalArgumentException("The LineString operand is not supported.");
        }
    } else if (wktGeometry instanceof MultiPoint) {
        if (isGeometryOperandSupported(Wfs10Constants.MULTI_POINT)) {
            return createMultiPoint(wktGeometry);
        } else {
            throw new IllegalArgumentException("The MultiPoint operand is not supported.");
        }
    } else if (wktGeometry instanceof MultiLineString) {
        if (isGeometryOperandSupported(Wfs10Constants.MULTI_LINESTRING)) {
            return createMultiLineString(wktGeometry);
        } else {
            throw new IllegalArgumentException("The MultiLineString operand is not supported.");
        }
    } else if (wktGeometry instanceof MultiPolygon) {
        if (isGeometryOperandSupported(Wfs10Constants.MULTI_POLYGON)) {
            return createMultiPolygon(wktGeometry);
        } else {
            throw new IllegalArgumentException("The MultiPolygon operand is not supported.");
        }
    } else if (wktGeometry instanceof GeometryCollection) {
        if (isGeometryOperandSupported(Wfs10Constants.GEOMETRY_COLLECTION)) {
            return createGeometryCollection(wktGeometry);
        } else {
            throw new IllegalArgumentException("The GeometryCollection operand is not supported.");
        }
    }
    throw new IllegalArgumentException("Unable to create Geometry from WKT String");
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) GeometryCollection(com.vividsolutions.jts.geom.GeometryCollection) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) ParseException(com.vividsolutions.jts.io.ParseException) Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 13 with LineString

use of com.vividsolutions.jts.geom.LineString in project elasticsearch by elastic.

the class LineStringBuilder method build.

@Override
public Shape build() {
    Coordinate[] coordinates = this.coordinates.toArray(new Coordinate[this.coordinates.size()]);
    Geometry geometry;
    if (wrapdateline) {
        ArrayList<LineString> strings = decompose(FACTORY, coordinates, new ArrayList<LineString>());
        if (strings.size() == 1) {
            geometry = strings.get(0);
        } else {
            LineString[] linestrings = strings.toArray(new LineString[strings.size()]);
            geometry = FACTORY.createMultiLineString(linestrings);
        }
    } else {
        geometry = FACTORY.createLineString(coordinates);
    }
    return jtsGeometry(geometry);
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString)

Example 14 with LineString

use of com.vividsolutions.jts.geom.LineString in project elasticsearch by elastic.

the class MultiLineStringBuilder method build.

@Override
public Shape build() {
    final Geometry geometry;
    if (wrapdateline) {
        ArrayList<LineString> parts = new ArrayList<>();
        for (LineStringBuilder line : lines) {
            LineStringBuilder.decompose(FACTORY, line.coordinates(false), parts);
        }
        if (parts.size() == 1) {
            geometry = parts.get(0);
        } else {
            LineString[] lineStrings = parts.toArray(new LineString[parts.size()]);
            geometry = FACTORY.createMultiLineString(lineStrings);
        }
    } else {
        LineString[] lineStrings = new LineString[lines.size()];
        Iterator<LineStringBuilder> iterator = lines.iterator();
        for (int i = 0; iterator.hasNext(); i++) {
            lineStrings[i] = FACTORY.createLineString(iterator.next().coordinates(false));
        }
        geometry = FACTORY.createMultiLineString(lineStrings);
    }
    return jtsGeometry(geometry);
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) LineString(com.vividsolutions.jts.geom.LineString) ArrayList(java.util.ArrayList)

Example 15 with LineString

use of com.vividsolutions.jts.geom.LineString in project elasticsearch by elastic.

the class ShapeBuilderTests method testNewPolygon.

public void testNewPolygon() {
    Polygon polygon = ShapeBuilders.newPolygon(new CoordinatesBuilder().coordinate(-45, 30).coordinate(45, 30).coordinate(45, -30).coordinate(-45, -30).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) LineString(com.vividsolutions.jts.geom.LineString) ElasticsearchGeoAssertions.assertMultiLineString(org.elasticsearch.test.hamcrest.ElasticsearchGeoAssertions.assertMultiLineString) Coordinate(com.vividsolutions.jts.geom.Coordinate) ElasticsearchGeoAssertions.assertPolygon(org.elasticsearch.test.hamcrest.ElasticsearchGeoAssertions.assertPolygon) ElasticsearchGeoAssertions.assertMultiPolygon(org.elasticsearch.test.hamcrest.ElasticsearchGeoAssertions.assertMultiPolygon) Polygon(com.vividsolutions.jts.geom.Polygon)

Aggregations

LineString (com.vividsolutions.jts.geom.LineString)30 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)15 Coordinate (com.vividsolutions.jts.geom.Coordinate)12 Point (com.vividsolutions.jts.geom.Point)12 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)7 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