Examples of SimpleFeatureStore


Examples of org.geotools.data.simple.SimpleFeatureStore

                for (AttributeDescriptor attr : sourceFC.getAttributeDescriptors()) {
                    LOGGER.debug( " Attr: "+attr);
                }
            }
            dstDs.createSchema(sft);
            SimpleFeatureStore fsLayer = (SimpleFeatureStore)dstDs.getFeatureSource(layer);
            SimpleFeatureType dstSft = dstDs.getFeatureSource(layer).getSchema();

            if ( LOGGER.isInfoEnabled() ) {
                for (PropertyDescriptor pd : dstSft.getDescriptors()) {
                    LOGGER.info("Attribute : " + pd.getName() + " " + pd.getType());
View Full Code Here

Examples of org.geotools.data.simple.SimpleFeatureStore

          }
 
          LOGGER.debug("Filter: " + filter);

            // try to look for the destination table
            SimpleFeatureStore store = (SimpleFeatureStore) ds.getFeatureSource(layer);
            store.removeFeatures(filter);
            tx.commit();
        } catch (Exception e) {
            quietRollbackTransaction(tx);
            LOGGER.error("An exception was raised when deleting features from " + layer + "", e);
            throw new PostGisException("An exception was raised when deleting features from " + layer, e);
View Full Code Here

Examples of org.geotools.data.simple.SimpleFeatureStore

        } catch (Exception e) {
            LOGGER.error("Destination layer " +layer + " does not exist:" + e.getMessage(), e);
            throw new PostGisException("Destination layer " +layer + " does not exist:" + e.getMessage(), e);
        }

        final SimpleFeatureStore featureStoreData = (SimpleFeatureStore) fsDestLayer;
        SimpleFeatureIterator iterator = null;
        final Transaction tx = new DefaultTransaction();
        featureStoreData.setTransaction(tx);
        // update the layer store with the new SimpleFeature coming from the shape file
        // data are saved itemsForPage elements at time
       
        try {
         
          // open iterator
            iterator = sourceFC.features();
          // prepare feature holder
          final ListFeatureCollection lfc= new ListFeatureCollection(sourceFC.getSchema());
          int count=0;
          int numPag = sourceFC.size() / ITEM_X_PAGE;
          int currentPage = 0;
          LOGGER.info("Page size: " + ITEM_X_PAGE + ", Page amount: " + numPag);
          while (iterator.hasNext()) {

              // copy over
               final SimpleFeature sf = iterator.next();
               lfc.add(sf);
//               LOGGER.debug("Feature " + count + " - page: " + currentPage);
               // paging check
               if(count++>=ITEM_X_PAGE){
                 // commit to relief load from destination DB
                   featureStoreData.addFeatures(lfc);                      
                   tx.commit();
                   lfc.clear();
                   count=0;
//                   System.gc();
                   LOGGER.debug("Page" + currentPage++ + "/" + numPag + " committed... ");

               }
            }
          LOGGER.info("Commit latest features...");
            if(!lfc.isEmpty()){
            // commit to relief load from destination DB
              featureStoreData.addFeatures(lfc);
            
              // final commit
              tx.commit();   
            }
        } catch (Exception e) {
View Full Code Here

Examples of org.geotools.data.simple.SimpleFeatureStore

        builder.setCRS(pointsType.getCoordinateReferenceSystem());
        SimpleFeatureType outputFeatureType = builder.buildFeatureType();
        MemoryDataStore dataStore = new MemoryDataStore(outputFeatureType);
        final String typeName = dataStore.getTypeNames()[0];
        SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);
        SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
        geogig.command(ExportDiffOp.class).setFeatureStore(featureStore).setPath(pointsName)
                .setNewRef(changeCommit.getId().toString())
                .setOldRef(insertCommit.getId().toString()).call();
        featureSource = dataStore.getFeatureSource(typeName);
        featureStore = (SimpleFeatureStore) featureSource;
        SimpleFeatureCollection featureCollection = featureStore.getFeatures();
        assertEquals(featureCollection.size(), points.length);
        SimpleFeatureIterator features = featureCollection.features();
        assertTrue(collectionsAreEqual(features, points));
    }
View Full Code Here

Examples of org.geotools.data.simple.SimpleFeatureStore

        builder.setCRS(pointsType.getCoordinateReferenceSystem());
        SimpleFeatureType outputFeatureType = builder.buildFeatureType();
        MemoryDataStore dataStore = new MemoryDataStore(outputFeatureType);
        final String typeName = dataStore.getTypeNames()[0];
        SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);
        SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
        geogig.command(ExportDiffOp.class).setFeatureStore(featureStore).setPath(pointsName)
                .setNewRef(changeCommit.getId().toString())
                .setOldRef(insertCommit.getId().toString()).setUseOld(true).call();
        featureSource = dataStore.getFeatureSource(typeName);
        featureStore = (SimpleFeatureStore) featureSource;
        SimpleFeatureCollection featureCollection = featureStore.getFeatures();
        assertEquals(featureCollection.size(), points.length);
        SimpleFeatureIterator features = featureCollection.features();
        assertTrue(collectionsAreEqual(features, points));
    }
View Full Code Here

Examples of org.geotools.data.simple.SimpleFeatureStore

            RevObject filterType = database.getIfPresent(filterFeatureTypeId);
            checkArgument(filterType instanceof RevFeatureType,
                    "Provided filter feature type is does not exist");
        }

        final SimpleFeatureStore targetStore = getTargetStore();

        final String refspec = resolveRefSpec();
        final String treePath = refspec.substring(refspec.indexOf(':') + 1);
        final RevTree rootTree = resolveRootTree(refspec);
        final NodeRef typeTreeRef = resolTypeTreeRef(refspec, treePath, rootTree);

        final ObjectId defaultMetadataId = typeTreeRef.getMetadataId();

        final RevTree typeTree = database.getTree(typeTreeRef.objectId());

        final ProgressListener progressListener = getProgressListener();

        progressListener.started();
        progressListener.setDescription("Exporting from " + path + " to "
                + targetStore.getName().getLocalPart() + "... ");

        FeatureCollection<SimpleFeatureType, SimpleFeature> asFeatureCollection = new BaseFeatureCollection<SimpleFeatureType, SimpleFeature>() {

            @Override
            public FeatureIterator<SimpleFeature> features() {

                final Iterator<SimpleFeature> plainFeatures = getFeatures(typeTree, database,
                        defaultMetadataId, progressListener);

                Iterator<SimpleFeature> adaptedFeatures = adaptToArguments(plainFeatures,
                        defaultMetadataId);

                Iterator<Optional<Feature>> transformed = Iterators.transform(adaptedFeatures,
                        ExportOp.this.function);

                Iterator<SimpleFeature> filtered = Iterators.filter(Iterators.transform(
                        transformed, new Function<Optional<Feature>, SimpleFeature>() {
                            @Override
                            public SimpleFeature apply(Optional<Feature> input) {
                                return (SimpleFeature) (input.isPresent() ? input.get() : null);
                            }
                        }), Predicates.notNull());

                return new DelegateFeatureIterator<SimpleFeature>(filtered);
            }
        };

        // add the feature collection to the feature store
        final Transaction transaction;
        if (transactional) {
            transaction = new DefaultTransaction("create");
        } else {
            transaction = Transaction.AUTO_COMMIT;
        }
        try {
            targetStore.setTransaction(transaction);
            try {
                targetStore.addFeatures(asFeatureCollection);
                transaction.commit();
            } catch (final Exception e) {
                if (transactional) {
                    transaction.rollback();
                }
View Full Code Here

Examples of org.geotools.data.simple.SimpleFeatureStore

        }
        return refspec;
    }

    private SimpleFeatureStore getTargetStore() {
        SimpleFeatureStore targetStore;
        try {
            targetStore = targetStoreProvider.get();
        } catch (Exception e) {
            throw new GeoToolsOpException(StatusCode.CANNOT_CREATE_FEATURESTORE);
        }
View Full Code Here

Examples of org.geotools.data.simple.SimpleFeatureStore

     * @return a FeatureCollection with the specified features
     */
    @Override
    protected  SimpleFeatureStore _call() {

        final SimpleFeatureStore targetStore = getTargetStore();

        final String refspec = old ? oldRef : newRef;
        final RevTree rootTree = resolveRootTree(refspec);
        final NodeRef typeTreeRef = resolTypeTreeRef(refspec, path, rootTree);
        final ObjectId defaultMetadataId = typeTreeRef.getMetadataId();

        final ProgressListener progressListener = getProgressListener();

        progressListener.started();
        progressListener.setDescription("Exporting diffs for path '" + path + "'... ");

        FeatureCollection<SimpleFeatureType, SimpleFeature> asFeatureCollection = new BaseFeatureCollection<SimpleFeatureType, SimpleFeature>() {

            @Override
            public FeatureIterator<SimpleFeature> features() {

                Iterator<DiffEntry> diffs = command(DiffOp.class).setOldVersion(oldRef)
                        .setNewVersion(newRef).setFilter(path).call();

                final Iterator<SimpleFeature> plainFeatures = getFeatures(diffs, old, stagingDatabase(),
                        defaultMetadataId, progressListener);

                Iterator<Optional<Feature>> transformed = Iterators.transform(plainFeatures,
                        ExportDiffOp.this.function);

                Iterator<SimpleFeature> filtered = Iterators.filter(Iterators.transform(
                        transformed, new Function<Optional<Feature>, SimpleFeature>() {
                            @Override
                            public SimpleFeature apply(Optional<Feature> input) {
                                return (SimpleFeature) (input.isPresent() ? input.get() : null);
                            }
                        }), Predicates.notNull());

                return new DelegateFeatureIterator<SimpleFeature>(filtered);
            }
        };

        // add the feature collection to the feature store
        final Transaction transaction;
        if (transactional) {
            transaction = new DefaultTransaction("create");
        } else {
            transaction = Transaction.AUTO_COMMIT;
        }
        try {
            targetStore.setTransaction(transaction);
            try {
                targetStore.addFeatures(asFeatureCollection);
                transaction.commit();
            } catch (final Exception e) {
                if (transactional) {
                    transaction.rollback();
                }
View Full Code Here

Examples of org.geotools.data.simple.SimpleFeatureStore

        RevTree rootTree = stagingDatabase().getTree(rootTreeId.get());
        return rootTree;
    }

    private SimpleFeatureStore getTargetStore() {
        SimpleFeatureStore targetStore;
        try {
            targetStore = targetStoreProvider.get();
        } catch (Exception e) {
            throw new GeoToolsOpException(StatusCode.CANNOT_CREATE_FEATURESTORE);
        }
View Full Code Here

Examples of org.geotools.data.simple.SimpleFeatureStore

            insert(feature);
        }
        MemoryDataStore dataStore = new MemoryDataStore(pointsType);
        final String typeName = dataStore.getTypeNames()[0];
        SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);
        SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
        geogig.command(ExportOp.class).setFeatureStore(featureStore).setPath(pointsName).call();
        featureSource = dataStore.getFeatureSource(typeName);
        featureStore = (SimpleFeatureStore) featureSource;
        SimpleFeatureCollection featureCollection = featureStore.getFeatures();
        assertEquals(featureCollection.size(), points.length);
        SimpleFeatureIterator features = featureCollection.features();
        assertTrue(collectionsAreEqual(features, points));
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.