Search in sources :

Example 1 with SurfaceImpl

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

the class OpenSearchQueryTest method testBboxSpatialFilter.

@Test
public void testBboxSpatialFilter() throws Exception {
    String bboxCorners = "0,10,20,30";
    OpenSearchQuery query = new OpenSearchQuery(null, 0, 10, "relevance", "desc", 30000, FILTER_BUILDER);
    query.addBBoxSpatialFilter(bboxCorners);
    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 bbox = (SurfaceImpl) literalWrapper.evaluate(null);
    String[] expectedCoords = bboxCorners.split(",");
    double[] lowerCornerCoords = bbox.getEnvelope().getLowerCorner().getCoordinate();
    LOGGER.debug("lowerCornerCoords:  [0] = {},   [1] = {}", lowerCornerCoords[0], lowerCornerCoords[1]);
    assertEquals(Double.parseDouble(expectedCoords[0]), lowerCornerCoords[0], DOUBLE_DELTA);
    assertEquals(Double.parseDouble(expectedCoords[1]), lowerCornerCoords[1], DOUBLE_DELTA);
    double[] upperCornerCoords = bbox.getEnvelope().getUpperCorner().getCoordinate();
    LOGGER.debug("upperCornerCoords:  [0] = {},   [1] = {}", upperCornerCoords[0], upperCornerCoords[1]);
    assertEquals(Double.parseDouble(expectedCoords[2]), upperCornerCoords[0], DOUBLE_DELTA);
    assertEquals(Double.parseDouble(expectedCoords[3]), upperCornerCoords[1], DOUBLE_DELTA);
}
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) Literal(org.opengis.filter.expression.Literal) Test(org.junit.Test)

Example 2 with SurfaceImpl

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

the class OpenSearchFilterVisitor method visit.

/**
     * Contains filter maps to a Polygon or BBox Spatial search criteria.
     */
@Override
public Object visit(Contains filter, Object data) {
    LOGGER.trace("ENTERING: Contains filter");
    if (currentNest == null || NestedTypes.AND.equals(currentNest)) {
        // 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) filter.getExpression2();
        Object geometryExpression = literalWrapper.getValue();
        StringBuffer geometryWkt = new StringBuffer();
        if (geometryExpression instanceof SurfaceImpl) {
            SurfaceImpl polygon = (SurfaceImpl) literalWrapper.evaluate(null);
            Coordinate[] coords = polygon.getJTSGeometry().getCoordinates();
            geometryWkt.append("POLYGON((");
            for (int i = 0; i < coords.length; i++) {
                geometryWkt.append(coords[i].x);
                geometryWkt.append(" ");
                geometryWkt.append(coords[i].y);
                if (i != (coords.length - 1)) {
                    geometryWkt.append(",");
                }
            }
            geometryWkt.append("))");
            this.spatialSearch = new SpatialFilter(geometryWkt.toString());
            LOGGER.debug("geometryWkt = [{}]", geometryWkt.toString());
            filters.add(filter);
        } else {
            LOGGER.debug("Only POLYGON geometry WKT for Contains filter is supported");
        }
    } else {
        LOGGER.debug(ONLY_AND_MSG);
    }
    LOGGER.trace("EXITING: Contains filter");
    return super.visit(filter, data);
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) PropertyIsEqualToLiteral(ddf.catalog.filter.impl.PropertyIsEqualToLiteral) Literal(org.opengis.filter.expression.Literal) SpatialFilter(ddf.catalog.impl.filter.SpatialFilter) SurfaceImpl(org.geotools.geometry.jts.spatialschema.geometry.primitive.SurfaceImpl)

Example 3 with SurfaceImpl

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

the class OpenSearchFilterVisitor method visit.

/**
     * Intersects filter maps to a Polygon or BBox Spatial search criteria.
     */
@Override
public Object visit(Intersects filter, Object data) {
    LOGGER.trace("ENTERING: Intersects filter");
    if (currentNest == null || NestedTypes.AND.equals(currentNest)) {
        // 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) filter.getExpression2();
        Object geometryExpression = literalWrapper.getValue();
        StringBuffer geometryWkt = new StringBuffer();
        if (geometryExpression instanceof SurfaceImpl) {
            SurfaceImpl polygon = (SurfaceImpl) literalWrapper.evaluate(null);
            Coordinate[] coords = polygon.getJTSGeometry().getCoordinates();
            geometryWkt.append("POLYGON((");
            for (int i = 0; i < coords.length; i++) {
                geometryWkt.append(coords[i].x);
                geometryWkt.append(" ");
                geometryWkt.append(coords[i].y);
                if (i != (coords.length - 1)) {
                    geometryWkt.append(",");
                }
            }
            geometryWkt.append("))");
            this.spatialSearch = new SpatialFilter(geometryWkt.toString());
            LOGGER.debug("geometryWkt = [{}]", geometryWkt.toString());
            filters.add(filter);
        } else {
            LOGGER.debug("Only POLYGON geometry WKT for Intersects filter is supported");
        }
    } else {
        LOGGER.debug(ONLY_AND_MSG);
    }
    LOGGER.trace("EXITING: Intersects filter");
    return super.visit(filter, data);
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) PropertyIsEqualToLiteral(ddf.catalog.filter.impl.PropertyIsEqualToLiteral) Literal(org.opengis.filter.expression.Literal) SpatialFilter(ddf.catalog.impl.filter.SpatialFilter) SurfaceImpl(org.geotools.geometry.jts.spatialschema.geometry.primitive.SurfaceImpl)

Example 4 with SurfaceImpl

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

the class TwitterFilterVisitor method visit.

/**
     * Contains filter maps to a Polygon or BBox Spatial search criteria.
     */
@Override
public Object visit(Contains filter, Object data) {
    LOGGER.trace("ENTERING: Contains filter");
    if (currentNest == null || NestedTypes.AND.equals(currentNest)) {
        // 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) filter.getExpression2();
        Object geometryExpression = literalWrapper.getValue();
        if (geometryExpression instanceof SurfaceImpl) {
            SurfaceImpl polygon = (SurfaceImpl) literalWrapper.evaluate(null);
            Point point = polygon.getJTSGeometry().getCentroid();
            longitude = point.getX();
            latitude = point.getY();
            radius = point.getBoundary().getLength() * 10;
            hasSpatial = true;
            filters.add(filter);
        } else if (geometryExpression instanceof Polygon) {
            Polygon polygon = (Polygon) geometryExpression;
            Point centroid = polygon.getCentroid();
            longitude = centroid.getX();
            latitude = centroid.getY();
            radius = polygon.getBoundary().getLength() * 10;
            hasSpatial = true;
            filters.add(filter);
        } else {
            LOGGER.warn("Only POLYGON geometry WKT for Contains filter is supported");
        }
    } else {
        LOGGER.warn(ONLY_AND_MSG);
    }
    LOGGER.trace("EXITING: Contains filter");
    return super.visit(filter, data);
}
Also used : Literal(org.opengis.filter.expression.Literal) SurfaceImpl(org.geotools.geometry.jts.spatialschema.geometry.primitive.SurfaceImpl) Point(com.vividsolutions.jts.geom.Point) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 5 with SurfaceImpl

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

the class TwitterFilterVisitor method visit.

/**
     * Intersects filter maps to a Polygon or BBox Spatial search criteria.
     */
@Override
public Object visit(Intersects filter, Object data) {
    LOGGER.trace("ENTERING: Intersects filter");
    if (currentNest == null || NestedTypes.AND.equals(currentNest)) {
        // 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) filter.getExpression2();
        Object geometryExpression = literalWrapper.getValue();
        if (geometryExpression instanceof SurfaceImpl) {
            SurfaceImpl polygon = (SurfaceImpl) literalWrapper.evaluate(null);
            Point point = polygon.getJTSGeometry().getCentroid();
            longitude = point.getX();
            latitude = point.getY();
            radius = point.getBoundary().getLength() * 10;
            hasSpatial = true;
            filters.add(filter);
        } else if (geometryExpression instanceof Polygon) {
            Polygon polygon = (Polygon) geometryExpression;
            Point centroid = polygon.getCentroid();
            longitude = centroid.getX();
            latitude = centroid.getY();
            radius = polygon.getBoundary().getLength() * 10;
            hasSpatial = true;
            filters.add(filter);
        } else {
            LOGGER.warn("Only POLYGON geometry WKT for Intersects filter is supported");
        }
    } else {
        LOGGER.warn(ONLY_AND_MSG);
    }
    LOGGER.trace("EXITING: Intersects filter");
    return super.visit(filter, data);
}
Also used : Literal(org.opengis.filter.expression.Literal) SurfaceImpl(org.geotools.geometry.jts.spatialschema.geometry.primitive.SurfaceImpl) Point(com.vividsolutions.jts.geom.Point) Polygon(com.vividsolutions.jts.geom.Polygon)

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