Search in sources :

Example 26 with DataStore

use of org.geotools.data.DataStore in project incubator-rya by apache.

the class GeoWaveGeoIndexer method createDataStore.

/**
 * Creates the {@link DataStore} for the {@link GeoWaveGeoIndexer}.
 * @param conf the {@link Configuration}.
 * @return the {@link DataStore}.
 */
public DataStore createDataStore(final Configuration conf) throws IOException, GeoWavePluginException {
    final Map<String, Serializable> params = getParams(conf);
    final Instance instance = ConfigUtils.getInstance(conf);
    final boolean useMock = instance instanceof MockInstance;
    final StoreFactoryFamilySpi storeFactoryFamily;
    if (useMock) {
        storeFactoryFamily = new MemoryStoreFactoryFamily();
    } else {
        storeFactoryFamily = new AccumuloStoreFactoryFamily();
    }
    final GeoWaveGTDataStoreFactory geoWaveGTDataStoreFactory = new GeoWaveGTDataStoreFactory(storeFactoryFamily);
    final DataStore dataStore = geoWaveGTDataStoreFactory.createNewDataStore(params);
    return dataStore;
}
Also used : Serializable(java.io.Serializable) StoreFactoryFamilySpi(mil.nga.giat.geowave.core.store.StoreFactoryFamilySpi) MemoryStoreFactoryFamily(mil.nga.giat.geowave.core.store.memory.MemoryStoreFactoryFamily) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) Instance(org.apache.accumulo.core.client.Instance) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) GeoWaveGTDataStoreFactory(mil.nga.giat.geowave.adapter.vector.plugin.GeoWaveGTDataStoreFactory) DataStore(org.geotools.data.DataStore) GeoWaveGTDataStore(mil.nga.giat.geowave.adapter.vector.plugin.GeoWaveGTDataStore) AccumuloDataStore(mil.nga.giat.geowave.datastore.accumulo.AccumuloDataStore) AccumuloStoreFactoryFamily(mil.nga.giat.geowave.datastore.accumulo.AccumuloStoreFactoryFamily)

Example 27 with DataStore

use of org.geotools.data.DataStore in project graphhopper by graphhopper.

the class ShapeFileReader method openShapefileDataStore.

protected DataStore openShapefileDataStore(File file) {
    try {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("url", file.toURI().toURL());
        DataStore ds = DataStoreFinder.getDataStore(map);
        if (ds == null)
            throw new IllegalArgumentException("Cannot find DataStore at " + file);
        return ds;
    } catch (Exception e) {
        throw Utils.asUnchecked(e);
    }
}
Also used : HashMap(java.util.HashMap) DataStore(org.geotools.data.DataStore)

Example 28 with DataStore

use of org.geotools.data.DataStore in project GeoGig by boundlessgeo.

the class GeoGigDataStoreFactoryTest method testDataStoreFinder.

@Test
public void testDataStoreFinder() throws Exception {
    Map<String, ? extends Serializable> params;
    DataStore dataStore;
    params = ImmutableMap.of();
    dataStore = DataStoreFinder.getDataStore(params);
    assertNull(dataStore);
    params = ImmutableMap.of(REPOSITORY.key, repoDirectory);
    dataStore = DataStoreFinder.getDataStore(params);
    assertNotNull(dataStore);
    assertTrue(dataStore instanceof GeoGigDataStore);
}
Also used : DataStore(org.geotools.data.DataStore) Test(org.junit.Test)

Example 29 with DataStore

use of org.geotools.data.DataStore in project GeoGig by boundlessgeo.

the class SLImport method runInternal.

/**
     * Executes the import command using the provided options.
     */
@Override
protected void runInternal(GeogigCLI cli) throws IOException {
    DataStore dataStore = getDataStore();
    try {
        cli.getConsole().println("Importing from database " + commonArgs.database);
        ProgressListener progressListener = cli.getProgressListener();
        cli.getGeogig().command(ImportOp.class).setAll(all).setTable(table).setAlter(alter).setOverwrite(!add).setDataStore(dataStore).setAdaptToDefaultFeatureType(!forceFeatureType).setProgressListener(progressListener).call();
        cli.getConsole().println("Import successful.");
    } catch (GeoToolsOpException e) {
        switch(e.statusCode) {
            case TABLE_NOT_DEFINED:
                throw new CommandFailedException("No tables specified for import. Specify --all or --table <table>.", e);
            case ALL_AND_TABLE_DEFINED:
                throw new CommandFailedException("Specify --all or --table <table>, both cannot be set.", e);
            case NO_FEATURES_FOUND:
                throw new CommandFailedException("No features were found in the database.", e);
            case TABLE_NOT_FOUND:
                throw new CommandFailedException("Could not find the specified table.", e);
            case UNABLE_TO_GET_NAMES:
                throw new CommandFailedException("Unable to get feature types from the database.", e);
            case UNABLE_TO_GET_FEATURES:
                throw new CommandFailedException("Unable to get features from the database.", e);
            case UNABLE_TO_INSERT:
                throw new CommandFailedException("Unable to insert features into the working tree.", e);
            case INCOMPATIBLE_FEATURE_TYPE:
                throw new CommandFailedException("The feature type of the data to import does not match the feature type of the destination tree and cannot be imported\n" + "USe the --force-featuretype switch to import using the original featuretype and crete a mixed type tree", e);
            case ALTER_AND_ALL_DEFINED:
                throw new CommandFailedException("Alter cannot be used with --all option and more than one table.", e);
            default:
                throw new CommandFailedException("Import failed with exception: " + e.statusCode.name(), e);
        }
    } finally {
        dataStore.dispose();
        cli.getConsole().flush();
    }
}
Also used : ProgressListener(org.locationtech.geogig.api.ProgressListener) DataStore(org.geotools.data.DataStore) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) GeoToolsOpException(org.locationtech.geogig.geotools.plumbing.GeoToolsOpException)

Example 30 with DataStore

use of org.geotools.data.DataStore in project GeoGig by boundlessgeo.

the class SLList method runInternal.

/**
     * Executes the list command using the provided options.
     */
@Override
protected void runInternal(GeogigCLI cli) throws IOException {
    DataStore dataStore = getDataStore();
    try {
        cli.getConsole().println("Fetching feature types...");
        Optional<List<String>> features = cli.getGeogig().command(ListOp.class).setDataStore(dataStore).call();
        if (features.isPresent()) {
            for (String featureType : features.get()) {
                cli.getConsole().println(" - " + featureType);
            }
        } else {
            throw new CommandFailedException("No features types were found in the specified database.");
        }
    } catch (GeoToolsOpException e) {
        throw new CommandFailedException("Unable to get feature types from the database.", e);
    } finally {
        dataStore.dispose();
        cli.getConsole().flush();
    }
}
Also used : DataStore(org.geotools.data.DataStore) List(java.util.List) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) GeoToolsOpException(org.locationtech.geogig.geotools.plumbing.GeoToolsOpException)

Aggregations

DataStore (org.geotools.data.DataStore)52 IOException (java.io.IOException)28 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)28 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)23 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)22 GeoToolsOpException (org.locationtech.geogig.geotools.plumbing.GeoToolsOpException)22 HashMap (java.util.HashMap)10 Map (java.util.Map)10 SimpleFeature (org.opengis.feature.simple.SimpleFeature)9 SimpleFeatureStore (org.geotools.data.simple.SimpleFeatureStore)8 Test (org.junit.Test)8 InvalidParameterException (org.locationtech.geogig.cli.InvalidParameterException)8 ExportOp (org.locationtech.geogig.geotools.plumbing.ExportOp)8 Serializable (java.io.Serializable)7 ArrayList (java.util.ArrayList)7 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)6 DataSourceInfo (com.sldeditor.datasource.impl.DataSourceInfo)6 URL (java.net.URL)6 ProgressListener (org.locationtech.geogig.api.ProgressListener)6 ListFeatureCollection (org.geotools.data.collection.ListFeatureCollection)5