Search in sources :

Example 1 with GenericNameIndex

use of org.geotoolkit.storage.feature.GenericNameIndex in project geotoolkit by Geomatys.

the class OMFeatureTypes method getFeatureTypes.

public static GenericNameIndex<FeatureType> getFeatureTypes(final String name) {
    final GenericNameIndex<FeatureType> types = new GenericNameIndex<>();
    final GenericName OM_TN_SAMPLINGPOINT = NamesExt.create(OM_NAMESPACE, name);
    final FeatureTypeBuilder featureTypeBuilder = new FeatureTypeBuilder();
    featureTypeBuilder.setName(OM_TN_SAMPLINGPOINT);
    featureTypeBuilder.setSuperTypes(GMLConvention.ABSTRACTFEATURETYPE_31);
    featureTypeBuilder.addAttribute(String.class).setName(ATT_DESC).setMinimumOccurs(0).setMaximumOccurs(1);
    featureTypeBuilder.addAttribute(String.class).setName(ATT_NAME).setMinimumOccurs(1).setMaximumOccurs(Integer.MAX_VALUE);
    featureTypeBuilder.addAttribute(String.class).setName(ATT_SAMPLED).setMinimumOccurs(0).setMaximumOccurs(Integer.MAX_VALUE).addCharacteristic(GMLConvention.NILLABLE_CHARACTERISTIC);
    featureTypeBuilder.addAttribute(Geometry.class).setName(ATT_POSITION).addRole(AttributeRole.DEFAULT_GEOMETRY);
    try {
        types.add(null, OM_TN_SAMPLINGPOINT, featureTypeBuilder.build());
    } catch (IllegalNameException ex) {
        // won't happen
        throw new FeatureStoreRuntimeException(ex);
    }
    return types;
}
Also used : FeatureType(org.opengis.feature.FeatureType) FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) GenericName(org.opengis.util.GenericName) GenericNameIndex(org.geotoolkit.storage.feature.GenericNameIndex) FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException) IllegalNameException(org.apache.sis.storage.IllegalNameException)

Example 2 with GenericNameIndex

use of org.geotoolkit.storage.feature.GenericNameIndex in project geotoolkit by Geomatys.

the class GMLSparseStore method getType.

@Override
public synchronized FeatureType getType() throws DataStoreException {
    if (featureType == null) {
        final String xsd = parameters.getValue(GMLProvider.XSD);
        final String xsdTypeName = parameters.getValue(GMLProvider.XSD_TYPE_NAME);
        catalog = new GenericNameIndex();
        if (xsd != null) {
            // read types from XSD file
            final JAXBFeatureTypeReader reader = new JAXBFeatureTypeReader();
            try {
                catalog = reader.read(new URL(xsd));
                featureType = catalog.get(xsdTypeName);
            } catch (MalformedURLException | JAXBException ex) {
                throw new DataStoreException(ex.getMessage(), ex);
            }
        } else {
            final JAXPStreamFeatureReader reader = new JAXPStreamFeatureReader();
            reader.getProperties().put(JAXPStreamFeatureReader.LONGITUDE_FIRST, longitudeFirst);
            reader.getProperties().put(JAXPStreamFeatureReader.READ_EMBEDDED_FEATURE_TYPE, true);
            try {
                if (Files.isDirectory(file)) {
                    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(file, new PosixDirectoryFilter("*.gml", true))) {
                        final Iterator<Path> gmlPaths = directoryStream.iterator();
                        // get first gml file only
                        if (gmlPaths.hasNext()) {
                            final Path gmlPath = gmlPaths.next();
                            try (FeatureReader ite = reader.readAsStream(gmlPath)) {
                                catalog = reader.getFeatureTypes();
                                featureType = ite.getFeatureType();
                            }
                        }
                    }
                } else {
                    try (FeatureReader ite = reader.readAsStream(file)) {
                        catalog = reader.getFeatureTypes();
                        featureType = ite.getFeatureType();
                    }
                }
            } catch (IOException | XMLStreamException ex) {
                throw new DataStoreException(ex.getMessage(), ex);
            } finally {
                reader.dispose();
            }
        }
    }
    return featureType;
}
Also used : Path(java.nio.file.Path) MalformedURLException(java.net.MalformedURLException) DataStoreException(org.apache.sis.storage.DataStoreException) PosixDirectoryFilter(org.geotoolkit.nio.PosixDirectoryFilter) JAXBException(javax.xml.bind.JAXBException) GenericNameIndex(org.geotoolkit.storage.feature.GenericNameIndex) IOException(java.io.IOException) URL(java.net.URL) XMLStreamException(javax.xml.stream.XMLStreamException) JAXBFeatureTypeReader(org.geotoolkit.feature.xml.jaxb.JAXBFeatureTypeReader) JAXPStreamFeatureReader(org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureReader) JAXPStreamFeatureReader(org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureReader) FeatureReader(org.geotoolkit.storage.feature.FeatureReader)

Example 3 with GenericNameIndex

use of org.geotoolkit.storage.feature.GenericNameIndex in project geotoolkit by Geomatys.

the class GMLStore method getType.

@Override
public synchronized FeatureType getType() throws DataStoreException {
    if (rootType == null) {
        final String xsd = parameters.getValue(GMLProvider.XSD);
        final String xsdTypeName = parameters.getValue(GMLProvider.XSD_TYPE_NAME);
        catalog = new GenericNameIndex();
        if (xsd != null) {
            // read types from XSD file
            final JAXBFeatureTypeReader reader = new JAXBFeatureTypeReader();
            try {
                catalog = reader.read(new URL(xsd));
                rootType = catalog.get(xsdTypeName);
            // schemaLocations.put(reader.getTargetNamespace(),xsd); needed?
            } catch (MalformedURLException | JAXBException ex) {
                throw new DataStoreException(ex.getMessage(), ex);
            }
        } else {
            final JAXPStreamFeatureReader reader = new JAXPStreamFeatureReader();
            reader.getProperties().put(JAXPStreamFeatureReader.LONGITUDE_FIRST, longitudeFirst);
            reader.getProperties().put(JAXPStreamFeatureReader.READ_EMBEDDED_FEATURE_TYPE, true);
            try (FeatureReader ite = reader.readAsStream(file)) {
                catalog = reader.getFeatureTypes();
                rootType = ite.getFeatureType();
            } catch (IOException | XMLStreamException ex) {
                throw new DataStoreException(ex.getMessage(), ex);
            } finally {
                reader.dispose();
            }
        }
        featureType = getCollectionSubType(rootType);
    }
    return featureType;
}
Also used : MalformedURLException(java.net.MalformedURLException) DataStoreException(org.apache.sis.storage.DataStoreException) JAXBException(javax.xml.bind.JAXBException) GenericNameIndex(org.geotoolkit.storage.feature.GenericNameIndex) IOException(java.io.IOException) URL(java.net.URL) XMLStreamException(javax.xml.stream.XMLStreamException) JAXBFeatureTypeReader(org.geotoolkit.feature.xml.jaxb.JAXBFeatureTypeReader) JAXPStreamFeatureReader(org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureReader) JAXPStreamFeatureReader(org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureReader) FeatureReader(org.geotoolkit.storage.feature.FeatureReader)

Aggregations

GenericNameIndex (org.geotoolkit.storage.feature.GenericNameIndex)3 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 JAXBException (javax.xml.bind.JAXBException)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 DataStoreException (org.apache.sis.storage.DataStoreException)2 JAXBFeatureTypeReader (org.geotoolkit.feature.xml.jaxb.JAXBFeatureTypeReader)2 JAXPStreamFeatureReader (org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureReader)2 FeatureReader (org.geotoolkit.storage.feature.FeatureReader)2 Path (java.nio.file.Path)1 FeatureTypeBuilder (org.apache.sis.feature.builder.FeatureTypeBuilder)1 IllegalNameException (org.apache.sis.storage.IllegalNameException)1 PosixDirectoryFilter (org.geotoolkit.nio.PosixDirectoryFilter)1 FeatureStoreRuntimeException (org.geotoolkit.storage.feature.FeatureStoreRuntimeException)1 FeatureType (org.opengis.feature.FeatureType)1 GenericName (org.opengis.util.GenericName)1