Search in sources :

Example 6 with SpatialOpsType

use of org.geotoolkit.ogc.xml.v100.SpatialOpsType in project geotoolkit by Geomatys.

the class FilterToOGC100Converter method visit.

@Override
public JAXBElement<?> visit(final Filter filter) {
    if (filter.equals(Filter.include())) {
        return null;
    }
    if (filter.equals(Filter.exclude())) {
        return null;
    }
    final CodeList<?> type = filter.getOperatorType();
    if (filter instanceof BetweenComparisonOperator) {
        final BetweenComparisonOperator pib = (BetweenComparisonOperator) filter;
        final PropertyIsBetweenType bot = ogc_factory.createPropertyIsBetweenType();
        final LowerBoundaryType lbt = ogc_factory.createLowerBoundaryType();
        lbt.setExpression(extract(pib.getLowerBoundary()));
        final UpperBoundaryType ubt = ogc_factory.createUpperBoundaryType();
        ubt.setExpression(extract(pib.getUpperBoundary()));
        bot.setExpression(extract(pib.getExpression()));
        bot.setLowerBoundary(lbt);
        bot.setUpperBoundary(ubt);
        return ogc_factory.createPropertyIsBetween(bot);
    } else if (type == ComparisonOperatorName.PROPERTY_IS_EQUAL_TO) {
        final BinaryComparisonOperator pit = (BinaryComparisonOperator) filter;
        final PropertyIsEqualToType bot = new PropertyIsEqualToType();
        bot.getExpression().add(extract(pit.getOperand1()));
        bot.getExpression().add(extract(pit.getOperand2()));
        return ogc_factory.createPropertyIsEqualTo(bot);
    } else if (type == ComparisonOperatorName.PROPERTY_IS_GREATER_THAN) {
        final BinaryComparisonOperator pit = (BinaryComparisonOperator) filter;
        final PropertyIsGreaterThanType bot = new PropertyIsGreaterThanType();
        bot.getExpression().add(extract(pit.getOperand1()));
        bot.getExpression().add(extract(pit.getOperand2()));
        return ogc_factory.createPropertyIsGreaterThan(bot);
    } else if (type == ComparisonOperatorName.PROPERTY_IS_GREATER_THAN_OR_EQUAL_TO) {
        final BinaryComparisonOperator pit = (BinaryComparisonOperator) filter;
        final PropertyIsGreaterThanOrEqualToType bot = new PropertyIsGreaterThanOrEqualToType();
        bot.getExpression().add(extract(pit.getOperand1()));
        bot.getExpression().add(extract(pit.getOperand2()));
        return ogc_factory.createPropertyIsGreaterThanOrEqualTo(bot);
    } else if (type == ComparisonOperatorName.PROPERTY_IS_LESS_THAN) {
        final BinaryComparisonOperator pit = (BinaryComparisonOperator) filter;
        final PropertyIsLessThanType bot = new PropertyIsLessThanType();
        bot.getExpression().add(extract(pit.getOperand1()));
        bot.getExpression().add(extract(pit.getOperand2()));
        return ogc_factory.createPropertyIsLessThan(bot);
    } else if (type == ComparisonOperatorName.PROPERTY_IS_LESS_THAN_OR_EQUAL_TO) {
        final BinaryComparisonOperator pit = (BinaryComparisonOperator) filter;
        final PropertyIsLessThanOrEqualToType bot = new PropertyIsLessThanOrEqualToType();
        bot.getExpression().add(extract(pit.getOperand1()));
        bot.getExpression().add(extract(pit.getOperand2()));
        return ogc_factory.createPropertyIsLessThanOrEqualTo(bot);
    } else if (filter instanceof LikeOperator) {
        final LikeOperator pis = (LikeOperator) filter;
        final List<Expression> expressions = filter.getExpressions();
        final PropertyIsLikeType bot = ogc_factory.createPropertyIsLikeType();
        bot.setEscape(String.valueOf(pis.getEscapeChar()));
        final LiteralType lt = ogc_factory.createLiteralType();
        lt.getContent().add(((Literal) expressions.get(1)).getValue());
        bot.setLiteral(lt);
        final Expression expression = expressions.get(0);
        if (!(expression instanceof ValueReference)) {
            throw new IllegalArgumentException("LikeOperator can support ValueReference only, but was a " + expression);
        }
        final PropertyNameType pnt = (PropertyNameType) extract(expression).getValue();
        bot.setPropertyName(pnt);
        bot.setSingleChar(String.valueOf(pis.getSingleChar()));
        bot.setWildCard(String.valueOf(pis.getWildCard()));
        return ogc_factory.createPropertyIsLike(bot);
    } else if (type == ComparisonOperatorName.PROPERTY_IS_NOT_EQUAL_TO) {
        final BinaryComparisonOperator pit = (BinaryComparisonOperator) filter;
        final PropertyIsNotEqualToType bot = new PropertyIsNotEqualToType();
        bot.getExpression().add(extract(pit.getOperand1()));
        bot.getExpression().add(extract(pit.getOperand2()));
        return ogc_factory.createPropertyIsNotEqualTo(bot);
    } else if (filter instanceof NullOperator) {
        final NullOperator pis = (NullOperator) filter;
        final PropertyIsNullType bot = ogc_factory.createPropertyIsNullType();
        final Object obj = extract((Expression) pis.getExpressions().get(0)).getValue();
        if (obj instanceof LiteralType) {
            bot.setLiteral((LiteralType) obj);
        } else if (obj instanceof PropertyNameType) {
            bot.setPropertyName((PropertyNameType) obj);
        } else {
            // should not be possible
            throw new IllegalArgumentException("Invalid expression element : " + obj);
        }
        return ogc_factory.createPropertyIsNull(bot);
    } else if (type == LogicalOperatorName.AND) {
        final LogicalOperator and = (LogicalOperator) filter;
        final AndType lot = new AndType();
        for (final Filter f : (List<Filter>) and.getOperands()) {
            lot.getComparisonOpsOrSpatialOpsOrLogicOps().add(visit(f));
        }
        return ogc_factory.createAnd(lot);
    } else if (type == LogicalOperatorName.OR) {
        final LogicalOperator or = (LogicalOperator) filter;
        final OrType lot = new OrType();
        for (final Filter f : (List<Filter>) or.getOperands()) {
            lot.getComparisonOpsOrSpatialOpsOrLogicOps().add(visit(f));
        }
        return ogc_factory.createOr(lot);
    } else if (type == LogicalOperatorName.NOT) {
        final LogicalOperator not = (LogicalOperator) filter;
        final NotType lot = new NotType();
        JAXBElement<?> sf = visit((Filter) not.getOperands().get(0));
        if (sf.getValue() instanceof ComparisonOpsType) {
            lot.setComparisonOps((JAXBElement<? extends ComparisonOpsType>) sf);
        } else if (sf.getValue() instanceof LogicOpsType) {
            lot.setLogicOps((JAXBElement<? extends LogicOpsType>) sf);
        } else if (sf.getValue() instanceof SpatialOpsType) {
            lot.setSpatialOps((JAXBElement<? extends SpatialOpsType>) sf);
        } else {
            // should not happen
            throw new IllegalArgumentException("invalid filter element : " + sf);
        }
        return ogc_factory.createNot(lot);
    } else if (type == SpatialOperatorName.BBOX) {
        final BBOX bbox = BBOX.wrap((BinarySpatialOperator) filter);
        final BBOXType bboxType = ogc_factory.createBBOXType();
        final Expression sourceExp1 = bbox.getOperand1();
        final JAXBElement<?> exp1 = extract(sourceExp1);
        final Expression sourceExp2 = bbox.getOperand2();
        JAXBElement<?> exp2 = extract(sourceExp2);
        final PropertyNameType pName;
        final BoxType boxType;
        if (exp1 != null && exp1.getValue() instanceof PropertyNameType) {
            pName = (PropertyNameType) exp1.getValue();
        } else if (exp2 != null && exp2.getValue() instanceof PropertyNameType) {
            pName = (PropertyNameType) exp2.getValue();
        } else
            throw new IllegalArgumentException("No property name found in given bbox filter");
        if (sourceExp1 instanceof Literal) {
            boxType = toBox((Literal) sourceExp1);
        } else if (sourceExp2 instanceof Literal) {
            boxType = toBox((Literal) sourceExp2);
        } else
            throw new IllegalArgumentException("No bbox found in given bbox filter");
        bboxType.setPropertyName(pName);
        bboxType.setBox(boxType);
        return ogc_factory.createBBOX(bboxType);
    }
    throw new IllegalArgumentException("Unknowed filter element : " + filter + " class :" + filter.getClass());
}
Also used : PropertyIsLessThanType(org.geotoolkit.ogc.xml.v100.PropertyIsLessThanType) AndType(org.geotoolkit.ogc.xml.v100.AndType) PropertyIsLessThanOrEqualToType(org.geotoolkit.ogc.xml.v100.PropertyIsLessThanOrEqualToType) BoxType(org.geotoolkit.gml.xml.v212.BoxType) PropertyIsNullType(org.geotoolkit.ogc.xml.v100.PropertyIsNullType) NotType(org.geotoolkit.ogc.xml.v100.NotType) SpatialOpsType(org.geotoolkit.ogc.xml.v100.SpatialOpsType) Literal(org.opengis.filter.Literal) CodeList(org.opengis.util.CodeList) List(java.util.List) PropertyIsBetweenType(org.geotoolkit.ogc.xml.v100.PropertyIsBetweenType) BetweenComparisonOperator(org.opengis.filter.BetweenComparisonOperator) ValueReference(org.opengis.filter.ValueReference) PropertyNameType(org.geotoolkit.ogc.xml.v100.PropertyNameType) OrType(org.geotoolkit.ogc.xml.v100.OrType) PropertyIsGreaterThanType(org.geotoolkit.ogc.xml.v100.PropertyIsGreaterThanType) LogicalOperator(org.opengis.filter.LogicalOperator) ComparisonOpsType(org.geotoolkit.ogc.xml.v100.ComparisonOpsType) LiteralType(org.geotoolkit.ogc.xml.v100.LiteralType) JAXBElement(javax.xml.bind.JAXBElement) PropertyIsGreaterThanOrEqualToType(org.geotoolkit.ogc.xml.v100.PropertyIsGreaterThanOrEqualToType) NullOperator(org.opengis.filter.NullOperator) LogicOpsType(org.geotoolkit.ogc.xml.v100.LogicOpsType) UpperBoundaryType(org.geotoolkit.ogc.xml.v100.UpperBoundaryType) PropertyIsNotEqualToType(org.geotoolkit.ogc.xml.v100.PropertyIsNotEqualToType) PropertyIsEqualToType(org.geotoolkit.ogc.xml.v100.PropertyIsEqualToType) BBOXType(org.geotoolkit.ogc.xml.v100.BBOXType) Expression(org.opengis.filter.Expression) Filter(org.opengis.filter.Filter) LowerBoundaryType(org.geotoolkit.ogc.xml.v100.LowerBoundaryType) LikeOperator(org.opengis.filter.LikeOperator) BinaryComparisonOperator(org.opengis.filter.BinaryComparisonOperator) PropertyIsLikeType(org.geotoolkit.ogc.xml.v100.PropertyIsLikeType)

Example 7 with SpatialOpsType

use of org.geotoolkit.ogc.xml.v100.SpatialOpsType in project geotoolkit by Geomatys.

the class OGC100toGTTransformer method visitSpatialOp.

/**
 * Transform a SLD spatial Filter v1.0 in GT filter.
 */
public Filter visitSpatialOp(final JAXBElement<? extends org.geotoolkit.ogc.xml.v100.SpatialOpsType> jax) {
    final org.geotoolkit.ogc.xml.v100.SpatialOpsType ops = jax.getValue();
    final String OpName = jax.getName().getLocalPart();
    if (ops instanceof org.geotoolkit.ogc.xml.v100.BinarySpatialOpType) {
        final org.geotoolkit.ogc.xml.v100.BinarySpatialOpType binary = (org.geotoolkit.ogc.xml.v100.BinarySpatialOpType) ops;
        final JAXBElement<? extends org.geotoolkit.gml.xml.v212.AbstractGeometryType> geom = binary.getGeometry();
        final org.geotoolkit.ogc.xml.v100.PropertyNameType pnt = binary.getPropertyName();
        final Expression left = filterFactory.property(pnt.getContent());
        final Expression right = visit(geom);
        if (OGCJAXBStatics.FILTER_SPATIAL_CONTAINS.equalsIgnoreCase(OpName)) {
            return filterFactory.contains(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_CROSSES.equalsIgnoreCase(OpName)) {
            return filterFactory.crosses(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_DISJOINT.equalsIgnoreCase(OpName)) {
            return filterFactory.disjoint(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_EQUALS.equalsIgnoreCase(OpName)) {
            return filterFactory.equals(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_INTERSECTS.equalsIgnoreCase(OpName)) {
            return filterFactory.intersects(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_OVERLAPS.equalsIgnoreCase(OpName)) {
            return filterFactory.overlaps(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_TOUCHES.equalsIgnoreCase(OpName)) {
            return filterFactory.touches(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_WITHIN.equalsIgnoreCase(OpName)) {
            return filterFactory.within(left, right);
        }
        throw new IllegalArgumentException("Illegal filter element" + OpName + " : " + ops);
    } else if (ops instanceof org.geotoolkit.ogc.xml.v100.DistanceBufferType) {
        final org.geotoolkit.ogc.xml.v100.DistanceBufferType dstOp = (org.geotoolkit.ogc.xml.v100.DistanceBufferType) ops;
        final org.geotoolkit.ogc.xml.v100.DistanceType dt = dstOp.getDistanceType();
        final JAXBElement<? extends org.geotoolkit.gml.xml.v212.AbstractGeometryType> geom = dstOp.getAbstractGeometry();
        final org.geotoolkit.ogc.xml.v100.PropertyNameType pnt = dstOp.getPropertyName();
        final Expression geom1 = filterFactory.property(pnt.getContent());
        final Expression geom2 = visit(geom);
        final double distance = Double.valueOf(dt.getContent());
        final String units = dt.getUnits();
        if (OGCJAXBStatics.FILTER_SPATIAL_DWITHIN.equalsIgnoreCase(OpName)) {
            return filterFactory.dwithin(geom1, geom2, distance, units);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_BEYOND.equalsIgnoreCase(OpName)) {
            return filterFactory.beyond(geom1, geom2, distance, units);
        }
        throw new IllegalArgumentException("Illegal filter element" + OpName + " : " + ops);
    } else if (ops instanceof org.geotoolkit.ogc.xml.v100.BBOXType) {
        final org.geotoolkit.ogc.xml.v100.BBOXType binary = (org.geotoolkit.ogc.xml.v100.BBOXType) ops;
        final org.geotoolkit.gml.xml.v212.BoxType box = binary.getBox();
        final org.geotoolkit.ogc.xml.v100.PropertyNameType pnt = binary.getPropertyNameType();
        final Expression geom = filterFactory.property(pnt.getContent());
        final double minx = box.getCoord().get(0).getX();
        final double maxx = box.getCoord().get(1).getX();
        final double miny = box.getCoord().get(0).getY();
        final double maxy = box.getCoord().get(1).getY();
        final String srs = box.getSrsName();
        if (OGCJAXBStatics.FILTER_SPATIAL_BBOX.equalsIgnoreCase(OpName)) {
            return filterFactory.bbox(geom, minx, miny, maxx, maxy, srs);
        }
        throw new IllegalArgumentException("Illegal filter element" + OpName + " : " + ops);
    }
    throw new IllegalArgumentException("Unknowed filter element" + jax);
}
Also used : PropertyNameType(org.geotoolkit.ogc.xml.v100.PropertyNameType) JAXBElement(javax.xml.bind.JAXBElement) PropertyNameType(org.geotoolkit.ogc.xml.v100.PropertyNameType) Expression(org.opengis.filter.Expression)

Example 8 with SpatialOpsType

use of org.geotoolkit.ogc.xml.v100.SpatialOpsType in project geotoolkit by Geomatys.

the class OGC110toGTTransformer method visitSpatialOp.

/**
 * Transform a SLD spatial Filter v1.1 in GT filter.
 */
public Filter visitSpatialOp(final JAXBElement<? extends org.geotoolkit.ogc.xml.v110.SpatialOpsType> jax) throws NoSuchAuthorityCodeException, FactoryException {
    final org.geotoolkit.ogc.xml.v110.SpatialOpsType ops = jax.getValue();
    final String OpName = jax.getName().getLocalPart();
    if (ops instanceof org.geotoolkit.ogc.xml.v110.BinarySpatialOpType) {
        final org.geotoolkit.ogc.xml.v110.BinarySpatialOpType binary = (org.geotoolkit.ogc.xml.v110.BinarySpatialOpType) ops;
        final JAXBElement<? extends AbstractGeometryType> geom = binary.getAbstractGeometry();
        final JAXBElement<EnvelopeType> env = binary.getEnvelope();
        final org.geotoolkit.ogc.xml.v110.PropertyNameType pnt = binary.getPropertyName().getValue();
        final Expression left = visitPropertyName(pnt);
        final Expression right;
        if (env != null && env.getValue() != null) {
            try {
                right = visitEnv(env);
            } catch (FactoryException ex) {
                throw new IllegalArgumentException("SRS name is unknowned : " + ex.getLocalizedMessage(), ex);
            }
        } else {
            right = visit(geom);
        }
        if (OGCJAXBStatics.FILTER_SPATIAL_CONTAINS.equalsIgnoreCase(OpName)) {
            return filterFactory.contains(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_CROSSES.equalsIgnoreCase(OpName)) {
            return filterFactory.crosses(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_DISJOINT.equalsIgnoreCase(OpName)) {
            return filterFactory.disjoint(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_EQUALS.equalsIgnoreCase(OpName)) {
            return filterFactory.equals(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_INTERSECTS.equalsIgnoreCase(OpName)) {
            return filterFactory.intersects(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_OVERLAPS.equalsIgnoreCase(OpName)) {
            return filterFactory.overlaps(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_TOUCHES.equalsIgnoreCase(OpName)) {
            return filterFactory.touches(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_WITHIN.equalsIgnoreCase(OpName)) {
            return filterFactory.within(left, right);
        }
        throw new IllegalArgumentException("Illegal filter element" + OpName + " : " + ops);
    } else if (ops instanceof org.geotoolkit.ogc.xml.v110.DistanceBufferType) {
        final org.geotoolkit.ogc.xml.v110.DistanceBufferType dstOp = (org.geotoolkit.ogc.xml.v110.DistanceBufferType) ops;
        final org.geotoolkit.ogc.xml.v110.DistanceType dt = dstOp.getDistanceType();
        final JAXBElement<? extends AbstractGeometryType> geom = dstOp.getAbstractGeometry();
        final org.geotoolkit.ogc.xml.v110.PropertyNameType pnt = dstOp.getPropertyName();
        final Expression geom1 = visitPropertyName(pnt);
        final Expression geom2 = visit(geom);
        // TODO marche pas ? ou est la distance ? Double.valueOf(dt.getContent());
        final double distance = 0;
        final String units = dt.getUnits();
        if (OGCJAXBStatics.FILTER_SPATIAL_DWITHIN.equalsIgnoreCase(OpName)) {
            return filterFactory.dwithin(geom1, geom2, distance, units);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_BEYOND.equalsIgnoreCase(OpName)) {
            return filterFactory.beyond(geom1, geom2, distance, units);
        }
        throw new IllegalArgumentException("Illegal filter element" + OpName + " : " + ops);
    } else if (ops instanceof org.geotoolkit.ogc.xml.v110.BBOXType) {
        final org.geotoolkit.ogc.xml.v110.BBOXType binary = (org.geotoolkit.ogc.xml.v110.BBOXType) ops;
        final EnvelopeType box = binary.getEnvelope();
        final String pnt = binary.getPropertyName();
        final Expression geom;
        if (pnt != null) {
            geom = visitPropertyName(pnt);
        } else {
            geom = null;
        }
        final double minx = box.getLowerCorner().getOrdinate(0);
        final double maxx = box.getUpperCorner().getOrdinate(0);
        final double miny = box.getLowerCorner().getOrdinate(1);
        final double maxy = box.getUpperCorner().getOrdinate(1);
        // final double minx = box.getPos().get(0).getOrdinate(0);
        // final double maxx = box.getPos().get(0).getOrdinate(1);
        // final double miny = box.getPos().get(1).getOrdinate(0);
        // final double maxy = box.getPos().get(1).getOrdinate(1);
        final String srs = box.getSrsName();
        if (OGCJAXBStatics.FILTER_SPATIAL_BBOX.equalsIgnoreCase(OpName)) {
            return filterFactory.bbox(geom, minx, miny, maxx, maxy, srs);
        }
        throw new IllegalArgumentException("Illegal filter element" + OpName + " : " + ops);
    }
    throw new IllegalArgumentException("Unknowed filter element" + jax);
}
Also used : FactoryException(org.opengis.util.FactoryException) PropertyNameType(org.geotoolkit.ogc.xml.v110.PropertyNameType) SpatialOpsType(org.geotoolkit.ogc.xml.v110.SpatialOpsType) PropertyNameType(org.geotoolkit.ogc.xml.v110.PropertyNameType) EnvelopeType(org.geotoolkit.gml.xml.v311.EnvelopeType) AbstractGeometryType(org.geotoolkit.gml.xml.v311.AbstractGeometryType) JAXBElement(javax.xml.bind.JAXBElement) Expression(org.opengis.filter.Expression)

Aggregations

JAXBElement (javax.xml.bind.JAXBElement)5 Filter (org.opengis.filter.Filter)5 QueryImpl (ddf.catalog.operation.impl.QueryImpl)3 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)3 ArrayList (java.util.ArrayList)3 SpatialOpsType (ogc.schema.opengis.filter.v_1_0_0.SpatialOpsType)3 BBOX (ogc.schema.opengis.filter_capabilities.v_1_0_0.BBOX)3 GetFeatureType (ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType)3 QueryType (ogc.schema.opengis.wfs.v_1_0_0.QueryType)3 Test (org.junit.Test)3 Expression (org.opengis.filter.Expression)3 List (java.util.List)2 ComparisonOpsType (org.geotoolkit.ogc.xml.v100.ComparisonOpsType)2 LogicOpsType (org.geotoolkit.ogc.xml.v100.LogicOpsType)2 PropertyNameType (org.geotoolkit.ogc.xml.v100.PropertyNameType)2 SpatialOpsType (org.geotoolkit.ogc.xml.v100.SpatialOpsType)2 SpatialOpsType (org.geotoolkit.ogc.xml.v110.SpatialOpsType)2 Intersect (ogc.schema.opengis.filter_capabilities.v_1_0_0.Intersect)1 BoxType (org.geotoolkit.gml.xml.v212.BoxType)1 AbstractGeometryType (org.geotoolkit.gml.xml.v311.AbstractGeometryType)1