Search in sources :

Example 1 with BoxType

use of org.geotoolkit.gml.xml.v212.BoxType in project ddf by codice.

the class WfsFilterDelegate method buildBBoxType.

private JAXBElement<BBOXType> buildBBoxType(String propertyName, String wkt) {
    BBOXType bboxType = new BBOXType();
    JAXBElement<BoxType> box = createBoxType(wkt);
    bboxType.setBox(box.getValue());
    bboxType.setPropertyName(createPropertyNameType(propertyName).getValue());
    return filterObjectFactory.createBBOX(bboxType);
}
Also used : BBOXType(ogc.schema.opengis.filter.v_1_0_0.BBOXType) BoxType(ogc.schema.opengis.gml.v_2_1_2.BoxType)

Example 2 with BoxType

use of org.geotoolkit.gml.xml.v212.BoxType in project ddf by codice.

the class WfsFilterDelegate method createBoxType.

private JAXBElement<BoxType> createBoxType(String wkt) {
    BoxType box = new BoxType();
    box.setSrsName(srsName);
    box.setCoordinates(createCoordinatesTypeFromWkt(wkt).getValue());
    return gmlObjectFactory.createBox(box);
}
Also used : BoxType(ogc.schema.opengis.gml.v_2_1_2.BoxType)

Example 3 with BoxType

use of org.geotoolkit.gml.xml.v212.BoxType in project geotoolkit by Geomatys.

the class FilterToOGC100Converter method toBox.

/**
 * Analyze given literal and try to transform it into GML 2 bbox. The
 * conversion is possible only if the given literal contains an
 * {@link Envelope} or a {@link GeographicBoundingBox}.
 *
 * @param input The literal to extract a bbox from.
 * @return Built bbox, never null.
 * @throws IllegalArgumentException If given literal does not contain any
 * usable envelope. Note that an envelope cannot be used if its dimension is
 * more than 2D and no CRS is present to allow us to find horizontal piece.
 */
private static BoxType toBox(final Literal input) throws IllegalArgumentException {
    final Object val = input.getValue();
    if (val == null) {
        throw new IllegalArgumentException("No value in input literal object. Conversion to BoxType impossible");
    }
    final BoxType bType = new BoxType();
    CoordinateReferenceSystem boxCrs = null;
    if (val instanceof Envelope) {
        final Envelope env = (Envelope) val;
        boxCrs = env.getCoordinateReferenceSystem();
        final int xAxis;
        if (env.getDimension() == 2) {
            xAxis = 0;
        } else if (env.getDimension() > 2) {
            if (boxCrs == null) {
                throw new IllegalArgumentException("Cannot find horizontal axis of given envelope");
            }
            final SingleCRS hCrs = CRS.getHorizontalComponent(boxCrs);
            if (hCrs == null) {
                throw new IllegalArgumentException("Cannot find horizontal axis of given envelope");
            }
            xAxis = AxisDirections.indexOfColinear(boxCrs.getCoordinateSystem(), hCrs.getCoordinateSystem());
            boxCrs = hCrs;
        } else
            throw new IllegalArgumentException(String.format("Given envelope has not enough dimension. Cannot build a bbox from it.%nExpected: %d%nBut was: %d", 2, env.getDimension()));
        final int yAxis = xAxis + 1;
        bType.getCoord().add(new CoordType(env.getMinimum(xAxis), env.getMinimum(yAxis)));
        bType.getCoord().add(new CoordType(env.getMaximum(xAxis), env.getMaximum(yAxis)));
    } else if (val instanceof GeographicBoundingBox) {
        final GeographicBoundingBox e = (GeographicBoundingBox) val;
        bType.getCoord().add(new CoordType(e.getWestBoundLongitude(), e.getSouthBoundLatitude()));
        bType.getCoord().add(new CoordType(e.getEastBoundLongitude(), e.getNorthBoundLatitude()));
        boxCrs = CommonCRS.defaultGeographic();
    }
    if (boxCrs != null) {
        String srsName;
        try {
            srsName = IdentifiedObjects.lookupURN(boxCrs, null);
        } catch (FactoryException ex) {
            srsName = IdentifiedObjects.getSimpleNameOrIdentifier(boxCrs);
        }
        if (srsName != null) {
            bType.setSrsName(srsName);
        }
    }
    return bType;
}
Also used : SingleCRS(org.opengis.referencing.crs.SingleCRS) FactoryException(org.opengis.util.FactoryException) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) GeographicBoundingBox(org.opengis.metadata.extent.GeographicBoundingBox) Envelope(org.opengis.geometry.Envelope) BoxType(org.geotoolkit.gml.xml.v212.BoxType) CoordType(org.geotoolkit.gml.xml.v212.CoordType)

Example 4 with BoxType

use of org.geotoolkit.gml.xml.v212.BoxType 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)

Aggregations

BoxType (ogc.schema.opengis.gml.v_2_1_2.BoxType)2 BoxType (org.geotoolkit.gml.xml.v212.BoxType)2 List (java.util.List)1 JAXBElement (javax.xml.bind.JAXBElement)1 BBOXType (ogc.schema.opengis.filter.v_1_0_0.BBOXType)1 CoordType (org.geotoolkit.gml.xml.v212.CoordType)1 AndType (org.geotoolkit.ogc.xml.v100.AndType)1 BBOXType (org.geotoolkit.ogc.xml.v100.BBOXType)1 ComparisonOpsType (org.geotoolkit.ogc.xml.v100.ComparisonOpsType)1 LiteralType (org.geotoolkit.ogc.xml.v100.LiteralType)1 LogicOpsType (org.geotoolkit.ogc.xml.v100.LogicOpsType)1 LowerBoundaryType (org.geotoolkit.ogc.xml.v100.LowerBoundaryType)1 NotType (org.geotoolkit.ogc.xml.v100.NotType)1 OrType (org.geotoolkit.ogc.xml.v100.OrType)1 PropertyIsBetweenType (org.geotoolkit.ogc.xml.v100.PropertyIsBetweenType)1 PropertyIsEqualToType (org.geotoolkit.ogc.xml.v100.PropertyIsEqualToType)1 PropertyIsGreaterThanOrEqualToType (org.geotoolkit.ogc.xml.v100.PropertyIsGreaterThanOrEqualToType)1 PropertyIsGreaterThanType (org.geotoolkit.ogc.xml.v100.PropertyIsGreaterThanType)1 PropertyIsLessThanOrEqualToType (org.geotoolkit.ogc.xml.v100.PropertyIsLessThanOrEqualToType)1 PropertyIsLessThanType (org.geotoolkit.ogc.xml.v100.PropertyIsLessThanType)1