Examples of SimpleFeatureStore


Examples of org.geotools.data.simple.SimpleFeatureStore

           
            final SimpleFeatureType featureType = output.getSchema();
           
            IGeoResource scratch = CatalogPlugin.getDefault().getLocalCatalog().createTemporaryResource( featureType );
            final SimpleFeatureStore store = scratch.resolve(SimpleFeatureStore.class, SubMonitor.convert(monitor,Messages.ReshapeOperation_createTempSpaceTask, 10));
           
            store.setTransaction( transaction );
           
            ProgressListener progessListener = GeoToolsAdapters.progress( SubMonitor.convert(monitor,"processing "+source.getName(), 90));         //$NON-NLS-1$

            output.accepts(new FeatureVisitor(){
                boolean warning = true;
                public void visit( Feature rawFeature ) {
                    SimpleFeature feature = (SimpleFeature) rawFeature;
                    String fid = feature.getID();
                   
                    try {
                        store.addFeatures(DataUtilities.collection(feature));
                    } catch (Throwable t) {
                        if (warning) {
                            System.out.println( "Process "+fid+":"+t);
                            t.printStackTrace();
                            warning = false;
View Full Code Here

Examples of org.geotools.data.simple.SimpleFeatureStore

        params.put("url", URLUtils.fileToURL(file)); //$NON-NLS-1$
        params.put("create spatial index", Boolean.TRUE); //$NON-NLS-1$
        ShapefileDataStore ds = (ShapefileDataStore) dataStoreFactory.createDataStore(params);
        ds.createSchema(type);
       
        SimpleFeatureStore featureSource = (SimpleFeatureStore) ds.getFeatureSource();
        List<FeatureId> ids = featureSource.addFeatures(fc);
        return ids.size() >= 0;
    }
View Full Code Here

Examples of org.geotools.data.simple.SimpleFeatureStore

        FeatureCollection<SimpleFeatureType, SimpleFeature> collection = null;
        FeatureIterator<SimpleFeature> iterator = null;

        try {
            Class<? extends Filter> filterType = BBOX.class;
            SimpleFeatureStore store = handler.getEditLayer().getResource(SimpleFeatureStore.class,
                    null);
            Filter createBBoxFilter = createBBoxFilter(bbox, handler.getEditLayer(), filterType);
            collection = store.getFeatures(createBBoxFilter);
            iterator = collection.features();
            if (iterator.hasNext()) {
                return true;
            }
        } catch (IOException e1) {
View Full Code Here

Examples of org.geotools.data.simple.SimpleFeatureStore

        FeatureCollection<SimpleFeatureType, SimpleFeature> collection = null;
        FeatureIterator<SimpleFeature> iterator = null;

        try {
            Class<? extends Filter> filterType = BBOX.class;
            SimpleFeatureStore store = handler.getEditLayer().getResource(SimpleFeatureStore.class,
                    null);
            Filter createBBoxFilter = createBBoxFilter(bbox, handler.getEditLayer(), filterType);
            collection = store.getFeatures(createBBoxFilter);
            iterator = collection.features();
            if (iterator.hasNext()) {
                return iterator.next();
            }
        } catch (IOException e1) {
View Full Code Here

Examples of org.geotools.data.simple.SimpleFeatureStore

    }
   
    private SimpleFeature getFeature(IGeoResource geoResource, Filter filter) {
        try {
            if (geoResource.canResolve(SimpleFeatureStore.class)) {
                final SimpleFeatureStore featureSource = geoResource.resolve(
                        SimpleFeatureStore.class, new NullProgressMonitor());
                final SimpleFeatureCollection featureCollection = featureSource.getFeatures(filter);
                final SimpleFeatureIterator featureIterator = featureCollection.features();
                try {
                    if (featureIterator.hasNext()) {
                        return featureIterator.next();
                    }
View Full Code Here

Examples of org.geotools.data.simple.SimpleFeatureStore

        assertNotNull(hotlink);

        List<HotlinkDescriptor> list = hotlink.getHotlinkDescriptors(null, new NullProgressMonitor());
        assertEquals("descriptors found", 2, list.size());

        SimpleFeatureStore featureStore = resource.resolve(SimpleFeatureStore.class,
                new NullProgressMonitor());
        SimpleFeatureType schema = featureStore.getSchema();
        for (HotlinkDescriptor hotlinkDescriptor : list) {
            AttributeDescriptor attributeDescriptor = schema.getDescriptor(hotlinkDescriptor
                    .getAttributeName());
            assertNotNull("confirm attribute name matches", attributeDescriptor);
            assertTrue("Confirm String",
                    String.class.isAssignableFrom(attributeDescriptor.getType().getBinding()));

            assertNotNull(hotlinkDescriptor.getType() != null);
        }
        FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
        SimpleFeatureCollection features = featureStore.getFeatures(ff.equals(ff.property("STATE"),
                ff.literal("Tasmania")));
        SimpleFeatureIterator iterator = features.features();
        assertTrue("Tasmania found", iterator.hasNext());
        SimpleFeature tasmania = iterator.next();
View Full Code Here

Examples of org.geotools.data.simple.SimpleFeatureStore

    }

    private SimpleFeature getFeature(IGeoResource geoResource, Filter filter) {
        try {
            if (geoResource.canResolve(SimpleFeatureStore.class)) {
                final SimpleFeatureStore featureSource = geoResource.resolve(
                        SimpleFeatureStore.class, new NullProgressMonitor());
                final SimpleFeatureCollection featureCollection = featureSource.getFeatures(filter);
                final SimpleFeatureIterator featureIterator = featureCollection.features();
                try {
                    if (featureIterator.hasNext()) {
                        return featureIterator.next();
                    }
View Full Code Here

Examples of org.geotools.data.simple.SimpleFeatureStore

           
            final SimpleFeatureType featureType = output.getSchema();
           
            IGeoResource scratch = CatalogPlugin.getDefault().getLocalCatalog().createTemporaryResource( featureType );
            final SimpleFeatureStore store = scratch.resolve(SimpleFeatureStore.class, SubMonitor.convert(monitor,Messages.ReshapeOperation_createTempSpaceTask, 10));
           
            store.setTransaction( transaction );
           
            ProgressListener progessListener = GeoToolsAdapters.progress( SubMonitor.convert(monitor,"processing "+source.getName(), 90));         //$NON-NLS-1$

            output.accepts(new FeatureVisitor(){
                boolean warning = true;
                public void visit( Feature rawFeature ) {
                    SimpleFeature feature = (SimpleFeature) rawFeature;
                    String fid = feature.getID();
                   
                    try {
                        store.addFeatures(DataUtilities.collection(feature));
                    } catch (Throwable t) {
                        if (warning) {
                            System.out.println( "Process "+fid+":"+t);
                            t.printStackTrace();
                            warning = false;
View Full Code Here

Examples of org.geotools.data.simple.SimpleFeatureStore

      String typeName = newDataStore.getTypeNames()[0];
      SimpleFeatureSource featureSource = newDataStore
          .getFeatureSource(typeName);

      if (featureSource instanceof SimpleFeatureStore) {
        SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;

        /*
         * SimpleFeatureStore has a method to add features from a
         * SimpleFeatureCollection object, so we use the
         * ListFeatureCollection class to wrap our list of features.
         */
        SimpleFeatureCollection collection = new ListFeatureCollection(
            features.get(0).getFeatureType(), features);
        featureStore.setTransaction(transaction);
        try {
          featureStore.addFeatures(collection);
          transaction.commit();

        } catch (Exception problem) {
          problem.printStackTrace();
          transaction.rollback();
View Full Code Here

Examples of org.geotools.data.simple.SimpleFeatureStore

          int iYear = Integer.parseInt(year);
          int iMonth = month==null? -1 : Integer.parseInt(month);
          int iDay = day==null? -1 : Integer.parseInt(day);
          Date date = new Date(iYear-1900, iMonth==-1?0:iMonth-1, iDay==-1?1:iDay);
 
          SimpleFeatureStore featureStoreData = (SimpleFeatureStore) fsLayer;
 
          // update the layer store with the new SimpleFeature coming from the shape file
          // data are saved itemsForPage elements at time

            SimpleFeatureType dstSchema = dstDs.getSchema(layer);
            featureStoreData.setTransaction(tx);
            SimpleFeatureType srcSchema = sourceFC.getSchema();
            List<AttributeDescriptor> srcAttributeDescriptor = srcSchema.getAttributeDescriptors();

            SimpleFeatureBuilder featureBuilderData = new SimpleFeatureBuilder(dstSchema);
            SimpleFeatureIterator featureIterator = sourceFC.features();
            boolean hasFinished = false;
            int i = 0;
            Set<String> loggedMissingAttrib = new HashSet<String>();
            while (!hasFinished) { // TODO: refacotr this nested loop!!!

              //DamianoGiampaoli 03/11/2014
              //TEST IT!!!
              // Due to the upgrade needed from the Geotools 8-SNAPSHOT to geotools 10.8 in order to support GeoBatch 1.4.x
              // The add(SimpleFeature) method of SimpleFeatureCollection cannot be used anymore so a List<SimpleFeature> must be used.
                //SimpleFeatureCollection sfcData = FeatureCollections.newCollection();
                List<SimpleFeature> sfcData = new ArrayList<SimpleFeature>();
               
                boolean exitForIntermediateSaving = false;

                while (featureIterator.hasNext() && !exitForIntermediateSaving) {
                    i++;

                    exitForIntermediateSaving = ((i % ITEM_X_PAGE) == 0);

                    SimpleFeature sf = featureIterator.next();
                    SimpleFeature data = featureBuilderData.buildFeature(sf.getID());
                    for (int j = 0; j < srcAttributeDescriptor.size(); j++) {
                        String srcName = srcAttributeDescriptor.get(j).getLocalName();
                        String dstName = srcName.toLowerCase(); // FIXME: this is a worksroung for SHP 2 PG attrib name conversion. make it general!

                        Property p = sf.getProperty(srcName);
                        if( p!= null) // be lenient about inexistent attributes: consistency checks have already bben performed.
                            data.setAttribute(dstName, sf.getAttribute(srcName));
                        else {
                            if(LOGGER.isDebugEnabled() && ! loggedMissingAttrib.contains(srcName) ) {
                                LOGGER.debug("Skipping attrib "+srcName+" in feature #"+i);
                                loggedMissingAttrib.add(srcName);
                            }
                        }
                    }

                    data.setAttribute(YEARATTRIBUTENAME, iYear);
                    if(iMonth != -1){
                        data.setAttribute(MONTHATTRIBUTENAME, month);
                    }
                    if(iDay != -1){
                        data.setAttribute(DAYATTRIBUTENAME, day);
                    }
                    data.setAttribute(DATEATTRIBUTENAME, date);
                    sfcData.add(data);

                }
                if (!exitForIntermediateSaving) {
                    hasFinished = true;
                }
                SimpleFeatureCollection featureCollection = new ListFeatureCollection(srcSchema, sfcData);
                featureStoreData.addFeatures(featureCollection);
            }
           
            tx.commit();
            LOGGER.info("Copied " + i + " features for "+ layer+"/"+year+"/"+month+"/"+day+ " to " + dstPg);
            return i;
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.