use of org.geotoolkit.gml.xml.v311.EnvelopeType in project geotoolkit by Geomatys.
the class OGC110toGTTransformer method visitEnv.
public Expression visitEnv(final JAXBElement<EnvelopeType> env) throws FactoryException {
final EnvelopeType entry = env.getValue();
String srs = entry.getSrsName();
DirectPositionType lower = entry.getLowerCorner();
DirectPositionType upper = entry.getUpperCorner();
GeneralEnvelope genv = new GeneralEnvelope(CRS.forCode(srs));
genv.setRange(0, lower.getOrdinate(0), upper.getOrdinate(0));
genv.setRange(1, lower.getOrdinate(1), upper.getOrdinate(1));
return filterFactory.literal(genv);
}
use of org.geotoolkit.gml.xml.v311.EnvelopeType 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.gml.xml.v311.EnvelopeType in project geotoolkit by Geomatys.
the class GmlXMLBindingTest method marshallingTest.
/**
* Test simple Record Marshalling.
*
* @throws JAXBException
*/
@Test
public void marshallingTest() throws Exception {
DirectPositionType lower = new DirectPositionType(-30.711, 134.196);
DirectPositionType upper = new DirectPositionType(-30.702, 134.205);
EnvelopeType env = new EnvelopeType(lower, upper, "urn:ogc:def:crs:EPSG:6.8:4283");
StringWriter sw = new StringWriter();
marshaller.marshal(FACTORY.createEnvelope(env), sw);
String result = sw.toString();
// we remove the first line
result = result.substring(result.indexOf("?>") + 2).trim();
String expResult = "<gml:Envelope xmlns:gml=\"http://www.opengis.net/gml/3.2\" srsName=\"urn:ogc:def:crs:EPSG:6.8:4283\" >" + '\n' + " <gml:lowerCorner>-30.711 134.196</gml:lowerCorner>" + '\n' + " <gml:upperCorner>-30.702 134.205</gml:upperCorner>" + '\n' + "</gml:Envelope>" + '\n';
DocumentComparator comparator = new DocumentComparator(expResult, result) {
@Override
protected strictfp void compareNames(Node expected, Node actual) {
final String[] exArray = expected.getNodeName().split(":");
final String[] acArray = actual.getNodeName().split(":");
assertEquals(exArray.length, acArray.length);
assertEquals(exArray[exArray.length - 1], acArray[acArray.length - 1]);
}
};
comparator.ignoredAttributes.add("http://www.w3.org/2000/xmlns:*");
comparator.compare();
Duration d1 = javax.xml.datatype.DatatypeFactory.newInstance().newDuration("P2D");
TimePeriodType tp = new TimePeriodType(d1);
marshaller.marshal(FACTORY.createTimePeriod(tp), sw);
TimePositionType tpos = new TimePositionType("2002-08-15");
tp = new TimePeriodType(tpos);
marshaller.marshal(FACTORY.createTimePeriod(tp), sw);
// System.out.println(sw.toString());
LineStringSegmentType ls = new LineStringSegmentType();
DirectPositionListType posList = new DirectPositionListType();
posList.setValue(Arrays.asList(1.0, 1.1, 1.2));
ls.setPosList(posList);
sw = new StringWriter();
marshaller.marshal(FACTORY.createLineStringSegment(ls), sw);
result = sw.toString();
// we remove the first line
result = result.substring(result.indexOf("?>") + 2).trim();
expResult = "<gml:LineStringSegment xmlns:gml=\"http://www.opengis.net/gml/3.2\">" + '\n' + " <gml:posList>1.0 1.1 1.2</gml:posList>" + '\n' + "</gml:LineStringSegment>" + '\n';
comparator = new DocumentComparator(expResult, result) {
@Override
protected strictfp void compareNames(Node expected, Node actual) {
final String[] exArray = expected.getNodeName().split(":");
final String[] acArray = actual.getNodeName().split(":");
assertEquals(exArray.length, acArray.length);
assertEquals(exArray[exArray.length - 1], acArray[acArray.length - 1]);
}
};
comparator.ignoredAttributes.add("http://www.w3.org/2000/xmlns:*");
comparator.compare();
ls = new LineStringSegmentType();
DirectPositionType pos1 = new DirectPositionType(Arrays.asList(1.1, 1.2));
DirectPositionType pos2 = new DirectPositionType(Arrays.asList(2.3, 48.1));
ls.getPos().add(pos1);
ls.getPos().add(pos2);
sw = new StringWriter();
marshaller.marshal(FACTORY.createLineStringSegment(ls), sw);
result = sw.toString();
// we remove the first line
result = result.substring(result.indexOf("?>") + 2).trim();
expResult = "<gml:LineStringSegment xmlns:gml=\"http://www.opengis.net/gml/3.2\">" + '\n' + " <gml:pos>1.1 1.2</gml:pos>" + '\n' + " <gml:pos>2.3 48.1</gml:pos>" + '\n' + "</gml:LineStringSegment>" + '\n';
comparator = new DocumentComparator(expResult, result) {
@Override
protected strictfp void compareNames(Node expected, Node actual) {
final String[] exArray = expected.getNodeName().split(":");
final String[] acArray = actual.getNodeName().split(":");
assertEquals(exArray.length, acArray.length);
assertEquals(exArray[exArray.length - 1], acArray[acArray.length - 1]);
}
};
comparator.ignoredAttributes.add("http://www.w3.org/2000/xmlns:*");
comparator.compare();
}
use of org.geotoolkit.gml.xml.v311.EnvelopeType in project ddf by codice.
the class CswFilterFactory method createBinarySpatialOpType.
private BinarySpatialOpType createBinarySpatialOpType(PropertyNameType propertyName, String wkt, BinarySpatialOperand geometryOrEnvelope) {
BinarySpatialOpType binarySpatialOpType = null;
if (geometryOrEnvelope == BinarySpatialOperand.GEOMETRY) {
wkt = convertWktToLatLonOrdering(wkt);
Geometry geometry = getGeometryFromWkt(wkt);
JAXBElement<? extends AbstractGeometryType> geometryJaxbElement = convertGeometry(geometry);
binarySpatialOpType = createBinarySpatialOpTypeUsingGeometry(propertyName, geometryJaxbElement);
} else {
JAXBElement<EnvelopeType> envelopeJaxbElement = createEnvelopeType(wkt);
binarySpatialOpType = createBinarySpatialOpTypeUsingEnvelope(propertyName, envelopeJaxbElement);
}
return binarySpatialOpType;
}
use of org.geotoolkit.gml.xml.v311.EnvelopeType in project ddf by codice.
the class CswFilterFactory method createBBoxType.
private JAXBElement<BBOXType> createBBoxType(String propertyName, String wkt) {
BBOXType bboxType = new BBOXType();
JAXBElement<EnvelopeType> envelope = createEnvelopeType(wkt);
bboxType.setEnvelope(envelope);
bboxType.setPropertyName(createPropertyNameType(propertyName));
return filterObjectFactory.createBBOX(bboxType);
}
Aggregations