Search in sources :

Example 6 with SurfaceImpl

use of org.geotools.geometry.jts.spatialschema.geometry.primitive.SurfaceImpl in project ddf by codice.

the class OpenSearchQueryTest method testPolygonSpatialFilter.

@Test
public void testPolygonSpatialFilter() throws Exception {
    String latLon = "0,10,0,30,20,30,20,10,0,10";
    String lonLat = "10,0,30,0,30,20,10,20,10,0";
    OpenSearchQuery query = new OpenSearchQuery(null, 0, 10, "relevance", "desc", 30000, FILTER_BUILDER);
    query.addPolygonSpatialFilter(latLon);
    Filter filter = query.getFilter();
    // String filterXml = getFilterAsXml( filter );
    VerificationVisitor verificationVisitor = new VerificationVisitor();
    filter.accept(verificationVisitor, null);
    HashMap<String, FilterStatus> map = (HashMap<String, FilterStatus>) verificationVisitor.getMap();
    printFilterStatusMap(map);
    // List<Filter> filters = getFilters( map, ContainsImpl.class.getName() );
    List<Filter> filters = getFilters(map, IntersectsImpl.class.getName());
    assertEquals(1, filters.size());
    // ContainsImpl containsFilter = (ContainsImpl) filters.get( 0 );
    IntersectsImpl containsFilter = (IntersectsImpl) filters.get(0);
    // The geometric point is wrapped in a <Literal> element, so have to
    // get geometry expression as literal and then evaluate it to get the
    // geometry.
    // Example:
    // <ogc:Literal>org.geotools.geometry.jts.spatialschema.geometry.primitive.SurfaceImpl@64a7c45e</ogc:Literal>
    Literal literalWrapper = (Literal) containsFilter.getExpression2();
    // Luckily we know what type the geometry expression should be, so we can cast it
    SurfaceImpl polygon = (SurfaceImpl) literalWrapper.evaluate(null);
    // WKT is lon/lat, polygon is lat/lon
    String[] expectedCoords = lonLat.split(",");
    Coordinate[] coords = polygon.getJTSGeometry().getCoordinates();
    int i = 0;
    for (Coordinate coord : coords) {
        LOGGER.debug("coord {}: x = {},   y = {}", (i + 1), coord.x, coord.y);
        int index = i * 2 + 1;
        assertEquals(Double.parseDouble(expectedCoords[index - 1]), coord.x, DOUBLE_DELTA);
        assertEquals(Double.parseDouble(expectedCoords[index]), coord.y, DOUBLE_DELTA);
        i++;
    }
}
Also used : HashMap(java.util.HashMap) SurfaceImpl(org.geotools.geometry.jts.spatialschema.geometry.primitive.SurfaceImpl) IntersectsImpl(org.geotools.filter.spatial.IntersectsImpl) TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) BBoxSpatialFilter(org.codice.ddf.opensearch.query.filter.BBoxSpatialFilter) PolygonSpatialFilter(org.codice.ddf.opensearch.query.filter.PolygonSpatialFilter) Filter(org.opengis.filter.Filter) Coordinate(com.vividsolutions.jts.geom.Coordinate) Literal(org.opengis.filter.expression.Literal) Test(org.junit.Test)

Aggregations

SurfaceImpl (org.geotools.geometry.jts.spatialschema.geometry.primitive.SurfaceImpl)6 Literal (org.opengis.filter.expression.Literal)6 Coordinate (com.vividsolutions.jts.geom.Coordinate)3 Point (com.vividsolutions.jts.geom.Point)2 Polygon (com.vividsolutions.jts.geom.Polygon)2 PropertyIsEqualToLiteral (ddf.catalog.filter.impl.PropertyIsEqualToLiteral)2 SpatialFilter (ddf.catalog.impl.filter.SpatialFilter)2 TemporalFilter (ddf.catalog.impl.filter.TemporalFilter)2 HashMap (java.util.HashMap)2 BBoxSpatialFilter (org.codice.ddf.opensearch.query.filter.BBoxSpatialFilter)2 PolygonSpatialFilter (org.codice.ddf.opensearch.query.filter.PolygonSpatialFilter)2 IntersectsImpl (org.geotools.filter.spatial.IntersectsImpl)2 Test (org.junit.Test)2 Filter (org.opengis.filter.Filter)2