Search in sources :

Example 1 with JAXPStreamFeatureReader

use of org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureReader in project geotoolkit by Geomatys.

the class XmlFeatureTest method testReadSimpleFeatureOldEnc.

@Test
public void testReadSimpleFeatureOldEnc() throws JAXBException, IOException, XMLStreamException {
    final XmlFeatureReader readerGml = new JAXPStreamFeatureReader(simpleTypeFull);
    readerGml.getProperties().put(JAXPStreamFeatureReader.BINDING_PACKAGE, "GML");
    Object obj = readerGml.read(XmlFeatureTest.class.getResourceAsStream("/org/geotoolkit/feature/xml/SimpleFeatureOldEnc.xml"));
    assertTrue(obj instanceof Feature);
    Feature result = (Feature) obj;
    assertEquals(simpleFeatureFull, result);
    obj = readerGml.read(XmlFeatureTest.class.getResourceAsStream("/org/geotoolkit/feature/xml/SimpleFeatureOldEnc2.xml"));
    assertTrue(obj instanceof Feature);
    result = (Feature) obj;
    assertEquals(simpleFeatureFull, result);
    // adding lineString encoding
    obj = readerGml.read(XmlFeatureTest.class.getResourceAsStream("/org/geotoolkit/feature/xml/SimpleFeatureOldEnc3.xml"));
    readerGml.dispose();
    assertTrue(obj instanceof Feature);
    result = (Feature) obj;
    assertEquals(simpleFeatureFull, result);
    /*
         * Not working with JTSWrapper binding mode for JAXP Feature Writer
         *
         * working for Polygon
         * working for LineString
         * not for point
         */
    final XmlFeatureReader reader = new JAXPStreamFeatureReader(simpleTypeFull);
    reader.getProperties().put(JAXPStreamFeatureReader.BINDING_PACKAGE, "JTSWrapper");
    obj = reader.read(XmlFeatureTest.class.getResourceAsStream("/org/geotoolkit/feature/xml/SimpleFeatureOldEnc.xml"));
    assertTrue(obj instanceof Feature);
    result = (Feature) obj;
    assertEquals(simpleFeatureFull, result);
    // adding lineString encoding
    obj = reader.read(XmlFeatureTest.class.getResourceAsStream("/org/geotoolkit/feature/xml/SimpleFeatureOldEnc2.xml"));
    assertTrue(obj instanceof Feature);
    result = (Feature) obj;
    assertEquals(simpleFeatureFull, result);
    // adding lineString encoding
    obj = reader.read(XmlFeatureTest.class.getResourceAsStream("/org/geotoolkit/feature/xml/SimpleFeatureOldEnc3.xml"));
    reader.dispose();
    assertTrue(obj instanceof Feature);
    result = (Feature) obj;
    assertFalse(simpleFeatureFull.equals(result));
}
Also used : JAXPStreamFeatureReader(org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureReader) Feature(org.opengis.feature.Feature)

Example 2 with JAXPStreamFeatureReader

use of org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureReader in project geotoolkit by Geomatys.

the class XmlFeatureTest method testReadSimpleCollectionEmbeddedFT.

@Ignore
@Test
public void testReadSimpleCollectionEmbeddedFT() throws JAXBException, IOException, XMLStreamException {
    // verify that distant service is working properly
    URL url = new URL("http://www.ifremer.fr/services/wfs1?SERVICE=WFS&VERSION=1.1.0&REQUEST=DescribeFeatureType&TYPENAME=quadrige&OUTPUTFORMAT=text/xml;%20subtype=%22gml/3.1.1%22");
    final String response = getStringResponse(url.openConnection());
    if (response.contains("<!-- ERROR: Failed opening layer (null) -->")) {
        Logger.getLogger("org.geotoolkit.feature.xml").warning("Skipping embedded test. external service not responding correctly");
        return;
    }
    JAXPStreamFeatureReader reader = new JAXPStreamFeatureReader();
    reader.getProperties().put(JAXPStreamFeatureReader.READ_EMBEDDED_FEATURE_TYPE, true);
    Object obj = reader.read(XmlFeatureTest.class.getResourceAsStream("/org/geotoolkit/feature/xml/featureCollectionEmbedFT.xml"));
    reader.dispose();
    assertTrue(obj instanceof FeatureSet);
    reader = new JAXPStreamFeatureReader();
    reader.getProperties().put(JAXPStreamFeatureReader.READ_EMBEDDED_FEATURE_TYPE, true);
    obj = reader.read(XmlFeatureTest.class.getResourceAsStream("/org/geotoolkit/feature/xml/featureCollectionEmbedFT2.xml"));
    reader.dispose();
    assertTrue(obj instanceof FeatureSet);
    obj = reader.read(XmlFeatureTest.class.getResourceAsStream("/org/geotoolkit/feature/xml/featureCollectionEmbedFT3.xml"));
    reader.dispose();
    assertTrue(obj instanceof FeatureSet);
}
Also used : JAXPStreamFeatureReader(org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureReader) InMemoryFeatureSet(org.geotoolkit.storage.memory.InMemoryFeatureSet) FeatureSet(org.apache.sis.storage.FeatureSet) URL(java.net.URL)

Example 3 with JAXPStreamFeatureReader

use of org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureReader in project geotoolkit by Geomatys.

the class XmlFeatureTest method testReadSimpleFeatureWithAtts.

@Test
public void testReadSimpleFeatureWithAtts() throws JAXBException, IOException, XMLStreamException {
    final XmlFeatureReader reader = new JAXPStreamFeatureReader(typeWithAtts);
    Object obj = reader.read(XmlFeatureTest.class.getResourceAsStream("/org/geotoolkit/feature/xml/SimpleFeatureWithAttribute.xml"));
    reader.dispose();
    assertTrue(obj instanceof Feature);
    Feature result = (Feature) obj;
    assertEquals(featureWithAttributes, result);
}
Also used : JAXPStreamFeatureReader(org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureReader) Feature(org.opengis.feature.Feature)

Example 4 with JAXPStreamFeatureReader

use of org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureReader in project geotoolkit by Geomatys.

the class XmlFeatureTest method testReadSimpleCollection.

@Test
public void testReadSimpleCollection() throws JAXBException, IOException, XMLStreamException, DataStoreException {
    final XmlFeatureReader reader = new JAXPStreamFeatureReader(simpleTypeBasic);
    final Object obj = reader.read(XmlFeatureTest.class.getResourceAsStream("/org/geotoolkit/feature/xml/CollectionSimple.xml"));
    reader.dispose();
    assertTrue(obj instanceof FeatureSet);
    FeatureSet result = (FeatureSet) obj;
    assertEquals(FeatureStoreUtilities.getCount(collectionSimple), FeatureStoreUtilities.getCount(result));
    assertEquals(collectionSimple.getIdentifier().get().toString(), result.getIdentifier().get().toString());
    assertEquals(collectionSimple.getType(), result.getType());
    try {
        FeatureQuery query = new FeatureQuery();
        query.setSortBy(FF.sort(FF.property("attDouble"), SortOrder.ASCENDING));
        result = result.subset(query);
    } catch (DataStoreException ex) {
        Logger.getLogger("org.geotoolkit.feature.xml").log(Level.SEVERE, null, ex);
    }
    try (Stream<Feature> resultS = result.features(false);
        Stream<Feature> expectedS = collectionSimple.features(false)) {
        Iterator<Feature> resultIte = resultS.iterator();
        Iterator<Feature> expectedIte = expectedS.iterator();
        assertEquals(resultIte.next(), expectedIte.next());
        assertEquals(resultIte.next(), expectedIte.next());
        assertEquals(resultIte.next(), expectedIte.next());
    }
}
Also used : DataStoreException(org.apache.sis.storage.DataStoreException) JAXPStreamFeatureReader(org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureReader) InMemoryFeatureSet(org.geotoolkit.storage.memory.InMemoryFeatureSet) FeatureSet(org.apache.sis.storage.FeatureSet) FeatureQuery(org.apache.sis.storage.FeatureQuery) Feature(org.opengis.feature.Feature)

Example 5 with JAXPStreamFeatureReader

use of org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureReader in project geotoolkit by Geomatys.

the class WPSIO method getFeatureReader.

/**
 * Get the JAXPStreamFeatureReader to read feature. If there is a schema
 * defined, the JAXPStreamFeatureReader will use it. Otherwise it will try
 * to read it when reading data.
 *
 * @param schema location of the feature type definition.
 * @return
 * @throws MalformedURLException If given schema cannot be translated in a
 * propert URL.
 */
public static XmlFeatureReader getFeatureReader(String schema) throws MalformedURLException {
    final Collection<FeatureType> schemaTypes;
    if (schema == null || (schema = schema.trim()).isEmpty()) {
        schemaTypes = Collections.EMPTY_LIST;
    } else {
        Collection<FeatureType> types = null;
        try {
            final JAXBFeatureTypeReader xsdReader = new JAXBFeatureTypeReader();
            final URL schemaURL = new URL(URLDecoder.decode(schema, StandardCharsets.UTF_8.name()));
            types = xsdReader.read(schemaURL).getValues();
        } catch (JAXBException | UnsupportedEncodingException ex) {
            LOGGER.log(Level.FINE, "Cannot read schema at location " + schema, ex);
        }
        schemaTypes = types;
    }
    final JAXPStreamFeatureReader featureReader;
    if (schemaTypes == null || schemaTypes.isEmpty()) {
        featureReader = new JAXPStreamFeatureReader();
        featureReader.getProperties().put(JAXPStreamFeatureReader.READ_EMBEDDED_FEATURE_TYPE, true);
    } else {
        featureReader = new JAXPStreamFeatureReader(schemaTypes);
    }
    return featureReader;
}
Also used : FeatureType(org.opengis.feature.FeatureType) JAXBException(javax.xml.bind.JAXBException) JAXBFeatureTypeReader(org.geotoolkit.feature.xml.jaxb.JAXBFeatureTypeReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JAXPStreamFeatureReader(org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureReader) URL(java.net.URL)

Aggregations

JAXPStreamFeatureReader (org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureReader)13 Feature (org.opengis.feature.Feature)9 URL (java.net.URL)5 DataStoreException (org.apache.sis.storage.DataStoreException)5 IOException (java.io.IOException)4 JAXBException (javax.xml.bind.JAXBException)4 XMLStreamException (javax.xml.stream.XMLStreamException)4 FeatureSet (org.apache.sis.storage.FeatureSet)4 JAXBFeatureTypeReader (org.geotoolkit.feature.xml.jaxb.JAXBFeatureTypeReader)4 InMemoryFeatureSet (org.geotoolkit.storage.memory.InMemoryFeatureSet)4 MalformedURLException (java.net.MalformedURLException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 FeatureReader (org.geotoolkit.storage.feature.FeatureReader)2 GenericNameIndex (org.geotoolkit.storage.feature.GenericNameIndex)2 FeatureType (org.opengis.feature.FeatureType)2 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Path (java.nio.file.Path)1 AbstractMap (java.util.AbstractMap)1