Package org.geotools.data

Examples of org.geotools.data.DataStore


        connection.commit();
        ds.dispose();
    }

    private long count(PostGisConfig cfg, String table) throws PostGisException, IOException, SQLException {
        DataStore ds_ = PostGISUtils.createDatastore(cfg);
        assertTrue(ds_ instanceof JDBCDataStore);
       
        JDBCDataStore ds= (JDBCDataStore) ds_;

        Connection connection = ds.getConnection(Transaction.AUTO_COMMIT);
View Full Code Here


            try {
                schema = DataUtilities.createType(name, spec);
            } catch (SchemaException e) {
                throw new IOException(e);
            }
            DataStore dataStore = (DataStore) parent.store.getDataStore(null);
            dataStore.createSchema(schema);

            FeatureWriter<SimpleFeatureType, SimpleFeature> w =
                dataStore.getFeatureWriterAppend(name, Transaction.AUTO_COMMIT);
            for (Map<String,Object> map : data) {
                SimpleFeature f = w.next();
                for (Map.Entry<String,Object> kvp : map.entrySet()) {
                    f.setAttribute(kvp.getKey(), kvp.getValue());
                }

                w.write();
            }
            w.close();

            CatalogBuilder builder = builder();
            builder.setStore(parent.store);

            FeatureSource<?,?> source = dataStore.getFeatureSource(name);
            featureType = builder.buildFeatureType(source);
            builder.setupBounds(featureType, source);

            catalog.add(featureType);
View Full Code Here

        // if (!commonArgs.geometryMetadataTable.equals(""))
        // params.put(OracleNGDataStoreFactory.GEOMETRY_METADATA_TABLE.key,
        // commonArgs.geometryMetadataTable);
        // params.put(OracleNGDataStoreFactory.FETCHSIZE.key, 1000);

        DataStore dataStore;
        try {
            dataStore = dataStoreFactory.createDataStore(params);
        } catch (IOException e) {
            throw new CommandFailedException(
                    "Unable to connect using the specified database parameters.", e);
View Full Code Here

    /**
     * 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();
        }
    }
View Full Code Here

     * @see org.locationtech.geogig.geotools.cli.porcelain.AbstractOracleCommand#runInternal(org.locationtech.geogig.cli.GeogigCLI)
     */
    @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.");
        } finally {
            dataStore.dispose();
            cli.getConsole().flush();
        }
    }
View Full Code Here

        String path = args.get(0);
        String tableName = args.get(1);

        checkParameter(tableName != null && !tableName.isEmpty(), "No table name specified");

        DataStore dataStore = getDataStore();

        ObjectId featureTypeId = null;
        if (!Arrays.asList(dataStore.getTypeNames()).contains(tableName)) {
            SimpleFeatureType outputFeatureType;
            if (sFeatureTypeId != null) {
                // Check the feature type id string is a correct id
                Optional<ObjectId> id = cli.getGeogig().command(RevParse.class)
                        .setRefSpec(sFeatureTypeId).call();
                checkParameter(id.isPresent(), "Invalid feature type reference", sFeatureTypeId);
                TYPE type = cli.getGeogig().command(ResolveObjectType.class).setObjectId(id.get())
                        .call();
                checkParameter(type.equals(TYPE.FEATURETYPE),
                        "Provided reference does not resolve to a feature type: ", sFeatureTypeId);
                outputFeatureType = (SimpleFeatureType) cli.getGeogig()
                        .command(RevObjectParse.class).setObjectId(id.get())
                        .call(RevFeatureType.class).get().type();
                featureTypeId = id.get();
            } else {
                try {
                    SimpleFeatureType sft = getFeatureType(path, cli);
                    outputFeatureType = new SimpleFeatureTypeImpl(new NameImpl(tableName),
                            sft.getAttributeDescriptors(), sft.getGeometryDescriptor(),
                            sft.isAbstract(), sft.getRestrictions(), sft.getSuper(),
                            sft.getDescription());
                } catch (GeoToolsOpException e) {
                    throw new CommandFailedException("No features to export.", e);
                }
            }
            try {
                dataStore.createSchema(outputFeatureType);
            } catch (IOException e) {
                throw new CommandFailedException("Cannot create new table in database", e);
            }
        } else {
            if (!overwrite) {
                throw new CommandFailedException(
                        "The selected table already exists. Use -o to overwrite");
            }
        }

        SimpleFeatureSource featureSource = dataStore.getFeatureSource(tableName);
        if (!(featureSource instanceof SimpleFeatureStore)) {
            throw new CommandFailedException("Can't write to the selected table");
        }
        SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
        if (overwrite) {
View Full Code Here

                }

            };
            SimpleFeatureType outputFeatureType = rule.getFeatureType();
            String path = getOriginTreesFromOutputFeatureType(outputFeatureType);
            DataStore dataStore = null;
            try {
                dataStore = getDataStore();

                String tableName = outputFeatureType.getName().getLocalPart();
                if (Arrays.asList(dataStore.getTypeNames()).contains(tableName)) {
                    if (!overwrite) {
                        throw new CommandFailedException("A table named '" + tableName
                                + "'already exists. Use -o to overwrite");
                    }
                } else {
                    try {
                        dataStore.createSchema(outputFeatureType);
                    } catch (IOException e) {
                        throw new CommandFailedException("Cannot create new table in database", e);
                    }
                }

                final SimpleFeatureSource featureSource = dataStore.getFeatureSource(tableName);
                if (!(featureSource instanceof SimpleFeatureStore)) {
                    throw new CommandFailedException(
                            "Could not create feature store. Data source is read only.");
                }
                final SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
                if (overwrite) {
                    featureStore.removeFeatures(Filter.INCLUDE);
                }
                ExportOp op = cli.getGeogig().command(ExportOp.class).setFeatureStore(featureStore)
                        .setPath(path).setFeatureTypeConversionFunction(function);
                try {
                    op.setProgressListener(cli.getProgressListener()).call();
                    cli.getConsole().println("OSM data exported successfully to " + tableName);
                } catch (IllegalArgumentException iae) {
                    throw new org.locationtech.geogig.cli.InvalidParameterException(iae.getMessage(), iae);
                } catch (GeoToolsOpException e) {
                    throw new CommandFailedException("Could not export. Error:"
                            + e.statusCode.name(), e);
                }
            } catch (IOException e) {
                throw new IllegalStateException("Cannot connect to database: " + e.getMessage(), e);
            } finally {
                if (dataStore != null) {
                    dataStore.dispose();
                }
            }
        }
    }
View Full Code Here

    /**
     * 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)
                    .setDestinationPath(destTable).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 ALTER_AND_ALL_DEFINED:
                throw new CommandFailedException(
                        "Alter cannot be used with --all option and more than one table.", 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);
            default:
                throw new CommandFailedException("Import failed with exception: "
                        + e.statusCode.name(), e);
            }
        } finally {
            dataStore.dispose();
            cli.getConsole().flush();
        }
    }
View Full Code Here

     * 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)
                    .setDestinationPath(destTable).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 ALTER_AND_ALL_DEFINED:
                throw new CommandFailedException(
                        "Alter cannot be used with --all option and more than one table.", 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);
            default:
                throw new CommandFailedException("Import failed with exception: "
                        + e.statusCode.name(), e);
            }
        } finally {
            dataStore.dispose();
            cli.getConsole().flush();
        }
    }
View Full Code Here

     * 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.");
        } finally {
            dataStore.dispose();
            cli.getConsole().flush();
        }
    }
View Full Code Here

TOP

Related Classes of org.geotools.data.DataStore

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.