Search in sources :

Example 21 with FeatureStore

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

the class ShapefileDemo method main.

public static void main(String[] args) throws DataStoreException, URISyntaxException {
    Demos.init();
    // create using a Parameters object--------------------------------------
    System.out.println(ShapefileProvider.PARAMETERS_DESCRIPTOR);
    final ParameterValueGroup parameters = ShapefileProvider.PARAMETERS_DESCRIPTOR.createValue();
    parameters.parameter(ShapefileProvider.PATH.getName().getCode()).setValue(ShapefileDemo.class.getResource("/data/world/Countries.shp").toURI());
    final FeatureStore store1 = (FeatureStore) DataStores.open(parameters);
    // create using a Map----------------------------------------------------
    final Map<String, Serializable> map = new HashMap<String, Serializable>();
    map.put("path", ShapefileDemo.class.getResource("/data/world/Countries.shp").toURI());
    final FeatureStore store2 = (FeatureStore) DataStores.open(map);
}
Also used : Serializable(java.io.Serializable) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) HashMap(java.util.HashMap) FeatureStore(org.geotoolkit.storage.feature.FeatureStore)

Example 22 with FeatureStore

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

the class FeatureCopyDemo method main.

public static void main(String[] args) throws Exception {
    final ParameterValueGroup shpParams = ShapefileProvider.PARAMETERS_DESCRIPTOR.createValue();
    shpParams.parameter("path").setValue(URI.create("file:/...someshapefile"));
    final FeatureStore source = (FeatureStore) DataStores.open(shpParams);
    final ParameterValueGroup pgParams = PostgresProvider.PARAMETERS_DESCRIPTOR.createValue();
    pgParams.parameter("host").setValue("host");
    pgParams.parameter("port").setValue(5432);
    pgParams.parameter("database").setValue("database");
    pgParams.parameter("user").setValue("user");
    pgParams.parameter("password").setValue("secret");
    final FeatureStore target = (FeatureStore) DataStores.open(pgParams);
    final ParameterValueGroup copyParams = CopyDescriptor.INPUT_DESC.createValue();
    copyParams.parameter("source_datastore").setValue(source);
    copyParams.parameter("target_datastore").setValue(target);
    final Process process = CopyDescriptor.INSTANCE.createProcess(copyParams);
    process.call();
}
Also used : ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) Process(org.geotoolkit.process.Process) FeatureStore(org.geotoolkit.storage.feature.FeatureStore)

Example 23 with FeatureStore

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

the class StringToFeatureCollectionConverter method apply.

@Override
public FeatureCollection apply(final String s) throws UnconvertibleObjectException {
    if (s == null)
        throw new UnconvertibleObjectException("Empty FeatureCollection");
    try {
        String url;
        if (s.startsWith("file:")) {
            url = s;
        } else {
            url = "file:" + s;
        }
        final Map<String, Serializable> parameters = new HashMap<String, Serializable>();
        parameters.put(DataStoreProvider.LOCATION, URI.create(url));
        final FeatureStore store = (FeatureStore) DataStores.open(parameters);
        if (store == null) {
            throw new UnconvertibleObjectException("Invalid URL");
        }
        if (store.getNames().size() != 1) {
            throw new UnconvertibleObjectException("More than one FeatureCollection in the file");
        }
        final FeatureCollection collection = store.createSession(true).getFeatureCollection(new Query(store.getNames().iterator().next()));
        if (collection != null) {
            return collection;
        } else {
            throw new UnconvertibleObjectException("Collection not found");
        }
    } catch (DataStoreException ex) {
        throw new UnconvertibleObjectException(ex);
    }
}
Also used : UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) Serializable(java.io.Serializable) DataStoreException(org.apache.sis.storage.DataStoreException) Query(org.geotoolkit.storage.feature.query.Query) HashMap(java.util.HashMap) FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection) FeatureStore(org.geotoolkit.storage.feature.FeatureStore)

Example 24 with FeatureStore

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

the class DefaultFolderFeatureStore method removeFeatures.

/**
 * {@inheritDoc}
 */
@Override
public void removeFeatures(final String groupName, final Filter filter) throws DataStoreException {
    typeCheck(groupName);
    final FeatureStore store = stores.get(this, groupName);
    store.removeFeatures(groupName, filter);
}
Also used : FeatureStore(org.geotoolkit.storage.feature.FeatureStore) AbstractFeatureStore(org.geotoolkit.storage.feature.AbstractFeatureStore)

Example 25 with FeatureStore

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

the class DefaultFolderFeatureStore method addFeatures.

/**
 * {@inheritDoc}
 */
@Override
public List<ResourceId> addFeatures(final String groupName, final Collection<? extends Feature> newFeatures, final Hints hints) throws DataStoreException {
    typeCheck(groupName);
    final FeatureStore store = stores.get(this, groupName);
    return store.addFeatures(groupName, newFeatures);
}
Also used : FeatureStore(org.geotoolkit.storage.feature.FeatureStore) AbstractFeatureStore(org.geotoolkit.storage.feature.AbstractFeatureStore)

Aggregations

FeatureStore (org.geotoolkit.storage.feature.FeatureStore)28 GenericName (org.opengis.util.GenericName)11 AbstractFeatureStore (org.geotoolkit.storage.feature.AbstractFeatureStore)10 Query (org.geotoolkit.storage.feature.query.Query)9 DataStoreException (org.apache.sis.storage.DataStoreException)8 FeatureCollection (org.geotoolkit.storage.feature.FeatureCollection)6 Test (org.junit.Test)6 FeatureType (org.opengis.feature.FeatureType)6 Session (org.geotoolkit.storage.feature.session.Session)5 Serializable (java.io.Serializable)4 HashMap (java.util.HashMap)4 FeatureTypeBuilder (org.apache.sis.feature.builder.FeatureTypeBuilder)3 Parameters (org.apache.sis.parameter.Parameters)3 ShapefileProvider (org.geotoolkit.data.shapefile.ShapefileProvider)3 Feature (org.opengis.feature.Feature)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 MapLayer (org.apache.sis.portrayal.MapLayer)2 MapLayers (org.apache.sis.portrayal.MapLayers)2