Search in sources :

Example 1 with FeatureProperty

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;
}
Also used : AbstractGeometry(org.geotoolkit.gml.xml.AbstractGeometry) FactoryException(org.opengis.util.FactoryException) ArrayList(java.util.ArrayList) SamplingFeature(org.geotoolkit.sampling.xml.SamplingFeature) SamplingFeature(org.geotoolkit.sampling.xml.SamplingFeature) AnyFeature(org.opengis.observation.AnyFeature) Feature(org.opengis.feature.Feature) FeatureProperty(org.geotoolkit.gml.xml.FeatureProperty) AbstractGeometry(org.geotoolkit.gml.xml.AbstractGeometry) Geometry(org.locationtech.jts.geom.Geometry) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Example 2 with FeatureProperty

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;
}
Also used : Observation(org.opengis.observation.Observation) SamplingFeature(org.opengis.observation.sampling.SamplingFeature) FeatureProperty(org.geotoolkit.gml.xml.FeatureProperty) ObservationCollection(org.opengis.observation.ObservationCollection)

Example 3 with FeatureProperty

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);
}
Also used : DataArrayProperty(org.geotoolkit.swe.xml.DataArrayProperty) FeatureProperty(org.geotoolkit.gml.xml.FeatureProperty)

Example 4 with FeatureProperty

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);
}
Also used : DataArrayProperty(org.geotoolkit.swe.xml.DataArrayProperty) FeatureProperty(org.geotoolkit.gml.xml.FeatureProperty)

Example 5 with FeatureProperty

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());
}
Also used : ReferenceToFeatureCollectionConverter(org.geotoolkit.wps.converters.inputs.references.ReferenceToFeatureCollectionConverter) MalformedURLException(java.net.MalformedURLException) URISyntaxException(java.net.URISyntaxException) JAXBElement(javax.xml.bind.JAXBElement) ArgumentChecks(org.apache.sis.util.ArgumentChecks) WPSConvertersUtils(org.geotoolkit.wps.converters.WPSConvertersUtils) IOException(java.io.IOException) FeatureProperty(org.geotoolkit.gml.xml.FeatureProperty) ArrayList(java.util.ArrayList) List(java.util.List) Stream(java.util.stream.Stream) FeatureSet(org.apache.sis.storage.FeatureSet) Map(java.util.Map) XMLStreamException(javax.xml.stream.XMLStreamException) UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) FeatureCollection(org.geotoolkit.gml.xml.FeatureCollection) WPSDefaultConverter(org.geotoolkit.wps.converters.WPSDefaultConverter) Data(org.geotoolkit.wps.xml.v200.Data) DataStoreException(org.apache.sis.storage.DataStoreException) WPSIO(org.geotoolkit.wps.io.WPSIO) WPSMimeType(org.geotoolkit.wps.io.WPSMimeType) Path(java.nio.file.Path) XmlFeatureReader(org.geotoolkit.feature.xml.XmlFeatureReader) MalformedURLException(java.net.MalformedURLException) ReferenceToFeatureCollectionConverter(org.geotoolkit.wps.converters.inputs.references.ReferenceToFeatureCollectionConverter) XmlFeatureReader(org.geotoolkit.feature.xml.XmlFeatureReader) ArrayList(java.util.ArrayList) JAXBElement(javax.xml.bind.JAXBElement) FeatureProperty(org.geotoolkit.gml.xml.FeatureProperty) UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) FeatureCollection(org.geotoolkit.gml.xml.FeatureCollection) FeatureSet(org.apache.sis.storage.FeatureSet)

Aggregations

FeatureProperty (org.geotoolkit.gml.xml.FeatureProperty)7 ArrayList (java.util.ArrayList)3 AbstractGeometry (org.geotoolkit.gml.xml.AbstractGeometry)2 SamplingFeature (org.geotoolkit.sampling.xml.SamplingFeature)2 DataArrayProperty (org.geotoolkit.swe.xml.DataArrayProperty)2 Geometry (org.locationtech.jts.geom.Geometry)2 Feature (org.opengis.feature.Feature)2 AnyFeature (org.opengis.observation.AnyFeature)2 Observation (org.opengis.observation.Observation)2 ObservationCollection (org.opengis.observation.ObservationCollection)2 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)2 FactoryException (org.opengis.util.FactoryException)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 Path (java.nio.file.Path)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Stream (java.util.stream.Stream)1