use of org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature in project arctic-sea by 52North.
the class SamplingDecoderv20 method parseSpatialSamplingFeature.
private AbstractFeature parseSpatialSamplingFeature(final SFSpatialSamplingFeatureType spatialSamplingFeature) throws DecodingException {
final SamplingFeature sosFeat = new SamplingFeature(null, spatialSamplingFeature.getId());
// parse identifier, names, description
parseAbstractFeatureType(spatialSamplingFeature, sosFeat);
sosFeat.setFeatureType(getFeatureType(spatialSamplingFeature.getType()));
sosFeat.setSampledFeatures(getSampledFeatures(spatialSamplingFeature.getSampledFeatureArray()));
sosFeat.setXml(getXmlDescription(spatialSamplingFeature));
sosFeat.setGeometry(getGeometry(spatialSamplingFeature.getShape()));
checkTypeAndGeometry(sosFeat);
sosFeat.setGmlId(spatialSamplingFeature.getId());
return sosFeat;
}
use of org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature in project arctic-sea by 52North.
the class GmlEncoderv311 method createFeature.
private XmlObject createFeature(AbstractFeature sosAbstractFeature) throws EncodingException {
if (sosAbstractFeature instanceof SamplingFeature) {
SamplingFeature sampFeat = (SamplingFeature) sosAbstractFeature;
if (sosAbstractFeature.isSetGmlID()) {
FeaturePropertyType featureProperty = FeaturePropertyType.Factory.newInstance(getXmlOptions());
featureProperty.setHref("#" + sosAbstractFeature.getGmlId());
return featureProperty;
} else {
if (!sampFeat.isSetGeometry()) {
FeaturePropertyType featureProperty = FeaturePropertyType.Factory.newInstance(getXmlOptions());
featureProperty.setHref(sosAbstractFeature.getIdentifierCodeWithAuthority().getValue());
if (sampFeat.isSetName()) {
featureProperty.setTitle(sampFeat.getFirstName().getValue());
}
return featureProperty;
}
StringBuilder builder = new StringBuilder();
builder.append("sf_");
builder.append(JavaHelper.generateID(sosAbstractFeature.getIdentifierCodeWithAuthority().getValue()));
sosAbstractFeature.setGmlId(builder.toString());
Encoder<XmlObject, SamplingFeature> encoder = getEncoder(SfConstants.NS_SA, sampFeat);
return encoder.encode(sampFeat);
}
} else if (sosAbstractFeature instanceof FeatureCollection) {
return createFeatureCollection((FeatureCollection) sosAbstractFeature);
}
throw new UnsupportedEncoderInputException(this, sosAbstractFeature);
}
use of org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature 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.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature in project arctic-sea by 52North.
the class GmlEncoderv321 method createFeature.
private XmlObject createFeature(AbstractFeature feature, EncodingContext ctx) throws EncodingException {
FeaturePropertyType featurePropertyType = FeaturePropertyType.Factory.newInstance(getXmlOptions());
if (isNotSamplingFeature(feature) || ctx.has(XmlBeansEncodingFlags.REFERENCED)) {
featurePropertyType.setHref(feature.getIdentifierCodeWithAuthority().getValue());
return featurePropertyType;
} else {
AbstractSamplingFeature samplingFeature = (AbstractSamplingFeature) feature;
if (samplingFeature.isSetGmlID()) {
featurePropertyType.setHref("#" + samplingFeature.getGmlId());
return featurePropertyType;
} else {
if (ctx.has(XmlBeansEncodingFlags.ENCODE) && !ctx.getBoolean(XmlBeansEncodingFlags.ENCODE) || !samplingFeature.isEncode()) {
featurePropertyType.setHref(feature.getIdentifierCodeWithAuthority().getValue());
if (feature instanceof SamplingFeature && samplingFeature.isSetName()) {
featurePropertyType.setTitle(samplingFeature.getFirstName().getValue());
}
return featurePropertyType;
}
if (!samplingFeature.isSetGeometry()) {
featurePropertyType.setHref(samplingFeature.getIdentifierCodeWithAuthority().getValue());
if (samplingFeature.isSetName()) {
featurePropertyType.setTitle(samplingFeature.getFirstName().getValue());
}
return featurePropertyType;
}
if (samplingFeature.isSetUrl()) {
featurePropertyType.setHref(samplingFeature.getUrl());
if (samplingFeature.isSetName()) {
featurePropertyType.setTitle(samplingFeature.getFirstName().getValue());
}
return featurePropertyType;
} else {
String namespace = ctx.getString(XmlEncoderFlags.ENCODE_NAMESPACE).orElseGet(() -> OMHelper.getNamespaceForFeatureType(samplingFeature.getFeatureType()));
XmlObject encodedXmlObject = encodeObjectToXml(namespace, samplingFeature);
if (encodedXmlObject != null) {
return encodedXmlObject;
} else {
if (feature.isSetXml()) {
try {
// XmlDescription? <-- XmlCursor
return XmlObject.Factory.parse(feature.getXml());
} catch (XmlException xmle) {
throw new EncodingException("Error while encoding featurePropertyType!", xmle);
}
} else {
featurePropertyType.setHref(feature.getIdentifierCodeWithAuthority().getValue());
if (samplingFeature.isSetName()) {
featurePropertyType.setTitle(feature.getFirstName().getValue());
}
return featurePropertyType;
}
}
}
}
}
}
use of org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature in project arctic-sea by 52North.
the class SamplingEncoderv20 method createFeature.
@Override
protected XmlObject createFeature(FeaturePropertyType featurePropertyType, AbstractFeature abstractFeature, EncodingContext context) throws EncodingException {
if (abstractFeature instanceof AbstractSamplingFeature) {
final AbstractSamplingFeature samplingFeature = (AbstractSamplingFeature) abstractFeature;
String namespace;
if (context.has(XmlEncoderFlags.ENCODE_NAMESPACE) && context.get(XmlEncoderFlags.ENCODE_NAMESPACE).isPresent() && context.get(XmlEncoderFlags.ENCODE_NAMESPACE).get() instanceof String) {
namespace = (String) context.get(XmlEncoderFlags.ENCODE_NAMESPACE).get();
} else {
namespace = OMHelper.getNamespaceForFeatureType(samplingFeature.getFeatureType());
}
final XmlObject encodedXmlObject = encodeObjectToXml(namespace, samplingFeature);
if (encodedXmlObject != null) {
return encodedXmlObject;
} else {
if (samplingFeature.isSetXml()) {
try {
// XmlDescription? <-- XmlCursor
return XmlObject.Factory.parse(samplingFeature.getXml());
} catch (final XmlException xmle) {
throw new EncodingException("Error while encoding featurePropertyType!", xmle);
}
} else {
featurePropertyType.setHref(samplingFeature.getIdentifierCodeWithAuthority().getValue());
if (samplingFeature.isSetName()) {
featurePropertyType.setTitle(samplingFeature.getFirstName().getValue());
}
return featurePropertyType;
}
}
}
return featurePropertyType;
}
Aggregations