use of org.geotoolkit.gml.xml.FeatureProperty in project geotoolkit by Geomatys.
the class XmlFeatureReader method getFeatureFromFOI.
protected final Feature getFeatureFromFOI(final AnyFeature foi) {
if (foi instanceof SamplingFeature) {
final SamplingFeature feature = (SamplingFeature) foi;
final Feature f = type.newInstance();
f.setPropertyValue(AttributeConvention.IDENTIFIER, feature.getId());
final org.opengis.geometry.Geometry isoGeom = feature.getGeometry();
try {
final Geometry geom;
if (isoGeom instanceof AbstractGeometry) {
geom = GeometrytoJTS.toJTS((AbstractGeometry) isoGeom);
} else {
geom = null;
}
if (firstCRS && isoGeom != null) {
// configure crs in the feature type
final CoordinateReferenceSystem crs = ((AbstractGeometry) isoGeom).getCoordinateReferenceSystem(false);
type = FeatureTypeExt.createSubType(type, null, crs);
firstCRS = false;
}
f.setPropertyValue(ATT_DESC.toString(), feature.getDescription());
if (feature.getName() != null) {
f.setPropertyValue(ATT_NAME.toString(), feature.getName().toString());
}
f.setPropertyValue(ATT_POSITION.toString(), geom);
final List<String> sampleds = new ArrayList<>();
for (FeatureProperty featProp : feature.getSampledFeatures()) {
if (featProp.getHref() != null) {
sampleds.add(featProp.getHref());
}
}
f.setPropertyValue(ATT_SAMPLED.toString(), sampleds);
return f;
} catch (FactoryException ex) {
LOGGER.log(Level.WARNING, "error while transforming GML geometry to JTS", ex);
}
} else {
LOGGER.warning("unable to find a valid feature of interest in the observation");
}
return null;
}
use of org.geotoolkit.gml.xml.FeatureProperty in project geotoolkit by Geomatys.
the class XmlObservationReader method getFeatureOfInterest.
@Override
public SamplingFeature getFeatureOfInterest(final String samplingFeatureName, final String version) throws DataStoreException {
for (Object xmlObject : xmlObjects) {
if (xmlObject instanceof ObservationCollection) {
final ObservationCollection collection = (ObservationCollection) xmlObject;
for (Observation obs : collection.getMember()) {
final AbstractObservation o = (AbstractObservation) obs;
final FeatureProperty foiProp = o.getPropertyFeatureOfInterest();
if (foiProp != null && foiProp.getAbstractFeature() != null && foiProp.getAbstractFeature().getId() != null && foiProp.getAbstractFeature().getId().equals(samplingFeatureName)) {
return (SamplingFeature) foiProp.getAbstractFeature();
}
}
} else if (xmlObject instanceof AbstractObservation) {
final AbstractObservation obs = (AbstractObservation) xmlObject;
final FeatureProperty foiProp = obs.getPropertyFeatureOfInterest();
if (foiProp != null && foiProp.getAbstractFeature() != null && foiProp.getAbstractFeature().getId() != null && foiProp.getAbstractFeature().getId().equals(samplingFeatureName)) {
return (SamplingFeature) foiProp.getAbstractFeature();
}
}
}
return null;
}
use of org.geotoolkit.gml.xml.FeatureProperty in project geotoolkit by Geomatys.
the class OMUtils method buildObservation.
public static AbstractObservation buildObservation(final String obsid, final SamplingFeature sf, final Phenomenon phenomenon, final Process procedure, final int count, final AbstractDataRecord datarecord, final MeasureStringBuilder sb, final TemporalGeometricPrimitive time) {
final DataArrayProperty result = SOSXmlFactory.buildDataArrayProperty("2.0.0", "array-1", count, "SimpleDataArray", datarecord, DEFAULT_ENCODING, sb.getString(), null);
final FeatureProperty foi = SOSXmlFactory.buildFeatureProperty("2.0.0", sf);
return // version
OMXmlFactory.buildObservation(// version
"2.0.0", // id
obsid, // name
obsid, // description
null, // foi
foi, // phenomenon
phenomenon, // procedure
procedure, // result
result, time, null);
}
use of org.geotoolkit.gml.xml.FeatureProperty in project geotoolkit by Geomatys.
the class OMUtils method buildObservation.
public static AbstractObservation buildObservation(final String obsid, final SamplingFeature sf, final Phenomenon phenomenon, final Process procedure, final int count, final AbstractDataRecord datarecord, final List<Object> dataValues, final TemporalGeometricPrimitive time) {
final DataArrayProperty result = SOSXmlFactory.buildDataArrayProperty("2.0.0", "array-1", count, "SimpleDataArray", datarecord, DEFAULT_ENCODING, null, dataValues);
final FeatureProperty foi = SOSXmlFactory.buildFeatureProperty("2.0.0", sf);
return // version
OMXmlFactory.buildObservation(// version
"2.0.0", // id
obsid, // name
obsid, // description
null, // foi
foi, // phenomenon
phenomenon, // procedure
procedure, // result
result, time, null);
}
use of org.geotoolkit.gml.xml.FeatureProperty in project geotoolkit by Geomatys.
the class AbstractComplexInputConverter method fromXml.
private static Stream<FeatureSet> fromXml(final Data source) {
final XmlFeatureReader fcollReader;
try {
fcollReader = WPSIO.getFeatureReader(source.getSchema());
} catch (MalformedURLException ex) {
throw new UnconvertibleObjectException("Unable to reach the schema url.", ex);
}
List<Object> content = new ArrayList<>();
// extract feature nodes from gml unmarshalled feature collection
for (Object o : source.getContent()) {
if (o instanceof JAXBElement) {
o = ((JAXBElement) o).getValue();
}
if (o instanceof FeatureCollection) {
FeatureCollection fc = (FeatureCollection) o;
for (FeatureProperty fp : fc.getFeatureMember()) {
if (fp.getUnknowFeature() != null) {
content.add(fp.getUnknowFeature());
} else {
throw new UnconvertibleObjectException("Unabel to read feature from XML.");
}
}
} else {
content.add(o);
}
}
final Stream<FeatureSet> result = content.stream().map(in -> {
try {
return fcollReader.read(in);
} catch (XMLStreamException | IOException ex) {
throw new UnconvertibleObjectException("Unable to read feature from nodes.", ex);
}
}).map(ReferenceToFeatureCollectionConverter::castOrWrap);
return result.onClose(() -> fcollReader.dispose());
}
Aggregations