use of org.n52.shetland.ogc.om.features.FeatureCollection in project arctic-sea by 52North.
the class AqdGetObservationResponseXmlStreamWriter method writeFeatureCollectionDoc.
private void writeFeatureCollectionDoc() throws XMLStreamException, EncodingException {
start(GmlConstants.QN_FEATURE_COLLECTION_32);
addNamespaces();
addSchemaLocations();
FeatureCollection featureCollection = getElement();
addGmlId(featureCollection.getGmlId());
TimeInstant resultTime = new TimeInstant(new DateTime(DateTimeZone.UTC));
for (AbstractFeature abstractFeature : featureCollection.getMembers().values()) {
long start = System.currentTimeMillis();
Encoder<XmlObject, AbstractFeature> encoder = getEncoder(abstractFeature);
if (abstractFeature instanceof OmObservation) {
OmObservation observation = (OmObservation) abstractFeature;
if (observation.getValue() instanceof ObservationStream) {
try {
// start the timer task to write blank strings to avoid
// connection closing
startTimer();
ObservationStream mergeObservation = ((ObservationStream) observation.getValue()).merge();
LOGGER.debug("Observation processing requires {} ms", System.currentTimeMillis() - start);
int count = 0;
while (mergeObservation.hasNext()) {
OmObservation omObservation = mergeObservation.next();
if (abstractFeature.isSetGmlID()) {
if (count == 0) {
omObservation.setGmlId(abstractFeature.getGmlId());
} else {
omObservation.setGmlId(abstractFeature.getGmlId() + "_" + count);
}
count++;
}
omObservation.setResultTime(resultTime);
String xmlTextObservation = prepareObservation(omObservation, encoder);
// stop the timer task
stopTimer();
writeMember(xmlTextObservation);
}
} catch (OwsExceptionReport ex) {
throw new EncodingException(ex);
}
} else {
if (encoder instanceof XmlStreamWriter) {
encoder.encode(abstractFeature, getContext());
} else {
writeMember(abstractFeature, encoder);
}
}
} else {
writeMember(abstractFeature, encoder);
}
LOGGER.debug("Writing member requires {} ms", System.currentTimeMillis() - start);
}
end(GmlConstants.QN_FEATURE_COLLECTION_32);
}
use of org.n52.shetland.ogc.om.features.FeatureCollection in project arctic-sea by 52North.
the class GetFeatureOfInterestXmlStreamWriter method writeGetFeatureOfInterestResponseDoc.
private void writeGetFeatureOfInterestResponseDoc() throws XMLStreamException, EncodingException {
start(Sos2StreamingConstants.QN_GET_FEATURE_OF_INTEREST_RESPONSE);
namespace(W3CConstants.NS_XLINK_PREFIX, W3CConstants.NS_XLINK);
namespace(Sos2Constants.NS_SOS_PREFIX, Sos2Constants.NS_SOS_20);
// write schemaLocation
schemaLocation(getSchemaLocation());
AbstractFeature feature = getElement().getAbstractFeature();
if (feature instanceof FeatureCollection) {
for (AbstractFeature f : (FeatureCollection) feature) {
writeFeatureMember(f);
}
} else if (feature instanceof AbstractSamplingFeature) {
writeFeatureMember(feature);
}
end(Sos2StreamingConstants.QN_GET_FEATURE_OF_INTEREST_RESPONSE);
}
use of org.n52.shetland.ogc.om.features.FeatureCollection in project arctic-sea by 52North.
the class FeatureCollectionTest method should_remove_member_from_feature_collection.
@Test
public final void should_remove_member_from_feature_collection() {
final FeatureCollection features = new FeatureCollection();
final String feature1Id = "feature-1";
final SamplingFeature feature1 = new SamplingFeature(new CodeWithAuthority(feature1Id));
features.addMember(feature1);
final String feature2Id = "feature-2";
final SamplingFeature feature2 = new SamplingFeature(new CodeWithAuthority(feature2Id));
features.addMember(feature2);
final SamplingFeature removedFeature = (SamplingFeature) features.removeMember(feature2Id);
assertThat(removedFeature, is(equalTo(feature2)));
assertThat(features.getMembers().size(), is(1));
assertThat(features.getMembers().containsKey(feature2Id), is(FALSE));
assertThat(features.getMembers().containsValue(feature2), is(FALSE));
assertThat(features.getMembers().containsKey(feature1Id), is(TRUE));
assertThat(features.getMembers().containsValue(feature1), is(TRUE));
}
use of org.n52.shetland.ogc.om.features.FeatureCollection in project arctic-sea by 52North.
the class AbstractWmlEncoderv20 method createMonitoringPoint.
/**
* Creates a WaterML 2.0 MonitoringPoint XML object from SOS feature object
*
* @param absFeature
* SOS feature
* @return WaterML 2.0 MonitoringPoint XML object
* @throws EncodingException
* If an error occurs
*/
protected XmlObject createMonitoringPoint(AbstractFeature absFeature) throws EncodingException {
if (absFeature instanceof AbstractSamplingFeature) {
AbstractSamplingFeature sampFeat = (AbstractSamplingFeature) absFeature;
StringBuilder builder = new StringBuilder();
builder.append("mp_");
builder.append(JavaHelper.generateID(absFeature.getIdentifierCodeWithAuthority().getValue()));
absFeature.setGmlId(builder.toString());
MonitoringPointDocument monitoringPointDoc = MonitoringPointDocument.Factory.newInstance(getXmlOptions());
if (sampFeat.isSetXml()) {
try {
XmlObject feature = XmlObject.Factory.parse(sampFeat.getXml());
if (XmlHelper.getNamespace(feature).equals(WaterMLConstants.NS_WML_20)) {
if (feature instanceof MonitoringPointDocument) {
monitoringPointDoc = (MonitoringPointDocument) feature;
} else if (feature instanceof MonitoringPointType) {
monitoringPointDoc.setSFSpatialSamplingFeature((MonitoringPointType) feature);
}
XmlHelper.updateGmlIDs(monitoringPointDoc.getDomNode(), absFeature.getGmlId(), null);
return monitoringPointDoc;
}
} catch (XmlException xmle) {
throw new EncodingException("Error while encoding GetFeatureOfInterest response, invalid samplingFeature description!", xmle);
}
}
MonitoringPointType mpt = monitoringPointDoc.addNewMonitoringPoint();
// set gml:id
mpt.setId(absFeature.getGmlId());
if (sampFeat.isSetIdentifier()) {
XmlObject xmlObject = encodeGML(sampFeat.getIdentifierCodeWithAuthority());
if (xmlObject != null) {
mpt.addNewIdentifier().set(xmlObject);
}
}
if (sampFeat.isSetName()) {
for (CodeType sosName : sampFeat.getName()) {
mpt.addNewName().set(encodeGML(sosName));
}
}
if (sampFeat.isSetDescription()) {
if (!mpt.isSetDescription()) {
mpt.addNewDescription();
}
mpt.getDescription().setStringValue(sampFeat.getDescription());
}
// TODO: CHECK
if (sampFeat.getSampledFeatures() != null && !sampFeat.getSampledFeatures().isEmpty()) {
if (sampFeat.getSampledFeatures().size() == 1) {
XmlObject encodeObjectToXml = encodeObjectToXml(GmlConstants.NS_GML_32, sampFeat.getSampledFeatures().get(0));
mpt.addNewSampledFeature().set(encodeObjectToXml);
} else {
FeatureCollection featureCollection = new FeatureCollection();
featureCollection.setGmlId("sampledFeatures_" + absFeature.getGmlId());
for (AbstractFeature sampledFeature : sampFeat.getSampledFeatures()) {
featureCollection.addMember(sampledFeature);
}
XmlObject encodeObjectToXml = encodeGML(featureCollection);
mpt.addNewSampledFeature().set(encodeObjectToXml);
}
} else {
mpt.addNewSampledFeature().setHref(GmlConstants.NIL_UNKNOWN);
}
if (sampFeat.isSetParameter()) {
addParameter(mpt, sampFeat);
}
// set position
ShapeType xbShape = mpt.addNewShape();
Encoder<XmlObject, Geometry> encoder = getEncoder(getEncoderKey(GmlConstants.NS_GML_32, sampFeat.getGeometry()));
if (encoder != null) {
XmlObject xmlObject = encoder.encode(sampFeat.getGeometry(), new EncodingContext().with(XmlBeansEncodingFlags.GMLID, absFeature.getGmlId()));
xbShape.addNewAbstractGeometry().set(xmlObject);
XmlHelper.substituteElement(xbShape.getAbstractGeometry(), xmlObject);
} else {
throw new EncodingException("Error while encoding geometry for feature, needed encoder is missing!");
}
if (absFeature instanceof WmlMonitoringPoint) {
addMonitoringPointValues(mpt, (WmlMonitoringPoint) absFeature);
}
sampFeat.wasEncoded();
return monitoringPointDoc;
}
throw new UnsupportedEncoderInputException(this, absFeature);
}
use of org.n52.shetland.ogc.om.features.FeatureCollection in project arctic-sea by 52North.
the class AqdEncoder method processObservation.
protected void processObservation(OmObservation observation, TimePeriod timePeriod, TimeInstant resultTime, FeatureCollection featureCollection, AbstractEReportingHeader eReportingHeader, int counter) {
if (observation.isSetPhenomenonTime()) {
// generate gml:id
observation.setGmlId(getObservationId(counter));
// add xlink:href to eReportingHeader.content
eReportingHeader.addContent((AbstractFeature) new OmObservation().setIdentifier(new CodeWithAuthority(getObservationXlink(observation.getGmlId()))));
timePeriod.extendToContain(observation.getPhenomenonTime());
observation.setResultTime(resultTime);
featureCollection.addMember(observation);
}
}
Aggregations