Search in sources :

Example 86 with LineString

use of org.locationtech.jts.geom.LineString in project graphhopper by graphhopper.

the class GraphHopperMultimodalIT method readWktLineString.

private LineString readWktLineString(String wkt) {
    WKTReader wktReader = new WKTReader();
    LineString expectedGeometry = null;
    try {
        expectedGeometry = (LineString) wktReader.read(wkt);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return expectedGeometry;
}
Also used : LineString(org.locationtech.jts.geom.LineString) ParseException(org.locationtech.jts.io.ParseException) WKTReader(org.locationtech.jts.io.WKTReader)

Example 87 with LineString

use of org.locationtech.jts.geom.LineString in project ddf by codice.

the class OpenSearchFilterVisitor method buildGeometrySearch.

protected static void buildGeometrySearch(BinarySpatialOperator filter, Object data) {
    OpenSearchFilterVisitorObject openSearchFilterVisitorObject = getOpenSearchFilterVisitorObjectFromData(data);
    if (openSearchFilterVisitorObject == null) {
        return;
    }
    if (NestedTypes.NOT.equals(openSearchFilterVisitorObject.getCurrentNest())) {
        LOGGER.debug(NOT_OPERATOR_UNSUPPORTED_MSG);
        return;
    }
    final org.opengis.filter.expression.Expression expression1 = filter.getExpression1();
    final String expectedSpatialSearchTerm = OpenSearchConstants.SUPPORTED_SPATIAL_SEARCH_TERM;
    if (!expectedSpatialSearchTerm.equals(expression1.toString())) {
        LOGGER.debug("Opensearch only supports spatial criteria on the term \"{}\", but expression1 is \"{}\". Ignoring filter.", expectedSpatialSearchTerm, expression1);
        return;
    }
    // The geometry is wrapped in a <Literal> element, so have to get the geometry expression as a
    // literal and then evaluate it to get the geometry.
    // Example:
    // <ogc:Literal>org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl@dc33f184</ogc:Literal>
    Literal literalWrapper = (Literal) filter.getExpression2();
    Object geometryExpression = literalWrapper.getValue();
    if (geometryExpression instanceof SurfaceImpl) {
        SurfaceImpl surface = (SurfaceImpl) literalWrapper.evaluate(null);
        Geometry polygon = surface.getJTSGeometry();
        openSearchFilterVisitorObject.addGeometrySearch(polygon);
    } else if (geometryExpression instanceof Polygon) {
        Geometry polygon = (Geometry) literalWrapper.evaluate(null);
        openSearchFilterVisitorObject.addGeometrySearch(polygon);
    } else if (geometryExpression instanceof GeometryImpl) {
        Geometry polygon = ((GeometryImpl) geometryExpression).getJTSGeometry();
        openSearchFilterVisitorObject.addGeometrySearch(polygon);
    } else if (geometryExpression instanceof MultiPolygon) {
        Geometry polygon = ((MultiPolygon) geometryExpression);
        openSearchFilterVisitorObject.addGeometrySearch(polygon);
    } else if (geometryExpression instanceof LineString) {
        Geometry polygon = ((LineString) geometryExpression);
        openSearchFilterVisitorObject.addGeometrySearch(polygon);
    } else if (geometryExpression instanceof MultiLineString) {
        Geometry polygon = ((MultiLineString) geometryExpression);
        openSearchFilterVisitorObject.addGeometrySearch(polygon);
    } else {
        LOGGER.debug("Unsupported filter constraint");
    }
}
Also used : MultiLineString(org.locationtech.jts.geom.MultiLineString) Expression(org.opengis.filter.expression.Expression) GeometryImpl(org.geotools.geometry.jts.spatialschema.geometry.GeometryImpl) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) SurfaceImpl(org.geotools.geometry.jts.spatialschema.geometry.primitive.SurfaceImpl) Geometry(org.locationtech.jts.geom.Geometry) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) Literal(org.opengis.filter.expression.Literal) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon)

Example 88 with LineString

use of org.locationtech.jts.geom.LineString in project jena by apache.

the class WKTReaderTest method testExtractGeometryCollection.

/**
 * Test of extract method, of class WKTReader.
 */
@Test
public void testExtractGeometryCollection() {
    String wktText = "GEOMETRYCOLLECTION(POINT(4 6),LINESTRING(4 6,7 10), MULTIPOINT((6 8),(2 3)))";
    WKTReader expResult = new WKTReader("geometrycollection", "", "(POINT(4 6),LINESTRING(4 6,7 10), MULTIPOINT((6 8),(2 3)))");
    WKTReader result = WKTReader.extract(wktText);
    // 
    // 
    assertEquals(expResult, result);
}
Also used : LineString(org.locationtech.jts.geom.LineString) Test(org.junit.Test)

Example 89 with LineString

use of org.locationtech.jts.geom.LineString in project jena by apache.

the class WKTDatatypeTest method testReadMultiLineString.

/**
 * Test of read method, of class WKTReader.
 */
@Test
public void testReadMultiLineString() {
    String wktLiteral = "MULTILINESTRING ZM((10 10 0 1, 20 20 0 1, 10 40 0 1), (40 40 0 1, 30 30 0 1, 40 20 0 1, 30 10 0 1))";
    LineString[] lineStrings = new LineString[2];
    lineStrings[0] = GEOMETRY_FACTORY.createLineString(new CustomCoordinateSequence(CoordinateSequenceDimensions.XYZM, "10 10 0 1, 20 20 0 1, 10 40 0 1"));
    lineStrings[1] = GEOMETRY_FACTORY.createLineString(new CustomCoordinateSequence(CoordinateSequenceDimensions.XYZM, "40 40 0 1, 30 30 0 1, 40 20 0 1, 30 10 0 1"));
    Geometry geometry = GEOMETRY_FACTORY.createMultiLineString(lineStrings);
    GeometryWrapper expResult = new GeometryWrapper(geometry, SRS_URI.DEFAULT_WKT_CRS84, WKTDatatype.URI, new DimensionInfo(4, 3, 1));
    GeometryWrapper result = WKT_DATATYPE.read(wktLiteral);
    // 
    // 
    assertEquals(expResult, result);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) LineString(org.locationtech.jts.geom.LineString) GeometryWrapper(org.apache.jena.geosparql.implementation.GeometryWrapper) DimensionInfo(org.apache.jena.geosparql.implementation.DimensionInfo) LineString(org.locationtech.jts.geom.LineString) CustomCoordinateSequence(org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence) Test(org.junit.Test)

Example 90 with LineString

use of org.locationtech.jts.geom.LineString in project jena by apache.

the class WKTDatatypeTest method testReadLineString.

/**
 * Test of read method, of class WKTReader.
 */
@Test
public void testReadLineString() {
    String wktLiteral = "LINESTRING ZM (11 12.1 8 5, 3 4 6 2)";
    Geometry geometry = GEOMETRY_FACTORY.createLineString(new CustomCoordinateSequence(CoordinateSequenceDimensions.XYZM, "11 12.1 8 5, 3 4 6 2"));
    GeometryWrapper expResult = new GeometryWrapper(geometry, SRS_URI.DEFAULT_WKT_CRS84, WKTDatatype.URI, new DimensionInfo(4, 3, 1));
    GeometryWrapper result = WKT_DATATYPE.read(wktLiteral);
    // 
    // 
    assertEquals(expResult, result);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryWrapper(org.apache.jena.geosparql.implementation.GeometryWrapper) DimensionInfo(org.apache.jena.geosparql.implementation.DimensionInfo) LineString(org.locationtech.jts.geom.LineString) CustomCoordinateSequence(org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence) Test(org.junit.Test)

Aggregations

LineString (org.locationtech.jts.geom.LineString)120 MultiLineString (org.locationtech.jts.geom.MultiLineString)48 Coordinate (org.locationtech.jts.geom.Coordinate)38 Geometry (org.locationtech.jts.geom.Geometry)35 Point (org.locationtech.jts.geom.Point)32 Test (org.junit.Test)24 Polygon (org.locationtech.jts.geom.Polygon)21 MultiPoint (org.locationtech.jts.geom.MultiPoint)19 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)14 WKTReader (org.locationtech.jts.io.WKTReader)13 ArrayList (java.util.ArrayList)12 CustomCoordinateSequence (org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence)12 HashMap (java.util.HashMap)10 DimensionInfo (org.apache.jena.geosparql.implementation.DimensionInfo)9 GeometryWrapper (org.apache.jena.geosparql.implementation.GeometryWrapper)9 ParseException (org.locationtech.jts.io.ParseException)9 DefaultGeometryProperty (eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty)8 GeometryNotSupportedException (eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException)7 MultiPolygon (org.locationtech.jts.geom.MultiPolygon)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)6