Search in sources :

Example 6 with SpatialFilter

use of org.n52.shetland.ogc.filter.SpatialFilter in project arctic-sea by 52North.

the class SpatialFilterDecoder method decodeJSON.

@Override
public SpatialFilter decodeJSON(JsonNode node, boolean validate) throws DecodingException {
    if (node == null || node.isNull() || node.isMissingNode()) {
        return null;
    }
    if (validate) {
        JSONValidator.getInstance().validateAndThrow(node, SchemaConstants.Common.SPATIAL_FILTER);
    }
    if (node.isObject()) {
        final String oName = node.fields().next().getKey();
        final SOp o = SOp.valueOf(oName);
        JsonNode value = node.path(oName).path(JSONConstants.VALUE);
        JsonNode ref = node.path(oName).path(JSONConstants.REF);
        return new SpatialFilter(o.getOp(), decodeGeometry(value), ref.textValue());
    } else {
        return null;
    }
}
Also used : SpatialFilter(org.n52.shetland.ogc.filter.SpatialFilter) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 7 with SpatialFilter

use of org.n52.shetland.ogc.filter.SpatialFilter in project arctic-sea by 52North.

the class ODataFesParserTest method testFeatureOfInterestShapeGeoIntersectsPolygon.

@Test
public void testFeatureOfInterestShapeGeoIntersectsPolygon() throws Exception {
    Filter<?> filter = parser.decode(String.format("geo.intersects(featureOfInterest/shape,'SRID=%s;%s')", polygon.getSRID(), wktGeometry));
    assertThat(filter, is(instanceOf(SpatialFilter.class)));
    SpatialFilter sf = (SpatialFilter) filter;
    errors.checkThat(sf.getSrid(), is(4326));
    errors.checkThat(sf.getGeometry().isEnvelope(), is(false));
    errors.checkThat(sf.getGeometry().isGeometry(), is(true));
    errors.checkThat(sf.getGeometry().getGeometry().get(), is(instanceOf(Polygon.class)));
    errors.checkThat(sf.getValueReference(), is("om:featureOfInterest/*/sams:shape"));
}
Also used : SpatialFilter(org.n52.shetland.ogc.filter.SpatialFilter) Test(org.junit.Test)

Example 8 with SpatialFilter

use of org.n52.shetland.ogc.filter.SpatialFilter in project arctic-sea by 52North.

the class ODataFesParserTest method testSamplingGeometryGeoIntersectsPolygon.

@Test
public void testSamplingGeometryGeoIntersectsPolygon() throws Exception {
    Filter<?> filter = parser.decode(String.format("geo.intersects(samplingGeometry,'SRID=%s;%s')", polygon.getSRID(), wktGeometry));
    assertThat(filter, is(instanceOf(SpatialFilter.class)));
    SpatialFilter sf = (SpatialFilter) filter;
    errors.checkThat(sf.getSrid(), is(4326));
    errors.checkThat(sf.getGeometry().isEnvelope(), is(false));
    errors.checkThat(sf.getGeometry().isGeometry(), is(true));
    errors.checkThat(sf.getGeometry().getGeometry().get(), is(instanceOf(Polygon.class)));
    errors.checkThat(sf.getValueReference(), is("http://www.opengis.net/req/omxml/2.0/data/samplingGeometry"));
}
Also used : SpatialFilter(org.n52.shetland.ogc.filter.SpatialFilter) Test(org.junit.Test)

Example 9 with SpatialFilter

use of org.n52.shetland.ogc.filter.SpatialFilter in project arctic-sea by 52North.

the class OgcDecoderv100 method parseBBOXFilterType.

/**
 * Parses the spatial filter of a request.
 *
 * @param xbBBOX XmlBean representing the feature of interest parameter of the request
 *
 * @return Returns SpatialFilter created from the passed foi request parameter
 *
 * @throws DecodingException * if creation of the SpatialFilter failed
 */
private SpatialFilter parseBBOXFilterType(BBOXTypeImpl xbBBOX) throws DecodingException {
    SpatialFilter spatialFilter = new SpatialFilter();
    // FIXME local workaround for SOSHelper check value reference
    String valueRef = "om:featureOfInterest/sams:SF_SpatialSamplingFeature/sams:shape";
    try {
        spatialFilter.setOperator(FilterConstants.SpatialOperator.BBOX);
        XmlCursor geometryCursor = xbBBOX.newCursor();
        if (geometryCursor.toChild(GmlConstants.QN_ENVELOPE)) {
            Object sosGeometry = decodeXmlElement(XmlObject.Factory.parse(geometryCursor.getDomNode()));
            // }
            if (sosGeometry instanceof Geometry) {
                spatialFilter.setGeometry((Geometry) sosGeometry);
                spatialFilter.setValueReference(valueRef);
            }
        } else {
            throw unsupportedSpatialFilterOperand();
        }
        geometryCursor.dispose();
    } catch (XmlException xmle) {
        throw errorParsingSpatialFilter(xmle);
    }
    return spatialFilter;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) XmlException(org.apache.xmlbeans.XmlException) SpatialFilter(org.n52.shetland.ogc.filter.SpatialFilter) XmlObject(org.apache.xmlbeans.XmlObject) XmlCursor(org.apache.xmlbeans.XmlCursor)

Aggregations

SpatialFilter (org.n52.shetland.ogc.filter.SpatialFilter)9 XmlObject (org.apache.xmlbeans.XmlObject)5 XmlCursor (org.apache.xmlbeans.XmlCursor)3 XmlException (org.apache.xmlbeans.XmlException)3 Test (org.junit.Test)3 Geometry (org.locationtech.jts.geom.Geometry)3 BBOXType (net.opengis.fes.x20.BBOXType)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Set (java.util.Set)1 BBOXTypeImpl (net.opengis.ogc.impl.BBOXTypeImpl)1 GetFeatureOfInterest (net.opengis.sos.x10.GetFeatureOfInterestDocument.GetFeatureOfInterest)1 GetObservation (net.opengis.sos.x10.GetObservationDocument.GetObservation)1 FeatureOfInterest (net.opengis.sos.x10.GetObservationDocument.GetObservation.FeatureOfInterest)1 Envelope (org.locationtech.jts.geom.Envelope)1 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)1 OwsServiceCommunicationObject (org.n52.shetland.ogc.ows.service.OwsServiceCommunicationObject)1 GetObservationRequest (org.n52.shetland.ogc.sos.request.GetObservationRequest)1 ReferencedEnvelope (org.n52.shetland.util.ReferencedEnvelope)1 DecodingException (org.n52.svalbard.decode.exception.DecodingException)1 NotYetSupportedDecodingException (org.n52.svalbard.decode.exception.NotYetSupportedDecodingException)1