use of org.apache.xmlbeans.XmlCursor in project arctic-sea by 52North.
the class FesDecoderv20 method parseSpatialFilterType.
/**
* Parses the spatial filter of a request.
*
* @param xbSpatialOpsType
* XmlBean representing the feature of interest parameter of the
* request
* @return Returns SpatialFilter created from the passed foi request
* parameter
*
* @throws DecodingException
* * if creation of the SpatialFilter failed
*/
private SpatialFilter parseSpatialFilterType(SpatialOpsType xbSpatialOpsType) throws DecodingException {
SpatialFilter spatialFilter = new SpatialFilter();
try {
if (xbSpatialOpsType instanceof BBOXType) {
spatialFilter.setOperator(FilterConstants.SpatialOperator.BBOX);
BBOXType xbBBOX = (BBOXType) xbSpatialOpsType;
if (isValueReferenceExpression(xbBBOX.getExpression())) {
spatialFilter.setValueReference(parseValueReference(xbBBOX.getExpression()));
}
XmlCursor geometryCursor = xbSpatialOpsType.newCursor();
if (geometryCursor.toChild(GmlConstants.QN_ENVELOPE_32)) {
Object sosGeometry = decodeXmlObject(Factory.parse(geometryCursor.getDomNode()));
if (sosGeometry instanceof Geometry) {
spatialFilter.setGeometry((Geometry) sosGeometry);
} else if (sosGeometry instanceof ReferencedEnvelope) {
spatialFilter.setGeometry((ReferencedEnvelope) sosGeometry);
} else {
throw new UnsupportedDecoderXmlInputException(this, xbSpatialOpsType);
}
} else {
throw new DecodingException(Sos2Constants.GetObservationParams.spatialFilter, "The requested spatial filter operand is not supported by this SOS!");
}
geometryCursor.dispose();
} else {
throw new DecodingException(Sos2Constants.GetObservationParams.spatialFilter, "The requested spatial filter is not supported by this SOS!");
}
} catch (XmlException xmle) {
throw new DecodingException("Error while parsing spatial filter!", xmle);
}
return spatialFilter;
}
use of org.apache.xmlbeans.XmlCursor in project arctic-sea by 52North.
the class OgcDecoderv100 method parseSpatialOperatorType.
private Object parseSpatialOperatorType(BinarySpatialOpType xbSpatialOpsType) throws DecodingException {
SpatialFilter spatialFilter = new SpatialFilter();
try {
if (xbSpatialOpsType instanceof BBOXTypeImpl) {
spatialFilter.setOperator(FilterConstants.SpatialOperator.BBOX);
BBOXTypeImpl xbBBOX = (BBOXTypeImpl) xbSpatialOpsType;
spatialFilter.setOperator(FilterConstants.SpatialOperator.BBOX);
XmlCursor geometryCursor = xbBBOX.newCursor();
if (geometryCursor.toChild(GmlConstants.QN_ENVELOPE)) {
Object sosGeometry = decodeXmlElement(XmlObject.Factory.parse(geometryCursor.getDomNode()));
if (sosGeometry instanceof Geometry) {
spatialFilter.setGeometry((Geometry) sosGeometry);
}
} else {
throw unsupportedSpatialFilter();
}
geometryCursor.dispose();
} else {
throw unsupportedSpatialFilter();
}
} catch (XmlException xmle) {
throw errorParsingSpatialFilter(xmle);
}
return spatialFilter;
}
use of org.apache.xmlbeans.XmlCursor in project arctic-sea by 52North.
the class GmlEncoderv311 method createFeatureCollection.
@SuppressFBWarnings("NP_NULL_ON_SOME_PATH")
private XmlObject createFeatureCollection(FeatureCollection sosFeatureCollection) throws EncodingException {
Map<String, AbstractFeature> members = sosFeatureCollection.getMembers();
XmlObject xmlObject = null;
if (sosFeatureCollection.isSetMembers()) {
if (members.size() == 1) {
for (Entry<String, AbstractFeature> entry : members.entrySet()) {
String member = entry.getKey();
if (members.get(member) instanceof SamplingFeature) {
return createFeature((SamplingFeature) members.get(member));
} else {
throw missingFeatureEncoder();
}
}
} else {
FeatureCollectionDocument2 xbFeatureColllectionDoc = FeatureCollectionDocument2.Factory.newInstance(getXmlOptions());
AbstractFeatureCollectionType xbFeatCol = xbFeatureColllectionDoc.addNewFeatureCollection();
StringBuilder builder = new StringBuilder();
builder.append("sfc_");
builder.append(JavaHelper.generateID(Long.toString(System.currentTimeMillis())));
xbFeatCol.setId(builder.toString());
for (Entry<String, AbstractFeature> entry : members.entrySet()) {
String member = entry.getKey();
if (members.get(member) instanceof SamplingFeature) {
XmlObject xmlFeature = createFeature((SamplingFeature) members.get(member));
xbFeatCol.addNewFeatureMember().set(xmlFeature);
} else {
throw missingFeatureEncoder();
}
}
xmlObject = xbFeatureColllectionDoc;
}
} else {
FeatureCollectionDocument2 xbFeatColDoc = FeatureCollectionDocument2.Factory.newInstance(getXmlOptions());
xbFeatColDoc.addNewFeatureCollection();
xmlObject = xbFeatColDoc;
}
XmlCursor cursor = xmlObject.newCursor();
boolean isAFC = cursor.toChild(new QName(GmlConstants.NS_GML, GmlConstants.EN_ABSTRACT_FEATURE_COLLECTION));
if (isAFC) {
cursor.setName(new QName(GmlConstants.NS_GML, GmlConstants.EN_FEATURE_COLLECTION));
}
cursor.dispose();
return xmlObject;
}
use of org.apache.xmlbeans.XmlCursor in project arctic-sea by 52North.
the class GmlEncoderv311 method createPolygonFromJtsGeometry.
/**
* Creates a XML Polygon from a SOS Polygon.
*
* @param jtsPolygon
* SOS Polygon
* @param xbPolType
* XML Polygon
*/
private void createPolygonFromJtsGeometry(Polygon jtsPolygon, PolygonType xbPolType) {
List<?> jtsPolygons = PolygonExtracter.getPolygons(jtsPolygon);
for (int i = 0; i < jtsPolygons.size(); i++) {
Polygon pol = (Polygon) jtsPolygons.get(i);
AbstractRingPropertyType xbArpt = xbPolType.addNewExterior();
AbstractRingType xbArt = xbArpt.addNewRing();
LinearRingType xbLrt = LinearRingType.Factory.newInstance(getXmlOptions());
// Exterior ring
LineString ring = pol.getExteriorRing();
String coords = JTSHelper.getCoordinatesString(ring);
DirectPositionListType xbPosList = xbLrt.addNewPosList();
xbPosList.setSrsName(getSrsName(jtsPolygon));
// switch coordinates
xbPosList.setStringValue(coords);
xbArt.set(xbLrt);
// Rename element name for output
XmlCursor cursor = xbArpt.newCursor();
if (cursor.toChild(GmlConstants.QN_ABSTRACT_RING)) {
cursor.setName(GmlConstants.QN_LINEAR_RING);
}
// Interior ring
int numberOfInteriorRings = pol.getNumInteriorRing();
for (int ringNumber = 0; ringNumber < numberOfInteriorRings; ringNumber++) {
xbArpt = xbPolType.addNewInterior();
xbArt = xbArpt.addNewRing();
xbLrt = LinearRingType.Factory.newInstance(getXmlOptions());
ring = pol.getInteriorRingN(ringNumber);
xbPosList = xbLrt.addNewPosList();
xbPosList.setSrsName(getSrsName(jtsPolygon));
xbPosList.setStringValue(JTSHelper.getCoordinatesString(ring));
xbArt.set(xbLrt);
// Rename element name for output
cursor = xbArpt.newCursor();
if (cursor.toChild(GmlConstants.QN_ABSTRACT_RING)) {
cursor.setName(GmlConstants.QN_LINEAR_RING);
}
}
}
}
use of org.apache.xmlbeans.XmlCursor in project arctic-sea by 52North.
the class GmlEncoderv321 method createPolygonFromJtsGeometry.
/**
* Creates a XML Polygon from a SOS Polygon.
*
* @param jtsPolygon
* SOS Polygon
* @param xbPolType
* XML Polygon
*/
private void createPolygonFromJtsGeometry(Polygon jtsPolygon, PolygonType xbPolType) {
List<?> jtsPolygons = PolygonExtracter.getPolygons(jtsPolygon);
String srsName = getSrsName(jtsPolygon);
for (int i = 0; i < jtsPolygons.size(); i++) {
Polygon pol = (Polygon) jtsPolygons.get(i);
AbstractRingPropertyType xbArpt = xbPolType.addNewExterior();
AbstractRingType xbArt = xbArpt.addNewAbstractRing();
LinearRingType xbLrt = LinearRingType.Factory.newInstance();
// Exterior ring
LineString ring = pol.getExteriorRing();
DirectPositionListType xbPosList = xbLrt.addNewPosList();
xbPosList.setSrsName(srsName);
xbPosList.setStringValue(JTSHelper.getCoordinatesString(ring));
xbArt.set(xbLrt);
// Rename element name for output
XmlCursor cursor = xbArpt.newCursor();
if (cursor.toChild(GmlConstants.QN_ABSTRACT_RING_32)) {
cursor.setName(GmlConstants.QN_LINEAR_RING_32);
}
// Interior ring
int numberOfInteriorRings = pol.getNumInteriorRing();
for (int ringNumber = 0; ringNumber < numberOfInteriorRings; ringNumber++) {
xbArpt = xbPolType.addNewInterior();
xbArt = xbArpt.addNewAbstractRing();
xbLrt = LinearRingType.Factory.newInstance();
ring = pol.getInteriorRingN(ringNumber);
xbPosList = xbLrt.addNewPosList();
xbPosList.setSrsName(srsName);
xbPosList.setStringValue(JTSHelper.getCoordinatesString(ring));
xbArt.set(xbLrt);
// Rename element name for output
cursor = xbArpt.newCursor();
if (cursor.toChild(GmlConstants.QN_ABSTRACT_RING_32)) {
cursor.setName(GmlConstants.QN_LINEAR_RING_32);
}
}
}
}
Aggregations