Search in sources :

Example 1 with FeatureCollection

use of org.geotoolkit.gml.xml.FeatureCollection 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

IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Stream (java.util.stream.Stream)1 JAXBElement (javax.xml.bind.JAXBElement)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 DataStoreException (org.apache.sis.storage.DataStoreException)1 FeatureSet (org.apache.sis.storage.FeatureSet)1 ArgumentChecks (org.apache.sis.util.ArgumentChecks)1 UnconvertibleObjectException (org.apache.sis.util.UnconvertibleObjectException)1 XmlFeatureReader (org.geotoolkit.feature.xml.XmlFeatureReader)1 FeatureCollection (org.geotoolkit.gml.xml.FeatureCollection)1 FeatureProperty (org.geotoolkit.gml.xml.FeatureProperty)1 WPSConvertersUtils (org.geotoolkit.wps.converters.WPSConvertersUtils)1 WPSDefaultConverter (org.geotoolkit.wps.converters.WPSDefaultConverter)1 ReferenceToFeatureCollectionConverter (org.geotoolkit.wps.converters.inputs.references.ReferenceToFeatureCollectionConverter)1