Search in sources :

Example 16 with Geometry

use of org.opengis.geometry.Geometry in project ddf by codice.

the class MockQuery method addSpatialFilter.

public void addSpatialFilter(String geometryWkt) {
    SpatialFilter spatialFilter = new SpatialFilter(geometryWkt);
    Geometry geometry = spatialFilter.getGeometry();
    if (geometry != null) {
        Filter filter = FILTER_FACTORY.contains(Metacard.ANY_GEO, geometry);
        filters.add(filter);
        this.filter = getFilter();
    }
}
Also used : Geometry(org.opengis.geometry.Geometry) SpatialFilter(ddf.catalog.impl.filter.SpatialFilter) TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) SpatialDistanceFilter(ddf.catalog.impl.filter.SpatialDistanceFilter) Filter(org.opengis.filter.Filter) SpatialFilter(ddf.catalog.impl.filter.SpatialFilter)

Example 17 with Geometry

use of org.opengis.geometry.Geometry in project ddf by codice.

the class MockQuery method addSpatialDistanceFilter.

public void addSpatialDistanceFilter(String lon, String lat, String radius) {
    SpatialDistanceFilter distanceFilter = new SpatialDistanceFilter(lon, lat, radius);
    Geometry geometry = distanceFilter.getGeometry();
    if (geometry != null) {
        Filter filter = FILTER_FACTORY.dwithin(Metacard.ANY_GEO, geometry, Double.parseDouble(radius), UomOgcMapping.METRE.getSEString());
        filters.add(filter);
        this.filter = getFilter();
    }
}
Also used : Geometry(org.opengis.geometry.Geometry) SpatialFilter(ddf.catalog.impl.filter.SpatialFilter) TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) SpatialDistanceFilter(ddf.catalog.impl.filter.SpatialDistanceFilter) Filter(org.opengis.filter.Filter) SpatialDistanceFilter(ddf.catalog.impl.filter.SpatialDistanceFilter)

Example 18 with Geometry

use of org.opengis.geometry.Geometry in project ddf by codice.

the class OpenSearchQuery method addSpatialDistanceFilter.

public void addSpatialDistanceFilter(String lon, String lat, String radius) {
    SpatialDistanceFilter distanceFilter = new SpatialDistanceFilter(lon, lat, radius);
    Geometry geometry = distanceFilter.getGeometry();
    if (geometry != null) {
        Filter filter = FILTER_FACTORY.dwithin(Metacard.ANY_GEO, geometry, Double.parseDouble(radius), UomOgcMapping.METRE.name());
        LOGGER.debug("Adding spatial filter");
        filters.add(filter);
    }
}
Also used : Geometry(org.opengis.geometry.Geometry) SpatialFilter(ddf.catalog.impl.filter.SpatialFilter) TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) SpatialDistanceFilter(ddf.catalog.impl.filter.SpatialDistanceFilter) PolygonSpatialFilter(org.codice.ddf.opensearch.query.filter.PolygonSpatialFilter) Filter(org.opengis.filter.Filter) BBoxSpatialFilter(org.codice.ddf.opensearch.query.filter.BBoxSpatialFilter) SpatialDistanceFilter(ddf.catalog.impl.filter.SpatialDistanceFilter)

Example 19 with Geometry

use of org.opengis.geometry.Geometry in project ddf by codice.

the class OpenSearchQueryTest method testWktParser.

@Test
public void testWktParser() throws Exception {
    String geometryWkt = "POINT( 48.44 -123.37)";
    GeometryBuilder builder = new GeometryBuilder(DefaultGeographicCRS.WGS84);
    WKTParser parser = new WKTParser(builder);
    // This fixed the NPE in parser.parse() - seems GeoTools has bug with
    // keeping the CRS hint set ...
    parser.setFactory(new PrimitiveFactoryImpl(DefaultGeographicCRS.WGS84));
    Geometry geometry = parser.parse(geometryWkt);
    CoordinateReferenceSystem crs = geometry.getCoordinateReferenceSystem();
    assertNotNull(crs);
    String geometryWkt2 = "POINT( 48.44 -123.37)";
    builder = new GeometryBuilder(DefaultGeographicCRS.WGS84);
    WKTParser parser2 = new WKTParser(builder);
    Geometry geometry2 = parser2.parse(geometryWkt2);
    assertTrue(geometry2.intersects(geometry));
    double[] coords = geometry.getCentroid().getCoordinate();
    LOGGER.debug("coords[0] = {},   coords[1] = {}", coords[0], coords[1]);
}
Also used : Geometry(org.opengis.geometry.Geometry) PrimitiveFactoryImpl(org.geotools.geometry.jts.spatialschema.geometry.primitive.PrimitiveFactoryImpl) WKTParser(org.geotools.geometry.text.WKTParser) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) GeometryBuilder(org.geotools.geometry.GeometryBuilder) Test(org.junit.Test)

Example 20 with Geometry

use of org.opengis.geometry.Geometry in project ddf by codice.

the class SpatialFilter method getGeometry.

public Geometry getGeometry() {
    Geometry geometry = null;
    try {
        if (geometryWkt.toLowerCase(Locale.US).startsWith("multi") || geometryWkt.toLowerCase(Locale.US).trim().indexOf("geometrycollection") != -1) {
            // WKTParser does not currently support MultiPolygon,
            // MultiLineString, or MultiPoint
            com.vividsolutions.jts.geom.Geometry geo = reader.read(geometryWkt);
            geometry = new JTSGeometryWrapper(geo);
        } else {
            geometry = parser.parse(geometryWkt);
        }
    } catch (ParseException e) {
        LOGGER.debug("Unable to compute geometry for WKT = {}", this.geometryWkt, e);
    } catch (com.vividsolutions.jts.io.ParseException e) {
        LOGGER.debug("Unable to read multi geometry for WKT = {}", this.geometryWkt, e);
    }
    return geometry;
}
Also used : Geometry(org.opengis.geometry.Geometry) ParseException(java.text.ParseException)

Aggregations

Geometry (org.opengis.geometry.Geometry)28 Test (org.junit.Test)22 Filter (org.opengis.filter.Filter)5 SpatialDistanceFilter (ddf.catalog.impl.filter.SpatialDistanceFilter)4 SpatialFilter (ddf.catalog.impl.filter.SpatialFilter)4 TemporalFilter (ddf.catalog.impl.filter.TemporalFilter)4 JTSGeometryWrapper (ddf.catalog.impl.filter.JTSGeometryWrapper)2 BBoxSpatialFilter (org.codice.ddf.opensearch.query.filter.BBoxSpatialFilter)2 PolygonSpatialFilter (org.codice.ddf.opensearch.query.filter.PolygonSpatialFilter)2 GeometryBuilder (org.geotools.geometry.GeometryBuilder)2 PrimitiveFactoryImpl (org.geotools.geometry.jts.spatialschema.geometry.primitive.PrimitiveFactoryImpl)2 WKTParser (org.geotools.geometry.text.WKTParser)2 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)2 ParseException (com.vividsolutions.jts.io.ParseException)1 WKTReader (com.vividsolutions.jts.io.WKTReader)1 FilterBuilder (ddf.catalog.filter.FilterBuilder)1 GeotoolsFilterBuilder (ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder)1 ParseException (java.text.ParseException)1 DefaultFilterVisitor (org.geotools.filter.visitor.DefaultFilterVisitor)1 Ignore (org.junit.Ignore)1