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);
}
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();
}
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);
}
}
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);
}
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);
}
Aggregations