use of org.geotoolkit.ogc.xml.v110.PropertyNameType in project geotoolkit by Geomatys.
the class FilterFactoryImpl method notEqual.
@Override
public BinaryComparisonOperator<Object> notEqual(final Expression<Object, ?> expr1, final Expression<Object, ?> expr2) {
LiteralType lit = null;
PropertyNameType propName = null;
if (expr1 instanceof PropertyNameType) {
propName = (PropertyNameType) expr1;
} else if (expr2 instanceof PropertyNameType) {
propName = (PropertyNameType) expr2;
}
if (expr1 instanceof LiteralType) {
lit = (LiteralType) expr1;
} else if (expr2 instanceof LiteralType) {
lit = (LiteralType) expr2;
}
return new PropertyIsNotEqualToType(lit, propName, null);
}
use of org.geotoolkit.ogc.xml.v110.PropertyNameType in project geotoolkit by Geomatys.
the class FilterFactoryImpl method beyond.
@Override
public DistanceOperator<Object> beyond(final Expression geometry1, final Expression geometry2, final double distance, String units) {
String propertyName = "";
if (geometry1 instanceof PropertyNameType) {
propertyName = ((PropertyNameType) geometry1).getXPath();
} else {
throw new IllegalArgumentException("unexpected type instead of propertyNameType: " + geometry1.getClass().getSimpleName());
}
// we transform the JTS geometry into a GML geometry
Object geom = null;
if (geometry2 instanceof LiteralType) {
geom = ((LiteralType) geometry2).getValue();
geom = GeometryToGML(geom);
}
// we formats the units (CQL parser add a white space at the end)
if (units.indexOf(' ') == units.length() - 1) {
units = units.substring(0, units.length() - 1);
}
return new BeyondType(propertyName, (AbstractGeometryType) geom, distance, units);
}
use of org.geotoolkit.ogc.xml.v110.PropertyNameType in project geotoolkit by Geomatys.
the class FilterFactoryImpl method endedBy.
@Override
public TemporalOperator<Object> endedBy(final Expression<Object, ?> expr1, final Expression<Object, ?> expr2) {
Object temporal = null;
PropertyNameType propName = null;
if (expr1 instanceof PropertyNameType) {
propName = (PropertyNameType) expr1;
temporal = expr2;
} else if (expr2 instanceof PropertyNameType) {
propName = (PropertyNameType) expr2;
temporal = expr1;
}
return new TimeEndedByType(propName.getXPath(), temporal);
}
use of org.geotoolkit.ogc.xml.v110.PropertyNameType 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());
}
use of org.geotoolkit.ogc.xml.v110.PropertyNameType in project geotoolkit by Geomatys.
the class OGC100Test method testFilterLogicalOr.
@Test
public void testFilterLogicalOr() throws JAXBException {
final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
final Marshaller MARSHALLER = POOL.acquireMarshaller();
// Read test
Object obj = UNMARSHALLER.unmarshal(FILE_FIL_LOG_OR);
assertNotNull(obj);
JAXBElement<? extends FilterType> jaxfilter = (JAXBElement<? extends FilterType>) obj;
assertNotNull(jaxfilter);
Filter filter = TRANSFORMER_GT.visitFilter(jaxfilter.getValue());
assertNotNull(filter);
LogicalOperator prop = (LogicalOperator) filter;
BinaryComparisonOperator leftop = (BinaryComparisonOperator) prop.getOperands().get(0);
BinaryComparisonOperator rightop = (BinaryComparisonOperator) prop.getOperands().get(1);
ValueReference left = (ValueReference) leftop.getOperand1();
Literal right = (Literal) leftop.getOperand2();
assertEquals(left.getXPath(), valueStr);
assertEquals(((Number) right.apply(null)).floatValue(), 455f, DELTA);
left = (ValueReference) rightop.getOperand1();
right = (Literal) rightop.getOperand2();
assertEquals(left.getXPath(), valueStr);
assertEquals(((Number) right.apply(null)).floatValue(), 457f, DELTA);
// write test
FilterType ft = TRANSFORMER_OGC.apply(filter);
assertNotNull(ft.getLogicOps());
LogicOpsType cot = ft.getLogicOps().getValue();
assertEquals(ft.getLogicOps().getName().getLocalPart(), OGCJAXBStatics.FILTER_LOGIC_OR);
BinaryLogicOpType pibt = (BinaryLogicOpType) cot;
BinaryComparisonOpType leftoptype = (BinaryComparisonOpType) pibt.getComparisonOpsOrSpatialOpsOrLogicOps().get(0).getValue();
BinaryComparisonOpType rightoptype = (BinaryComparisonOpType) pibt.getComparisonOpsOrSpatialOpsOrLogicOps().get(1).getValue();
PropertyNameType lf = (PropertyNameType) leftoptype.getExpression().get(0).getValue();
LiteralType rg = (LiteralType) leftoptype.getExpression().get(1).getValue();
assertEquals(valueStr, lf.getContent());
numberEquals(455, rg.getContent().get(0));
lf = (PropertyNameType) rightoptype.getExpression().get(0).getValue();
rg = (LiteralType) rightoptype.getExpression().get(1).getValue();
assertEquals(valueStr, lf.getContent());
numberEquals(457, rg.getContent().get(0));
MARSHALLER.marshal(ft.getLogicOps(), TEST_FILE_FIL_LOG_OR);
POOL.recycle(MARSHALLER);
POOL.recycle(UNMARSHALLER);
}
Aggregations