use of org.geotoolkit.gml.xml.v311.DirectPositionType in project geotoolkit by Geomatys.
the class GetCoverageType method getCRS.
/**
* {@inheritDoc}
*/
@Override
public CoordinateReferenceSystem getCRS() throws FactoryException {
if (domainSubset == null || domainSubset.getSpatialSubSet() == null || domainSubset.getSpatialSubSet().getEnvelope() == null) {
return null;
}
final CoordinateReferenceSystem objCrs = AbstractCRS.castOrCopy(CRS.forCode(domainSubset.getSpatialSubSet().getEnvelope().getSrsName())).forConvention(AxesConvention.RIGHT_HANDED);
final List<DirectPositionType> positions = domainSubset.getSpatialSubSet().getEnvelope().getPos();
/*
* If the bounding box contains at least 3 dimensions and the CRS specified is just
* a 2D one, then we have to add a VerticalCRS to the one gotten by the crs decoding step.
* Otherwise the CRS decoded is already fine, and we just return it.
*/
if (positions.get(0).getDimension() > 2 && objCrs.getCoordinateSystem().getDimension() < 3) {
final VerticalCRS verticalCRS = CommonCRS.Vertical.ELLIPSOIDAL.crs();
return new GeodeticObjectBuilder().addName(objCrs.getName().getCode() + " (3D)").createCompoundCRS(objCrs, verticalCRS);
} else {
return objCrs;
}
}
use of org.geotoolkit.gml.xml.v311.DirectPositionType in project geotoolkit by Geomatys.
the class ObservationXMLBindingTest method UnmarshalingTest.
/**
* Test simple Record Marshalling.
*
* @throws java.lang.Exception
*/
@Test
public void UnmarshalingTest() throws Exception {
/*
* Test Unmarshalling observation
*/
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<om:Observation xmlns:om=\"http://www.opengis.net/om/1.0\" xmlns:sampling=\"http://www.opengis.net/sampling/1.0\" " + " xmlns:gml=\"http://www.opengis.net/gml\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:swe=\"http://www.opengis.net/swe/1.0.1\">" + '\n' + " <gml:name>urn:Observation-007</gml:name>" + '\n' + " <om:samplingTime>" + '\n' + " <gml:TimePeriod>" + '\n' + " <gml:beginPosition>2007-01-01</gml:beginPosition>" + '\n' + " <gml:endPosition>2008-09-09</gml:endPosition>" + '\n' + " </gml:TimePeriod>" + '\n' + " </om:samplingTime>" + '\n' + " <om:procedure xlink:href=\"urn:sensor:007\"/>" + '\n' + " <om:observedProperty>" + '\n' + " <swe:Phenomenon gml:id=\"phenomenon-007\">" + '\n' + " <gml:name>urn:OGC:phenomenon-007</gml:name>" + '\n' + " </swe:Phenomenon>" + '\n' + " </om:observedProperty>" + '\n' + " <om:featureOfInterest>" + '\n' + " <sampling:SamplingPoint gml:id=\"samplingID-007\">" + '\n' + " <gml:description>a sampling Test</gml:description>" + '\n' + " <gml:name>urn:sampling:test:007</gml:name>" + '\n' + " <gml:boundedBy>" + '\n' + " <gml:Null>not_bounded</gml:Null>" + '\n' + " </gml:boundedBy>" + '\n' + " <sampling:sampledFeature xlink:href=\"urn:sampling:sampledFeature\"/>" + '\n' + " <sampling:position gml:id=\"point-ID\">" + '\n' + " <gml:Point gml:id=\"point-ID\">" + '\n' + " <gml:pos srsName=\"urn:ogc:crs:espg:4326\" srsDimension=\"2\">3.2 6.5</gml:pos>" + '\n' + " </gml:Point>" + '\n' + " </sampling:position>" + '\n' + " </sampling:SamplingPoint>" + '\n' + " </om:featureOfInterest>" + '\n' + " <om:result xsi:type=\"swe:DataArrayPropertyType\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + '\n' + " <swe:DataArray gml:id=\"array-001\">" + '\n' + " <swe:elementCount>" + '\n' + " <swe:Count>" + '\n' + " <swe:value>1</swe:value>" + '\n' + " </swe:Count>" + '\n' + " </swe:elementCount>" + '\n' + " <swe:elementType name=\"array-001\">" + '\n' + " <swe:SimpleDataRecord>" + '\n' + " <swe:field name=\"text-field-001\">" + '\n' + " <swe:Text definition=\"urn:something\">" + '\n' + " <swe:value>some value</swe:value>" + '\n' + " </swe:Text>" + '\n' + " </swe:field>" + '\n' + " </swe:SimpleDataRecord>" + '\n' + " </swe:elementType>" + '\n' + " <swe:encoding>" + '\n' + " <swe:TextBlock blockSeparator=\"@@\" decimalSeparator=\".\" tokenSeparator=\",\" id=\"encoding-001\"/>" + '\n' + " </swe:encoding>" + '\n' + " <swe:values>somevalue</swe:values>" + '\n' + " </swe:DataArray>" + '\n' + " </om:result>" + '\n' + "</om:Observation>\n";
StringReader sr = new StringReader(xml);
JAXBElement jb = (JAXBElement) unmarshaller.unmarshal(sr);
ObservationType result = (ObservationType) jb.getValue();
DirectPositionType pos = new DirectPositionType("urn:ogc:crs:espg:4326", 2, Arrays.asList(3.2, 6.5));
PointType location = new PointType("point-ID", pos);
SamplingPointType sp = new SamplingPointType("samplingID-007", "urn:sampling:test:007", "a sampling Test", new FeaturePropertyType("urn:sampling:sampledFeature"), location);
PhenomenonType observedProperty = new PhenomenonType("phenomenon-007", "urn:OGC:phenomenon-007");
TimePeriodType samplingTime = new TimePeriodType(null, "2007-01-01", "2008-09-09");
TextBlockType encoding = new TextBlockType("encoding-001", ",", "@@", ".");
List<AnyScalarPropertyType> fields = new ArrayList<>();
AnyScalarPropertyType field = new AnyScalarPropertyType("text-field-001", new Text("urn:something", "some value"));
fields.add(field);
SimpleDataRecordType record = new SimpleDataRecordType(fields);
DataArrayType array = new DataArrayType("array-001", 1, "array-001", record, encoding, "somevalue", null);
DataArrayPropertyType arrayProp = new DataArrayPropertyType(array);
ObservationType expResult = new ObservationType("urn:Observation-007", null, sp, observedProperty, "urn:sensor:007", arrayProp, samplingTime);
assertEquals(expResult.getFeatureOfInterest(), result.getFeatureOfInterest());
assertEquals(expResult.getDefinition(), result.getDefinition());
assertEquals(expResult.getName(), result.getName());
assertEquals(expResult.getObservationMetadata(), result.getObservationMetadata());
assertEquals(expResult.getObservedProperty(), result.getObservedProperty());
assertEquals(expResult.getProcedure(), result.getProcedure());
assertEquals(expResult.getProcedureParameter(), result.getProcedureParameter());
assertEquals(expResult.getProcedureTime(), result.getProcedureTime());
assertEquals(expResult.getPropertyFeatureOfInterest(), result.getPropertyFeatureOfInterest());
assertEquals(expResult.getPropertyObservedProperty(), result.getPropertyObservedProperty());
assertEquals(expResult.getQuality(), result.getQuality());
assertEquals(expResult.getResult(), result.getResult());
assertEquals(expResult.getSamplingTime(), result.getSamplingTime());
assertEquals(expResult, result);
/*
* Test Unmarshalling measurement
*/
xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<om:Measurement xmlns:om=\"http://www.opengis.net/om/1.0\" xmlns:sampling=\"http://www.opengis.net/sampling/1.0\" " + " xmlns:gml=\"http://www.opengis.net/gml\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:swe=\"http://www.opengis.net/swe/1.0.1\">" + '\n' + " <gml:name>urn:Observation-007</gml:name>" + '\n' + " <om:samplingTime>" + '\n' + " <gml:TimePeriod gml:id=\"t1\">" + '\n' + " <gml:beginPosition>2007-01-01</gml:beginPosition>" + '\n' + " <gml:endPosition>2008-09-09</gml:endPosition>" + '\n' + " </gml:TimePeriod>" + '\n' + " </om:samplingTime>" + '\n' + " <om:procedure xlink:href=\"urn:sensor:007\"/>" + '\n' + " <om:observedProperty>" + '\n' + " <swe:Phenomenon gml:id=\"phenomenon-007\">" + '\n' + " <gml:name>urn:OGC:phenomenon-007</gml:name>" + '\n' + " </swe:Phenomenon>" + '\n' + " </om:observedProperty>" + '\n' + " <om:featureOfInterest>" + '\n' + " <sampling:SamplingPoint gml:id=\"samplingID-007\">" + '\n' + " <gml:description>a sampling Test</gml:description>" + '\n' + " <gml:name>urn:sampling:test:007</gml:name>" + '\n' + " <gml:boundedBy>" + '\n' + " <gml:Null>not_bounded</gml:Null>" + '\n' + " </gml:boundedBy>" + '\n' + " <sampling:sampledFeature xlink:href=\"urn:sampling:sampledFeature\"/>" + '\n' + " <sampling:position gml:id=\"point-ID\">" + '\n' + " <gml:Point gml:id=\"point-ID\">" + '\n' + " <gml:pos srsName=\"urn:ogc:crs:espg:4326\" srsDimension=\"2\">3.2 6.5</gml:pos>" + '\n' + " </gml:Point>" + '\n' + " </sampling:position>" + '\n' + " </sampling:SamplingPoint>" + '\n' + " </om:featureOfInterest>" + '\n' + " <om:result xsi:type=\"om:MeasureType\" uom=\"meters\">7.0</om:result>" + '\n' + "</om:Measurement>\n";
sr = new StringReader(xml);
jb = (JAXBElement) unmarshaller.unmarshal(sr);
MeasurementType result2 = (MeasurementType) jb.getValue();
UnitOfMeasureEntry uom = new UnitOfMeasureEntry("m", null, null, "meters");
MeasureType meas = new MeasureType(uom, 7);
MeasurementType expResult2 = new MeasurementType("urn:Observation-007", null, sp, observedProperty, "urn:sensor:007", meas, samplingTime);
assertEquals(expResult2.getFeatureOfInterest(), result2.getFeatureOfInterest());
assertEquals(expResult2.getDefinition(), result2.getDefinition());
assertEquals(expResult2.getName(), result2.getName());
assertEquals(expResult2.getObservationMetadata(), result2.getObservationMetadata());
assertEquals(expResult2.getObservedProperty(), result2.getObservedProperty());
assertEquals(expResult2.getProcedure(), result2.getProcedure());
assertEquals(expResult2.getProcedureParameter(), result2.getProcedureParameter());
assertEquals(expResult2.getProcedureTime(), result2.getProcedureTime());
assertEquals(expResult2.getPropertyFeatureOfInterest(), result2.getPropertyFeatureOfInterest());
assertEquals(expResult2.getPropertyObservedProperty(), result2.getPropertyObservedProperty());
assertEquals(expResult2.getQuality(), result2.getQuality());
assertEquals(expResult2.getResult(), result2.getResult());
assertEquals(expResult2.getSamplingTime(), result2.getSamplingTime());
assertEquals(expResult2, result2);
xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<om:ObservationCollection xmlns:swe=\"http://www.opengis.net/swe/1.0.1\" xmlns:sampling=\"http://www.opengis.net/sampling/1.0\" xmlns:om=\"http://www.opengis.net/om/1.0\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:gml=\"http://www.opengis.net/gml\">" + '\n' + " <gml:boundedBy>" + '\n' + " <gml:Envelope srsName=\"urn:ogc:crs:espg:4326\">" + '\n' + " <gml:lowerCorner>-180.0 -90.0</gml:lowerCorner>" + '\n' + " <gml:upperCorner>180.0 90.0</gml:upperCorner>" + '\n' + " </gml:Envelope>" + '\n' + " </gml:boundedBy>" + '\n' + " <om:member>" + '\n' + " <om:Measurement>" + '\n' + " <gml:name>urn:ogc:object:observationTemplate:SunSpot:0014.4F01.0000.2626-12</gml:name>" + '\n' + " <om:samplingTime>" + '\n' + " <gml:TimePeriod>" + '\n' + " <gml:beginPosition>2009-08-03 11:18:06</gml:beginPosition>" + '\n' + " <gml:endPosition indeterminatePosition=\"now\"></gml:endPosition>" + '\n' + " </gml:TimePeriod>" + '\n' + " </om:samplingTime>" + '\n' + " <om:procedure xlink:href=\"urn:ogc:object:sensor:SunSpot:0014.4F01.0000.2626\"/>" + '\n' + " <om:observedProperty>" + '\n' + " <swe:Phenomenon gml:id=\"temperature\">" + '\n' + " <gml:name>urn:phenomenon:temperature</gml:name>" + '\n' + " </swe:Phenomenon>" + '\n' + " </om:observedProperty>" + '\n' + " <om:featureOfInterest>" + '\n' + " <sampling:SamplingPoint gml:id=\"sampling-point-001\">" + '\n' + " <gml:name>sampling-point-001</gml:name>" + '\n' + " <gml:boundedBy>" + '\n' + " <gml:Null>not_bounded</gml:Null>" + '\n' + " </gml:boundedBy>" + '\n' + " <sampling:sampledFeature>sampling-point-001</sampling:sampledFeature>" + '\n' + " <sampling:position>" + '\n' + " <gml:Point gml:id=\"point-ID\">" + '\n' + " <gml:pos srsDimension=\"0\">0.0 0.0</gml:pos>" + '\n' + " </gml:Point>" + '\n' + " </sampling:position>" + '\n' + " </sampling:SamplingPoint>" + '\n' + " </om:featureOfInterest>" + '\n' + " <om:result xsi:type=\"om:Measure\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + '\n' + " <om:name>mesure-027</om:name>" + '\n' + " <om:value>0.0</om:value>" + '\n' + " </om:result>" + '\n' + " </om:Measurement>" + '\n' + " </om:member>" + '\n' + "</om:ObservationCollection>" + '\n';
sr = new StringReader(xml);
ObservationCollectionType result3 = (ObservationCollectionType) unmarshaller.unmarshal(sr);
}
use of org.geotoolkit.gml.xml.v311.DirectPositionType in project geotoolkit by Geomatys.
the class SamplingXMLBindingTest method UnmarshalingTest.
/**
* Test simple Record Marshalling.
*
* @throws java.lang.Exception
*/
@Test
public void UnmarshalingTest() throws JAXBException {
/*
* Test Unmarshalling spatial filter.
*/
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<sa:SamplingPoint xmlns:sa=\"http://www.opengis.net/sampling/1.0\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:gml=\"http://www.opengis.net/gml\" gml:id=\"samplingID-007\">" + '\n' + " <gml:description>a sampling Test</gml:description>" + '\n' + " <gml:name>urn:sampling:test:007</gml:name>" + '\n' + " <gml:boundedBy>" + '\n' + " <gml:Null>not_bounded</gml:Null>" + '\n' + " </gml:boundedBy>" + '\n' + " <sa:sampledFeature xlink:href=\"\"/>" + '\n' + " <sa:position>" + '\n' + " <gml:Point gml:id=\"point-ID\">" + '\n' + " <gml:pos srsName=\"urn:ogc:crs:espg:4326\" srsDimension=\"2\">3.2 6.5</gml:pos>" + '\n' + " </gml:Point>" + '\n' + " </sa:position>" + '\n' + "</sa:SamplingPoint>" + '\n';
StringReader sr = new StringReader(xml);
JAXBElement jb = (JAXBElement) unmarshaller.unmarshal(sr);
final SamplingPointType result = (SamplingPointType) jb.getValue();
final DirectPositionType pos = new DirectPositionType("urn:ogc:crs:espg:4326", 2, Arrays.asList(3.2, 6.5));
final PointType location = new PointType("point-ID", pos);
final SamplingPointType expResult = new SamplingPointType("samplingID-007", "urn:sampling:test:007", "a sampling Test", new FeaturePropertyType(""), location);
assertEquals(expResult.getPosition(), result.getPosition());
assertEquals(expResult.getName(), result.getName());
assertEquals(expResult, result);
xml = "<gml:FeatureCollection xmlns:sampling=\"http://www.opengis.net/sampling/1.0\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:gml=\"http://www.opengis.net/gml\">" + '\n' + " <gml:featureMember>" + '\n' + " <sampling:SamplingPoint gml:id=\"samplingID-007\">" + '\n' + " <gml:description>a sampling Test</gml:description>" + '\n' + " <gml:name>urn:sampling:test:007</gml:name>" + '\n' + " <gml:boundedBy>" + '\n' + " <gml:Null>not_bounded</gml:Null>" + '\n' + " </gml:boundedBy>" + '\n' + " <sampling:sampledFeature xlink:href=\"\"/>" + '\n' + " <sampling:position>" + '\n' + " <gml:Point gml:id=\"point-ID\">" + '\n' + " <gml:pos srsName=\"urn:ogc:crs:espg:4326\" srsDimension=\"2\">3.2 6.5</gml:pos>" + '\n' + " </gml:Point>" + '\n' + " </sampling:position>" + '\n' + " </sampling:SamplingPoint>" + '\n' + " </gml:featureMember>" + '\n' + "</gml:FeatureCollection>" + '\n';
sr = new StringReader(xml);
Object obj = ((JAXBElement) unmarshaller.unmarshal(sr)).getValue();
final ObjectFactory facto = new ObjectFactory();
FeatureCollectionType collection = new FeatureCollectionType();
List<FeaturePropertyType> featProps = new ArrayList<FeaturePropertyType>();
featProps.add(new FeaturePropertyType(facto.createSamplingPoint(expResult)));
collection.getFeatureMember().addAll(featProps);
assertEquals(collection, obj);
}
use of org.geotoolkit.gml.xml.v311.DirectPositionType in project geotoolkit by Geomatys.
the class FilterFactoryImpl method GeometryToGML.
/**
* Transform a JTS geometric object into a GML marshallable object
*/
public Object GeometryToGML(final Object geom) {
Object result = null;
if (geom instanceof Polygon) {
final Polygon p = (Polygon) geom;
final Coordinate[] coord = p.getCoordinates();
// an envelope
if (coord.length == 5) {
final DirectPositionType lowerCorner = new DirectPositionType(coord[0].y, coord[0].x);
final DirectPositionType upperCorner = new DirectPositionType(coord[2].y, coord[2].x);
result = new EnvelopeType(null, lowerCorner, upperCorner, "EPSG:4326");
}
} else if (geom instanceof Point) {
final Point p = (Point) geom;
final Coordinate[] coord = p.getCoordinates();
result = new PointType(null, new DirectPositionType(coord[0].x, coord[0].y, coord[0].z));
((PointType) result).setSrsName("EPSG:4326");
} else if (geom instanceof LineString) {
final LineString ls = (LineString) geom;
final Coordinate[] coord = ls.getCoordinates();
result = new LineStringType(new CoordinatesType(coord[0].x + "," + coord[0].y + " " + coord[1].x + "," + coord[1].y));
((LineStringType) result).setSrsName("EPSG:4326");
} else {
LOGGER.severe("unable to create GML geometry with: " + geom.getClass().getSimpleName());
}
return result;
}
use of org.geotoolkit.gml.xml.v311.DirectPositionType in project geotoolkit by Geomatys.
the class FilterToOGC200Converter method visit.
public JAXBElement visit(Filter filter) {
if (filter.equals(Filter.include()) || filter.equals(Filter.exclude())) {
return null;
}
final CodeList<?> type = filter.getOperatorType();
if (filter instanceof BetweenComparisonOperator) {
final BetweenComparisonOperator pib = (BetweenComparisonOperator) filter;
final LowerBoundaryType lbt = ogc_factory.createLowerBoundaryType();
lbt.setExpression(extract(pib.getLowerBoundary()));
final UpperBoundaryType ubt = ogc_factory.createUpperBoundaryType();
ubt.setExpression(extract(pib.getUpperBoundary()));
final PropertyIsBetweenType bot = new PropertyIsBetweenType();
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.setContent(((Literal) expressions.get(1)).getValue());
bot.getElements().add(ogc_factory.createLiteral(lt));
final Expression expression = expressions.get(0);
if (!(expression instanceof ValueReference)) {
throw new IllegalArgumentException("LikeOperator can support ValueReference only, but was a " + expression);
}
bot.getElements().add(0, extract(expression));
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();
bot.setExpression(extract((Expression) pis.getExpressions().get(0)));
return ogc_factory.createPropertyIsNull(bot);
} else if (type == LogicalOperatorName.AND) {
final LogicalOperator and = (LogicalOperator) filter;
final List<JAXBElement> lot = new ArrayList<>();
for (final Filter f : (List<Filter>) and.getOperands()) {
final JAXBElement<?> ele = visit(f);
if (ele != null && ele.getValue() instanceof LogicOpsType) {
lot.add(ele);
}
}
return ogc_factory.createAnd(new AndType(lot.toArray()));
} else if (type == LogicalOperatorName.OR) {
final LogicalOperator or = (LogicalOperator) filter;
final List<JAXBElement> lot = new ArrayList<>();
for (final Filter f : (List<Filter>) or.getOperands()) {
final JAXBElement subFilter = visit(f);
if (subFilter != null) {
lot.add(subFilter);
}
}
return ogc_factory.createOr(new OrType(lot.toArray()));
} else if (type == LogicalOperatorName.NOT) {
final LogicalOperator not = (LogicalOperator) filter;
final JAXBElement<?> sf = visit((Filter) not.getOperands().get(0));
// should not happen
return ogc_factory.createNot(new NotType(sf));
} else if (filter instanceof ResourceId) {
throw new IllegalArgumentException("Not parsed yet : " + filter);
} else if (type == SpatialOperatorName.BBOX) {
final BBOX bbox = BBOX.wrap((BinarySpatialOperator) filter);
final Expression left = bbox.getOperand1();
final Expression right = bbox.getOperand2();
final String property;
final double minx;
final double maxx;
final double miny;
final double maxy;
String srs;
if (left instanceof ValueReference) {
property = ((ValueReference) left).getXPath();
final Object objGeom = ((Literal) right).getValue();
if (objGeom instanceof org.opengis.geometry.Envelope) {
final org.opengis.geometry.Envelope env = (org.opengis.geometry.Envelope) objGeom;
minx = env.getMinimum(0);
maxx = env.getMaximum(0);
miny = env.getMinimum(1);
maxy = env.getMaximum(1);
try {
srs = IdentifiedObjects.lookupURN(env.getCoordinateReferenceSystem(), null);
if (srs == null) {
srs = ReferencingUtilities.lookupIdentifier(env.getCoordinateReferenceSystem(), true);
}
} catch (FactoryException ex) {
throw new IllegalArgumentException("invalid bbox element : " + filter + " " + ex.getMessage(), ex);
}
} else if (objGeom instanceof Geometry) {
final Geometry geom = (Geometry) objGeom;
final Envelope env = geom.getEnvelopeInternal();
minx = env.getMinX();
maxx = env.getMaxX();
miny = env.getMinY();
maxy = env.getMaxY();
srs = SRIDGenerator.toSRS(geom.getSRID(), SRIDGenerator.Version.V1);
} else {
throw new IllegalArgumentException("invalid bbox element : " + filter);
}
} else if (right instanceof ValueReference) {
property = ((ValueReference) right).getXPath();
final Object objGeom = ((Literal) left).getValue();
if (objGeom instanceof org.opengis.geometry.Envelope) {
final org.opengis.geometry.Envelope env = (org.opengis.geometry.Envelope) objGeom;
minx = env.getMinimum(0);
maxx = env.getMaximum(0);
miny = env.getMinimum(1);
maxy = env.getMaximum(1);
try {
srs = IdentifiedObjects.lookupURN(env.getCoordinateReferenceSystem(), null);
if (srs == null) {
srs = ReferencingUtilities.lookupIdentifier(env.getCoordinateReferenceSystem(), true);
}
} catch (FactoryException ex) {
throw new IllegalArgumentException("invalid bbox element : " + filter + " " + ex.getMessage(), ex);
}
} else if (objGeom instanceof Geometry) {
final Geometry geom = (Geometry) objGeom;
final Envelope env = geom.getEnvelopeInternal();
minx = env.getMinX();
maxx = env.getMaxX();
miny = env.getMinY();
maxy = env.getMaxY();
srs = SRIDGenerator.toSRS(geom.getSRID(), SRIDGenerator.Version.V1);
} else {
throw new IllegalArgumentException("invalid bbox element : " + filter);
}
} else {
throw new IllegalArgumentException("invalid bbox element : " + filter);
}
final BBOXType bbtype = new BBOXType(property, minx, miny, maxx, maxy, srs);
return ogc_factory.createBBOX(bbtype);
} else if (filter instanceof ResourceId) {
final ValueReference n = FF.property(AttributeConvention.IDENTIFIER);
ResourceId idFilter = (ResourceId) filter;
final String id = idFilter.getIdentifier();
final ResourceIdType rId = ogc_factory.createResourceIdType();
rId.setRid(id);
return ogc_factory.createResourceId(rId);
} else if (filter instanceof BinarySpatialOperator) {
final BinarySpatialOperator spatialOp = (BinarySpatialOperator) filter;
Expression exp1 = spatialOp.getOperand1();
Expression exp2 = spatialOp.getOperand2();
if (!(exp1 instanceof ValueReference)) {
// flip order
final Expression ex = exp1;
exp1 = exp2;
exp2 = ex;
}
if (!(exp1 instanceof ValueReference)) {
throw new IllegalArgumentException("Filter can not be transformed in xml filter, " + "expression are not of the required type ");
} else if (!(exp2 instanceof Literal)) {
throw new IllegalArgumentException("Spatial operator should use a literal object containing the filtering geometry.");
}
final JAXBElement pnt = extract(exp1);
final String pName;
if (pnt.getValue() instanceof String) {
pName = (String) pnt.getValue();
} else {
throw new IllegalArgumentException("Property name cannot be cast to string.");
}
final JAXBElement<?> geometryExpression;
final Object geom = ((Literal) exp2).getValue();
if (geom instanceof Geometry) {
final Geometry jts = (Geometry) geom;
final String srid = SRIDGenerator.toSRS(jts.getSRID(), SRIDGenerator.Version.V1);
CoordinateReferenceSystem crs;
try {
crs = CRS.forCode(srid);
} catch (Exception ex) {
Logger.getLogger("org.geotoolkit.sld.xml").log(Level.WARNING, null, ex);
crs = null;
}
final AbstractGeometry gmlGeom;
try {
gmlGeom = JTStoGeometry.toGML("3.2.1", jts);
} catch (FactoryException ex) {
throw new IllegalArgumentException(ex);
}
// TODO use gml method to return any JAXBElement
if (gmlGeom instanceof PointType) {
geometryExpression = gml_factory.createPoint((PointType) gmlGeom);
} else if (gmlGeom instanceof CurveType) {
geometryExpression = gml_factory.createCurve((CurveType) gmlGeom);
} else if (gmlGeom instanceof LineStringType) {
geometryExpression = gml_factory.createLineString((LineStringType) gmlGeom);
} else if (gmlGeom instanceof PolygonType) {
geometryExpression = gml_factory.createPolygon((PolygonType) gmlGeom);
} else if (gmlGeom instanceof MultiSurfaceType) {
geometryExpression = gml_factory.createMultiSurface((MultiSurfaceType) gmlGeom);
} else if (gmlGeom instanceof MultiCurveType) {
geometryExpression = gml_factory.createMultiCurve((MultiCurveType) gmlGeom);
} else if (gmlGeom instanceof MultiPointType) {
geometryExpression = gml_factory.createMultiPoint((MultiPointType) gmlGeom);
} else if (gmlGeom instanceof MultiGeometryType) {
geometryExpression = gml_factory.createMultiGeometry((MultiGeometryType) gmlGeom);
} else if (gmlGeom instanceof SurfaceType) {
geometryExpression = gml_factory.createPolyhedralSurface((SurfaceType) gmlGeom);
} else {
throw new IllegalArgumentException("Unexpected Geometry type:" + gmlGeom.getClass().getName());
}
} else if (geom instanceof org.opengis.geometry.Geometry) {
throw new UnsupportedOperationException("No valid ISO implementation avaiable for now.");
} else if (geom instanceof org.opengis.geometry.Envelope) {
final org.opengis.geometry.Envelope genv = (org.opengis.geometry.Envelope) geom;
EnvelopeType ee = gml_factory.createEnvelopeType();
ee.setSrsDimension(genv.getDimension());
if (genv.getCoordinateReferenceSystem() != null) {
String urn;
try {
urn = IdentifiedObjects.lookupURN(genv.getCoordinateReferenceSystem(), null);
} catch (FactoryException ex) {
Logger.getLogger("org.geotoolkit.sld.xml").log(Level.WARNING, null, ex);
urn = null;
}
if (urn == null) {
urn = IdentifiedObjects.getIdentifierOrName(genv.getCoordinateReferenceSystem());
}
if (urn != null) {
ee.setSrsName(urn);
}
}
ee.setLowerCorner(new DirectPositionType(genv.getLowerCorner(), false));
ee.setUpperCorner(new DirectPositionType(genv.getUpperCorner(), false));
geometryExpression = gml_factory.createEnvelope(ee);
} else {
throw new IllegalArgumentException("Type is neither geometric nor envelope.");
}
if (type == DistanceOperatorName.BEYOND) {
throw new UnsupportedOperationException();
} else if (type == SpatialOperatorName.CONTAINS) {
return ogc_factory.createContains(new ContainsType(pName, geometryExpression));
} else if (type == SpatialOperatorName.CROSSES) {
ogc_factory.createCrosses(new CrossesType(pName, geometryExpression));
} else if (type == DistanceOperatorName.WITHIN) {
Quantity q = ((DistanceOperator) filter).getDistance();
return ogc_factory.createDWithin(new DWithinType(pName, geometryExpression, q.getValue().doubleValue(), q.getUnit().toString()));
} else if (type == SpatialOperatorName.DISJOINT) {
return ogc_factory.createDisjoint(new DisjointType(pName, geometryExpression));
} else if (type == SpatialOperatorName.EQUALS) {
return ogc_factory.createEquals(new EqualsType(pName, geometryExpression));
} else if (type == SpatialOperatorName.INTERSECTS) {
return ogc_factory.createIntersects(new IntersectsType(pName, geometryExpression));
} else if (type == SpatialOperatorName.OVERLAPS) {
return ogc_factory.createOverlaps(new OverlapsType(pName, geometryExpression));
} else if (type == SpatialOperatorName.TOUCHES) {
return ogc_factory.createTouches(new TouchesType(pName, geometryExpression));
} else if (type == SpatialOperatorName.WITHIN) {
return ogc_factory.createWithin(new WithinType(pName, geometryExpression));
}
throw new IllegalArgumentException("Unknown filter element : " + filter + " class :" + filter.getClass());
}
throw new IllegalArgumentException("Unknown filter element : " + filter + " class :" + filter.getClass());
}
Aggregations