use of org.geotoolkit.ogc.xml.v200 in project geotoolkit by Geomatys.
the class FilterXMLBindingTest method filterMarshalingTest.
/**
* Test simple Record Marshalling.
*
* @throws JAXBException
*/
@Test
public void filterMarshalingTest() throws JAXBException, IOException, ParserConfigurationException, SAXException {
/*
* Test marshalling spatial filter
*/
DirectPositionType lowerCorner = new DirectPositionType(10.0, 11.0);
DirectPositionType upperCorner = new DirectPositionType(10.0, 11.0);
EnvelopeType envelope = new EnvelopeType(lowerCorner, upperCorner, "EPSG:4326");
OverlapsType filterElement = new OverlapsType(new PropertyNameType("boundingBox"), envelope);
FilterType filter = new FilterType(filterElement);
StringWriter sw = new StringWriter();
marshaller.marshal(filter, sw);
String result = sw.toString();
String expResult = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<ogc:Filter xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:gml=\"http://www.opengis.net/gml\">" + '\n' + " <ogc:Overlaps>" + '\n' + " <ogc:PropertyName>boundingBox</ogc:PropertyName>" + '\n' + " <gml:Envelope srsName=\"EPSG:4326\">" + '\n' + " <gml:lowerCorner>10.0 11.0</gml:lowerCorner>" + '\n' + " <gml:upperCorner>10.0 11.0</gml:upperCorner>" + '\n' + " </gml:Envelope>" + '\n' + " </ogc:Overlaps>" + '\n' + "</ogc:Filter>" + '\n';
LOGGER.log(Level.FINER, "result: {0}", result);
LOGGER.log(Level.FINER, "expected: {0}", expResult);
assertXmlEquals(expResult, result, "xmlns:*");
ObjectFactory factory = new ObjectFactory();
final BBOXType bbox = new BBOXType("propName", envelope);
org.geotoolkit.ogc.xml.v200.FilterType filter2 = new org.geotoolkit.ogc.xml.v200.FilterType(bbox);
sw = new StringWriter();
marshaller.marshal(filter2, sw);
result = sw.toString();
expResult = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<fes:Filter xmlns:fes=\"http://www.opengis.net/fes/2.0\" xmlns:ns8=\"http://www.opengis.net/gml\">\n" + " <fes:BBOX>\n" + " <fes:ValueReference>propName</fes:ValueReference>\n" + " <ns8:Envelope srsName=\"EPSG:4326\">\n" + " <ns8:lowerCorner>10.0 11.0</ns8:lowerCorner>\n" + " <ns8:upperCorner>10.0 11.0</ns8:upperCorner>\n" + " </ns8:Envelope>\n" + " </fes:BBOX>\n" + "</fes:Filter>";
assertXmlEquals(expResult, result, "xmlns:*");
/*--------------------------------------------*/
/*- --------------- DEBUG --------------------*/
/*--------------------------------------------*/
String[] arr = new String[2];
arr[0] = "boby";
arr[1] = "DESC";
SortPropertyType sp = new SortPropertyType(arr[0], SortOrderType.valueOf(arr[1]));
SortByType sort = new SortByType(Arrays.asList(sp));
JAXBElement<SortByType> jbSort = factory.createSortBy(sort);
// marshaller.marshal(jbSort, System.out);
sp = new SortPropertyType(arr[0], FilterUtilities.sortOrder(arr[1]));
sort = new SortByType(Arrays.asList(sp));
jbSort = factory.createSortBy(sort);
// marshaller.marshal(jbSort, System.out);
BBOXType filterBox = new BBOXType("boundingBox", "$test");
org.geotoolkit.ogc.xml.v200.FilterType filter3 = new org.geotoolkit.ogc.xml.v200.FilterType(filterBox);
sw = new StringWriter();
marshaller.marshal(filter3, sw);
result = sw.toString();
expResult = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<fes:Filter xmlns:fes=\"http://www.opengis.net/fes/2.0\">\n" + " <fes:BBOX>\n" + " <fes:ValueReference>boundingBox</fes:ValueReference>$test</fes:BBOX>\n" + "</fes:Filter>";
assertXmlEquals(expResult, result, "xmlns:*");
TimeAfterType filterAfter = new TimeAfterType("boundingBox", "$test");
org.geotoolkit.ogc.xml.v200.FilterType filter4 = new org.geotoolkit.ogc.xml.v200.FilterType(filterAfter);
sw = new StringWriter();
marshaller.marshal(filter4, sw);
result = sw.toString();
expResult = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<fes:Filter xmlns:fes=\"http://www.opengis.net/fes/2.0\">\n" + " <fes:After>\n" + " <fes:ValueReference>boundingBox</fes:ValueReference>$test</fes:After>\n" + "</fes:Filter>";
assertXmlEquals(expResult, result, "xmlns:*");
final org.geotoolkit.gml.xml.v321.ObjectFactory gmlFactory = new org.geotoolkit.gml.xml.v321.ObjectFactory();
final org.geotoolkit.ogc.xml.v200.ObjectFactory fesFactory = new org.geotoolkit.ogc.xml.v200.ObjectFactory();
PropertyIsBetweenType pes = new PropertyIsBetweenType();
pes.setExpression(fesFactory.createValueReference((String) "prop"));
final LowerBoundaryType lower = new LowerBoundaryType();
final TimeInstantType ti = new TimeInstantType("2002");
final LiteralType lowlit = new LiteralType(gmlFactory.createTimeInstant(ti));
lower.setExpression(fesFactory.createLiteral(lowlit));
pes.setLowerBoundary(lower);
final UpperBoundaryType upper = new UpperBoundaryType();
final TimeInstantType ti2 = new TimeInstantType("2004");
final LiteralType upplit = new LiteralType(gmlFactory.createTimeInstant(ti2));
upper.setExpression(fesFactory.createLiteral(upplit));
pes.setUpperBoundary(upper);
org.geotoolkit.ogc.xml.v200.FilterType filter5 = new org.geotoolkit.ogc.xml.v200.FilterType(pes);
sw = new StringWriter();
marshaller.marshal(filter5, sw);
result = sw.toString();
expResult = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<fes:Filter xmlns:gml=\"http://www.opengis.net/gml/3.2\" xmlns:fes=\"http://www.opengis.net/fes/2.0\">\n" + " <fes:PropertyIsBetween>\n" + " <fes:ValueReference>prop</fes:ValueReference>\n" + " <fes:LowerBoundary>\n" + " <fes:Literal>\n" + " <gml:TimeInstant>\n" + " <gml:timePosition>2002</gml:timePosition>\n" + " </gml:TimeInstant>\n" + " </fes:Literal>\n" + " </fes:LowerBoundary>\n" + " <fes:UpperBoundary>\n" + " <fes:Literal>\n" + " <gml:TimeInstant>\n" + " <gml:timePosition>2004</gml:timePosition>\n" + " </gml:TimeInstant>\n" + " </fes:Literal>\n" + " </fes:UpperBoundary>\n" + " </fes:PropertyIsBetween>\n" + "</fes:Filter>";
assertXmlEquals(expResult, result, "xmlns:*");
}
use of org.geotoolkit.ogc.xml.v200 in project geotoolkit by Geomatys.
the class OGC200toGTTransformer method visitLogicOp.
/**
* Transform a SLD logic Filter v1.1 in GT filter.
*/
public Filter visitLogicOp(final JAXBElement<? extends org.geotoolkit.ogc.xml.v200.LogicOpsType> jax) throws NoSuchAuthorityCodeException, FactoryException {
final org.geotoolkit.ogc.xml.v200.LogicOpsType ops = jax.getValue();
final String OpName = jax.getName().getLocalPart();
if (ops instanceof org.geotoolkit.ogc.xml.v200.UnaryLogicOpType) {
final org.geotoolkit.ogc.xml.v200.UnaryLogicOpType unary = (org.geotoolkit.ogc.xml.v200.UnaryLogicOpType) ops;
if (OGCJAXBStatics.FILTER_LOGIC_NOT.equalsIgnoreCase(OpName)) {
Filter filter = null;
if (unary.getComparisonOps() != null) {
filter = visitComparisonOp(unary.getComparisonOps());
} else if (unary.getLogicOps() != null) {
filter = visitLogicOp(unary.getLogicOps());
} else if (unary.getSpatialOps() != null) {
filter = visitSpatialOp(unary.getSpatialOps());
} else if (!unary.getId().isEmpty()) {
filter = visitIds(unary.getId());
}
if (filter == null) {
throw new IllegalArgumentException("Invalid filter element" + unary);
}
return filterFactory.not(filter);
}
} else if (ops instanceof org.geotoolkit.ogc.xml.v200.BinaryLogicOpType) {
final org.geotoolkit.ogc.xml.v200.BinaryLogicOpType binary = (org.geotoolkit.ogc.xml.v200.BinaryLogicOpType) ops;
if (OGCJAXBStatics.FILTER_LOGIC_AND.equalsIgnoreCase(OpName)) {
final List<Filter> filters = new ArrayList<Filter>();
for (final JAXBElement<?> ele : binary.getComparisonOpsOrSpatialOpsOrTemporalOps()) {
if (ele.getValue() instanceof ComparisonOpsType) {
filters.add(visitComparisonOp((JAXBElement<? extends ComparisonOpsType>) ele));
} else if (ele.getValue() instanceof LogicOpsType) {
filters.add(visitLogicOp((JAXBElement<? extends LogicOpsType>) ele));
} else if (ele.getValue() instanceof SpatialOpsType) {
filters.add(visitSpatialOp((JAXBElement<? extends SpatialOpsType>) ele));
} else if (ele.getValue() instanceof AbstractIdType) {
filters.add(visitIds(Arrays.asList((JAXBElement<? extends AbstractIdType>) ele)));
}
}
if (filters.isEmpty()) {
return Filter.include();
} else if (filters.size() == 1) {
return filters.get(0);
} else {
return filterFactory.and((List) filters);
}
} else if (OGCJAXBStatics.FILTER_LOGIC_OR.equalsIgnoreCase(OpName)) {
final List<Filter> filters = new ArrayList<>();
for (final JAXBElement ele : binary.getComparisonOpsOrSpatialOpsOrTemporalOps()) {
if (ele.getValue() instanceof ComparisonOpsType) {
filters.add(visitComparisonOp((JAXBElement<? extends ComparisonOpsType>) ele));
} else if (ele.getValue() instanceof LogicOpsType) {
filters.add(visitLogicOp((JAXBElement<? extends LogicOpsType>) ele));
} else if (ele.getValue() instanceof SpatialOpsType) {
filters.add(visitSpatialOp((JAXBElement<? extends SpatialOpsType>) ele));
} else if (ele.getValue() instanceof AbstractIdType) {
filters.add(visitIds(Arrays.asList((JAXBElement<? extends AbstractIdType>) ele)));
}
}
if (filters.isEmpty()) {
return Filter.include();
} else if (filters.size() == 1) {
return filters.get(0);
} else {
return filterFactory.or((List) filters);
}
}
}
throw new IllegalArgumentException("Unknowed filter element" + jax);
}
use of org.geotoolkit.ogc.xml.v200 in project geotoolkit by Geomatys.
the class FilterXMLBindingTest method filterUnmarshalingTest.
/**
* Test simple Record Marshalling.
*
* @throws JAXBException
*/
@Test
public void filterUnmarshalingTest() throws JAXBException {
/*
* Test Unmarshalling spatial filter.
*/
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<ogc:Filter xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:gml=\"http://www.opengis.net/gml\">" + '\n' + " <ogc:Overlaps>" + '\n' + " <ogc:PropertyName>boundingBox</ogc:PropertyName>" + '\n' + " <gml:Envelope srsName=\"EPSG:4326\">" + '\n' + " <gml:lowerCorner>10.0 11.0</gml:lowerCorner>" + '\n' + " <gml:upperCorner>10.0 11.0</gml:upperCorner>" + '\n' + " </gml:Envelope>" + '\n' + " </ogc:Overlaps>" + '\n' + "</ogc:Filter>" + '\n';
StringReader sr = new StringReader(xml);
JAXBElement jb = (JAXBElement) unmarshaller.unmarshal(sr);
FilterType result = (FilterType) jb.getValue();
DirectPositionType lowerCorner = new DirectPositionType(10.0, 11.0);
DirectPositionType upperCorner = new DirectPositionType(10.0, 11.0);
EnvelopeType envelope = new EnvelopeType(lowerCorner, upperCorner, "EPSG:4326");
OverlapsType filterElement = new OverlapsType(new PropertyNameType("boundingBox"), envelope);
FilterType expResult = new FilterType(filterElement);
assertEquals(expResult.getSpatialOps().getValue(), result.getSpatialOps().getValue());
assertEquals(expResult, result);
xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<ogc:Filter xmlns:ogc=\"http://www.opengis.net/fes/2.0\" xmlns:gml=\"http://www.opengis.net/gml\">" + '\n' + " <ogc:BBOX>" + '\n' + " <ogc:ValueReference>boundingBox</ogc:ValueReference>" + '\n' + " <gml:Envelope srsName=\"EPSG:4326\">" + '\n' + " <gml:lowerCorner>10.0 11.0</gml:lowerCorner>" + '\n' + " <gml:upperCorner>10.0 11.0</gml:upperCorner>" + '\n' + " </gml:Envelope>" + '\n' + " </ogc:BBOX>" + '\n' + "</ogc:Filter>" + '\n';
sr = new StringReader(xml);
jb = (JAXBElement) unmarshaller.unmarshal(sr);
org.geotoolkit.ogc.xml.v200.FilterType result2 = (org.geotoolkit.ogc.xml.v200.FilterType) jb.getValue();
final org.geotoolkit.gml.xml.v311.ObjectFactory gmlFactory = new org.geotoolkit.gml.xml.v311.ObjectFactory();
BBOXType filterBox = new BBOXType("boundingBox", gmlFactory.createEnvelope(envelope));
org.geotoolkit.ogc.xml.v200.FilterType expResult2 = new org.geotoolkit.ogc.xml.v200.FilterType(filterBox);
assertEquals(((JAXBElement) ((BBOXType) expResult2.getSpatialOps().getValue()).getAny()).getValue(), ((JAXBElement) ((BBOXType) result2.getSpatialOps().getValue()).getAny()).getValue());
assertEquals(expResult2.getSpatialOps().getValue(), result2.getSpatialOps().getValue());
assertEquals(expResult2, result2);
xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<ogc:Filter xmlns:ogc=\"http://www.opengis.net/fes/2.0\">" + '\n' + " <ogc:BBOX>" + '\n' + " <ogc:ValueReference>boundingBox</ogc:ValueReference>" + '\n' + " $test" + '\n' + " </ogc:BBOX>" + '\n' + "</ogc:Filter>" + '\n';
sr = new StringReader(xml);
jb = (JAXBElement) unmarshaller.unmarshal(sr);
result2 = (org.geotoolkit.ogc.xml.v200.FilterType) jb.getValue();
filterBox = new BBOXType("boundingBox", "$test");
expResult2 = new org.geotoolkit.ogc.xml.v200.FilterType(filterBox);
assertEquals(expResult2.getSpatialOps().getValue(), result2.getSpatialOps().getValue());
assertEquals(expResult2, result2);
xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<ogc:Filter xmlns:ogc=\"http://www.opengis.net/fes/2.0\">" + '\n' + " <ogc:Contains>" + '\n' + " <ogc:ValueReference>boundingBox</ogc:ValueReference>" + '\n' + " $test" + '\n' + " </ogc:Contains>" + '\n' + "</ogc:Filter>" + '\n';
sr = new StringReader(xml);
jb = (JAXBElement) unmarshaller.unmarshal(sr);
result2 = (org.geotoolkit.ogc.xml.v200.FilterType) jb.getValue();
ContainsType filterContains = new ContainsType("boundingBox", "$test");
expResult2 = new org.geotoolkit.ogc.xml.v200.FilterType(filterContains);
assertEquals(expResult2.getSpatialOps().getValue(), result2.getSpatialOps().getValue());
assertEquals(expResult2, result2);
xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<ogc:Filter xmlns:ogc=\"http://www.opengis.net/fes/2.0\">" + '\n' + " <ogc:After>" + '\n' + " <ogc:ValueReference>boundingBox</ogc:ValueReference>" + '\n' + " $test" + '\n' + " </ogc:After>" + '\n' + "</ogc:Filter>" + '\n';
sr = new StringReader(xml);
jb = (JAXBElement) unmarshaller.unmarshal(sr);
result2 = (org.geotoolkit.ogc.xml.v200.FilterType) jb.getValue();
TimeAfterType filterAfter = new TimeAfterType("boundingBox", "$test");
expResult2 = new org.geotoolkit.ogc.xml.v200.FilterType(filterAfter);
assertEquals(expResult2.getTemporalOps().getValue(), result2.getTemporalOps().getValue());
assertEquals(expResult2, result2);
xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<fes:Filter xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:gco=\"http://www.isotc211.org/2005/gco\" xmlns:gmx=\"http://www.isotc211.org/2005/gmx\" xmlns:gmi=\"http://www.isotc211.org/2005/gmi\" xmlns:gmd=\"http://www.isotc211.org/2005/gmd\" xmlns:gml=\"http://www.opengis.net/gml/3.2\" xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:ns8=\"http://www.opengis.net/gml\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:fes=\"http://www.opengis.net/fes/2.0\" xmlns:ows=\"http://www.opengis.net/ows/1.1\">\n" + " <fes:PropertyIsBetween>\n" + " <fes:ValueReference>prop</fes:ValueReference>\n" + " <fes:LowerBoundary>\n" + " <fes:Literal><gml:TimeInstant>\n" + " <gml:timePosition>2002</gml:timePosition>\n" + " </gml:TimeInstant></fes:Literal>\n" + " </fes:LowerBoundary>\n" + " <fes:UpperBoundary>\n" + " <fes:Literal><gml:TimeInstant>\n" + " <gml:timePosition>2004</gml:timePosition>\n" + " </gml:TimeInstant></fes:Literal>\n" + " </fes:UpperBoundary>\n" + " </fes:PropertyIsBetween>\n" + "</fes:Filter>";
sr = new StringReader(xml);
jb = (JAXBElement) unmarshaller.unmarshal(sr);
org.geotoolkit.ogc.xml.v200.FilterType result3 = (org.geotoolkit.ogc.xml.v200.FilterType) jb.getValue();
final org.geotoolkit.gml.xml.v321.ObjectFactory gml32Factory = new org.geotoolkit.gml.xml.v321.ObjectFactory();
final org.geotoolkit.ogc.xml.v200.ObjectFactory fesFactory = new org.geotoolkit.ogc.xml.v200.ObjectFactory();
PropertyIsBetweenType expPes = new PropertyIsBetweenType();
expPes.setExpression(fesFactory.createValueReference((String) "prop"));
final LowerBoundaryType lower = new LowerBoundaryType();
final TimeInstantType ti = new TimeInstantType("2002");
final LiteralType lowlit = new LiteralType(gml32Factory.createTimeInstant(ti));
lower.setExpression(fesFactory.createLiteral(lowlit));
expPes.setLowerBoundary(lower);
final UpperBoundaryType upper = new UpperBoundaryType();
final TimeInstantType ti2 = new TimeInstantType("2004");
final LiteralType upplit = new LiteralType(gml32Factory.createTimeInstant(ti2));
upper.setExpression(fesFactory.createLiteral(upplit));
expPes.setUpperBoundary(upper);
org.geotoolkit.ogc.xml.v200.FilterType expResult3 = new org.geotoolkit.ogc.xml.v200.FilterType(expPes);
assertTrue(result3.getComparisonOps().getValue() instanceof PropertyIsBetweenType);
PropertyIsBetweenType resPes = (PropertyIsBetweenType) result3.getComparisonOps().getValue();
assertEquals(expPes.getUpperBoundary(), resPes.getUpperBoundary());
assertEquals(expPes.getLowerBoundary(), resPes.getLowerBoundary());
assertEquals(expPes, resPes);
assertEquals(expResult3.getComparisonOps().getValue(), result3.getComparisonOps().getValue());
assertEquals(expResult3, result3);
}
use of org.geotoolkit.ogc.xml.v200 in project geotoolkit by Geomatys.
the class OGC200toGTTransformer method visitSpatialOp.
/**
* Transform a SLD spatial Filter v1.1 in GT filter.
*/
public Filter visitSpatialOp(final JAXBElement<? extends org.geotoolkit.ogc.xml.v200.SpatialOpsType> jax) throws NoSuchAuthorityCodeException, FactoryException {
final org.geotoolkit.ogc.xml.v200.SpatialOpsType ops = jax.getValue();
final String OpName = jax.getName().getLocalPart();
if (ops instanceof org.geotoolkit.ogc.xml.v200.BinarySpatialOpType) {
final org.geotoolkit.ogc.xml.v200.BinarySpatialOpType binary = (org.geotoolkit.ogc.xml.v200.BinarySpatialOpType) ops;
Object geom = binary.getAny();
if (geom instanceof JAXBElement) {
geom = ((JAXBElement) geom).getValue();
}
final Expression left = visitPropertyName(binary.getValueReference());
final Expression right;
if (geom instanceof EnvelopeType) {
try {
right = visitEnv((EnvelopeType) geom);
} catch (FactoryException ex) {
throw new IllegalArgumentException("SRS name is unknowned : " + ex.getLocalizedMessage(), ex);
}
} else if (geom instanceof AbstractGeometryType) {
right = visit((AbstractGeometryType) geom);
} else {
throw new IllegalArgumentException("Unexpected geometry type:" + 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.v200.DistanceBufferType) {
final org.geotoolkit.ogc.xml.v200.DistanceBufferType dstOp = (org.geotoolkit.ogc.xml.v200.DistanceBufferType) ops;
final org.geotoolkit.ogc.xml.v200.MeasureType dt = dstOp.getDistanceType();
Object opAny = dstOp.getAny();
if (opAny instanceof JAXBElement) {
opAny = ((JAXBElement) opAny).getValue();
}
if (!(opAny instanceof AbstractGeometryType)) {
throw new IllegalArgumentException("geometry type is unexpected:" + opAny);
}
final AbstractGeometryType geom = (AbstractGeometryType) opAny;
final String 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.getUom();
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.v200.BBOXType) {
final org.geotoolkit.ogc.xml.v200.BBOXType binary = (org.geotoolkit.ogc.xml.v200.BBOXType) ops;
Object binAny = binary.getAny();
if (binAny instanceof JAXBElement) {
binAny = ((JAXBElement) binAny).getValue();
}
if (!(binAny instanceof EnvelopeType)) {
throw new IllegalArgumentException("geometry type is unexpected:" + binAny);
}
final EnvelopeType box = (EnvelopeType) binAny;
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 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);
}
use of org.geotoolkit.ogc.xml.v200 in project geotoolkit by Geomatys.
the class OGC200toGTTransformer method visitComparisonOp.
/**
* Transform a SLD comparison Filter v1.1 in GT filter.
*/
public Filter visitComparisonOp(final JAXBElement<? extends org.geotoolkit.ogc.xml.v200.ComparisonOpsType> jax) {
final org.geotoolkit.ogc.xml.v200.ComparisonOpsType ops = jax.getValue();
final String OpName = jax.getName().getLocalPart();
if (ops instanceof org.geotoolkit.ogc.xml.v200.BinaryComparisonOpType) {
final org.geotoolkit.ogc.xml.v200.BinaryComparisonOpType binary = (org.geotoolkit.ogc.xml.v200.BinaryComparisonOpType) ops;
if (binary.getExpression().size() < 2) {
throw new IllegalArgumentException("comparison operator must have two expression (valueReference and literal)");
}
final Expression left = visitExpression(binary.getExpression().get(0));
final Expression right = visitExpression(binary.getExpression().get(1));
Boolean match = binary.isMatchingCase();
if (match == null) {
match = Boolean.TRUE;
}
final MatchAction action = binary.getMatchAction();
if (OGCJAXBStatics.FILTER_COMPARISON_ISEQUAL.equalsIgnoreCase(OpName)) {
return filterFactory.equal(left, right, match, action);
} else if (OGCJAXBStatics.FILTER_COMPARISON_ISNOTEQUAL.equalsIgnoreCase(OpName)) {
return filterFactory.notEqual(left, right, match, action);
} else if (OGCJAXBStatics.FILTER_COMPARISON_ISLESS.equalsIgnoreCase(OpName)) {
return filterFactory.less(left, right, match, action);
} else if (OGCJAXBStatics.FILTER_COMPARISON_ISGREATER.equalsIgnoreCase(OpName)) {
return filterFactory.greater(left, right, match, action);
} else if (OGCJAXBStatics.FILTER_COMPARISON_ISLESSOREQUAL.equalsIgnoreCase(OpName)) {
return filterFactory.lessOrEqual(left, right, match, action);
} else if (OGCJAXBStatics.FILTER_COMPARISON_ISGREATEROREQUAL.equalsIgnoreCase(OpName)) {
return filterFactory.greaterOrEqual(left, right, match, action);
}
throw new IllegalArgumentException("Illegal filter element" + OpName + " : " + ops);
} else if (ops instanceof org.geotoolkit.ogc.xml.v200.PropertyIsLikeType) {
final org.geotoolkit.ogc.xml.v200.PropertyIsLikeType property = (org.geotoolkit.ogc.xml.v200.PropertyIsLikeType) ops;
final Expression expr = visitPropertyName(property.getPropertyName());
final String pattern = visitExpression(property.getLiteralType()).toString();
final char wild = property.getWildCard();
final char single = property.getSingleChar();
final char escape = property.getEscapeChar();
final boolean matchCase = property.isMatchingCase();
if (OGCJAXBStatics.FILTER_COMPARISON_ISLIKE.equalsIgnoreCase(OpName)) {
return filterFactory.like(expr, pattern, wild, single, escape, matchCase);
}
throw new IllegalArgumentException("Illegal filter element" + OpName + " : " + ops);
} else if (ops instanceof org.geotoolkit.ogc.xml.v200.PropertyIsBetweenType) {
final org.geotoolkit.ogc.xml.v200.PropertyIsBetweenType property = (org.geotoolkit.ogc.xml.v200.PropertyIsBetweenType) ops;
final Expression lower = visitExpression(property.getLowerBoundary().getExpression());
final Expression upper = visitExpression(property.getUpperBoundary().getExpression());
final Expression expr = visitExpression(property.getExpressionType());
if (OGCJAXBStatics.FILTER_COMPARISON_ISBETWEEN.equalsIgnoreCase(OpName)) {
return filterFactory.between(expr, lower, upper);
}
throw new IllegalArgumentException("Illegal filter element" + OpName + " : " + ops);
} else if (ops instanceof org.geotoolkit.ogc.xml.v200.PropertyIsNullType) {
final org.geotoolkit.ogc.xml.v200.PropertyIsNullType property = (org.geotoolkit.ogc.xml.v200.PropertyIsNullType) ops;
final Expression expr = visitPropertyName(property.getPropertyName());
if (OGCJAXBStatics.FILTER_COMPARISON_ISNULL.equalsIgnoreCase(OpName)) {
return filterFactory.isNull(expr);
}
throw new IllegalArgumentException("Illegal filter element" + OpName + " : " + ops);
} else if (ops instanceof org.geotoolkit.ogc.xml.v200.PropertyIsNilType) {
final org.geotoolkit.ogc.xml.v200.PropertyIsNilType property = (org.geotoolkit.ogc.xml.v200.PropertyIsNilType) ops;
final Expression expr = visitPropertyName(property.getPropertyName());
if (OGCJAXBStatics.FILTER_COMPARISON_ISNIL.equalsIgnoreCase(OpName)) {
return filterFactory.isNil(expr, null);
}
throw new IllegalArgumentException("Illegal filter element" + OpName + " : " + ops);
}
throw new IllegalArgumentException("Unknowed filter element" + jax);
}
Aggregations