Search in sources :

Example 1 with FeatureStore

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

the class Copy method execute.

/**
 *  {@inheritDoc }
 */
@Override
protected void execute() throws ProcessException {
    final FeatureStore sourceDS = inputParameters.getValue(SOURCE_STORE);
    final FeatureStore targetDS = inputParameters.getValue(TARGET_STORE);
    Session targetSS = inputParameters.getValue(TARGET_SESSION);
    final Boolean eraseParam = inputParameters.getValue(ERASE);
    final Boolean newVersion = inputParameters.getValue(NEW_VERSION);
    // Type name can be removed, it's embedded in the query param.
    final String typenameParam = inputParameters.getValue(TYPE_NAME);
    final Query queryParam = inputParameters.getValue(QUERY);
    final boolean doCommit = targetSS == null;
    final Session sourceSS = sourceDS.createSession(false);
    if (targetSS == null) {
        if (targetDS != null) {
            targetSS = targetDS.createSession(true);
        } else {
            throw new ProcessException("Input target_session or target_datastore missing.", this, null);
        }
    }
    boolean reBuildQuery = false;
    final String queryName;
    if (queryParam != null) {
        queryName = queryParam.getTypeName();
        reBuildQuery = true;
    } else if (typenameParam != null) {
        queryName = typenameParam;
    } else {
        queryName = "*";
    }
    final Set<GenericName> names;
    if ("*".equals(queryName)) {
        // all values
        try {
            names = sourceDS.getNames();
        } catch (DataStoreException ex) {
            throw new ProcessException(ex.getMessage(), this, ex);
        }
    } else {
        // pick only the wanted names
        names = new HashSet<>();
        final List<String> wanted = UnmodifiableArrayList.wrap(queryName.split(","));
        for (String s : wanted) {
            try {
                final FeatureType type = sourceDS.getFeatureType(s);
                names.add(type.getName());
            } catch (DataStoreException ex) {
                throw new ProcessException(ex.getMessage(), this, ex);
            }
        }
    }
    final float size = names.size();
    int inc = 0;
    for (GenericName n : names) {
        fireProgressing("Copying " + n + ".", (int) ((inc * 100f) / size), false);
        try {
            Query query;
            if (reBuildQuery) {
                Query builder = new Query();
                builder.copy(queryParam);
                builder.setTypeName(n);
                query = builder;
            } else {
                query = queryParam != null ? queryParam : new Query(n);
            }
            insert(n, sourceSS, targetSS, query, eraseParam, newVersion);
        } catch (DataStoreException ex) {
            throw new ProcessException(ex.getMessage(), this, ex);
        }
        inc++;
    }
    try {
        Date lastVersionDate = null;
        if (doCommit) {
            LOGGER.log(Level.INFO, "Commit all changes");
            targetSS.commit();
            // find last version
            for (GenericName n : names) {
                if (targetSS.getFeatureStore().getQueryCapabilities().handleVersioning()) {
                    final List<Version> versions = targetSS.getFeatureStore().getVersioning(n.toString()).list();
                    if (!versions.isEmpty()) {
                        if (lastVersionDate == null || versions.get(versions.size() - 1).getDate().getTime() > lastVersionDate.getTime()) {
                            lastVersionDate = versions.get(versions.size() - 1).getDate();
                        }
                    }
                }
            }
        }
        if (lastVersionDate != null) {
            outputParameters.getOrCreate(VERSION).setValue(lastVersionDate);
        }
    } catch (DataStoreException ex) {
        throw new ProcessException(ex.getMessage(), this, ex);
    } catch (VersioningException ex) {
        throw new ProcessException(ex.getMessage(), this, ex);
    }
}
Also used : FeatureType(org.opengis.feature.FeatureType) DataStoreException(org.apache.sis.storage.DataStoreException) Query(org.geotoolkit.storage.feature.query.Query) Date(java.util.Date) ProcessException(org.geotoolkit.process.ProcessException) GenericName(org.opengis.util.GenericName) Version(org.geotoolkit.version.Version) VersioningException(org.geotoolkit.version.VersioningException) FeatureStore(org.geotoolkit.storage.feature.FeatureStore) Session(org.geotoolkit.storage.feature.session.Session)

Example 2 with FeatureStore

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

the class AbstractWritingTests method testDataStore.

@Test
public void testDataStore() {
    final FeatureStore store = getDataStore();
    assertNotNull(store);
}
Also used : FeatureStore(org.geotoolkit.storage.feature.FeatureStore) Test(org.junit.Test)

Example 3 with FeatureStore

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

the class GPXDemo method main.

public static void main(String[] args) throws DataStoreException, URISyntaxException {
    Demos.init();
    final Map<String, Serializable> parameters = new HashMap<String, Serializable>();
    parameters.put("path", GPXDemo.class.getResource("/data/sampleGPX.gpx").toURI());
    final FeatureStore store = (FeatureStore) DataStores.open(parameters);
    System.out.println("=================== Feature types ====================");
    final Set<GenericName> names = store.getNames();
    for (GenericName name : names) {
        System.out.println(store.getFeatureType(name.toString()));
    }
}
Also used : Serializable(java.io.Serializable) GenericName(org.opengis.util.GenericName) HashMap(java.util.HashMap) FeatureStore(org.geotoolkit.storage.feature.FeatureStore)

Example 4 with FeatureStore

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

the class OSMDemo method main.

public static void main(String[] args) throws DataStoreException, URISyntaxException {
    Demos.init();
    final Map<String, Serializable> parameters = new HashMap<String, Serializable>();
    parameters.put("path", OSMDemo.class.getResource("/data/sampleOSM.osm").toURI());
    final FeatureStore store = (FeatureStore) DataStores.open(parameters);
    System.out.println("=================== Feature types ====================");
    final Set<GenericName> names = store.getNames();
    for (GenericName name : names) {
        System.out.println(store.getFeatureType(name.toString()));
    }
}
Also used : Serializable(java.io.Serializable) GenericName(org.opengis.util.GenericName) HashMap(java.util.HashMap) FeatureStore(org.geotoolkit.storage.feature.FeatureStore)

Example 5 with FeatureStore

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

the class DefaultFolderFeatureStore method createFeatureType.

/**
 * {@inheritDoc}
 */
@Override
public void createFeatureType(final FeatureType featureType) throws DataStoreException {
    final GenericName typeName = featureType.getName();
    if (getNames().contains(typeName)) {
        throw new DataStoreException("Type name " + typeName + " already exists.");
    }
    final Parameters params = singleFileDefaultParameters.clone();
    try {
        final Path folder = getFolder(folderParameters);
        final String fileName = typeName.tip().toString() + "." + singleFileFactory.getSuffix().iterator().next();
        final Path newFile = folder.resolve(fileName);
        params.getOrCreate(ShapefileProvider.PATH).setValue(newFile.toUri().toURL());
    } catch (MalformedURLException ex) {
        throw new DataStoreException(ex);
    }
    final FeatureStore store = (FeatureStore) singleFileFactory.create(params);
    store.addListener(StoreEvent.class, subListener);
    store.createFeatureType(featureType);
    stores.add(this, typeName, store);
}
Also used : GenericName(org.opengis.util.GenericName) DataStoreException(org.apache.sis.storage.DataStoreException) MalformedURLException(java.net.MalformedURLException) Parameters(org.apache.sis.parameter.Parameters) 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