Package org.geotools.data.simple

Examples of org.geotools.data.simple.SimpleFeatureIterator


             
              FileDataStore store = FileDataStoreFinder.getDataStore(shapeFile);
              SimpleFeatureSource featureSource = store.getFeatureSource();
             
              SimpleFeatureCollection featureCollection = featureSource.getFeatures();
              SimpleFeatureIterator featureIterator = featureCollection.features();
             
              List<AttributeDescriptor> attributeDescriptors = featureSource.getSchema().getAttributeDescriptors();
             
              // update field listing
              Long position = new Long(0);
             
              for(AttributeDescriptor attribute : attributeDescriptors)
              {
                GisUploadField field = new GisUploadField();
                field.fieldName = attribute.getName().toString();
                field.fieldType = attribute.getType().getName().getLocalPart();
                field.fieldPosition = position;
               
                field.gisUpload = gisUpload;
               
                field.save();
          
                position++;
              }
             
               
              CoordinateReferenceSystem dataCRS = featureSource.getSchema().getCoordinateReferenceSystem();
            
              String code = "EPSG:4326";
              CRSAuthorityFactory crsAuthorityFactory = CRS.getAuthorityFactory(true);
              CoordinateReferenceSystem mapCRS = crsAuthorityFactory.createCoordinateReferenceSystem(code);
               
               
              boolean lenient = true; // allow for some error due to different datums
              MathTransform transform = CRS.findMathTransform(dataCRS, mapCRS, lenient);
             
              while (featureIterator.hasNext())
              {
                SimpleFeature feature = featureIterator.next();
   
                GeometryType geomType = feature.getFeatureType().getGeometryDescriptor().getType();
               
                // handle appropriate shape/upload type
                if(gisUpload.type == GisUploadType.ROUTES)
View Full Code Here


    private Geometry unionGeometry( SimpleFeatureCollection featureCollection ) {
        if (featureCollection.size() < 0) return null;

        List<Geometry> geoms = new ArrayList<Geometry>();
        SimpleFeatureIterator featureIterator = featureCollection.features();

        while( featureIterator.hasNext() ) {
            SimpleFeature feature = featureIterator.next();
            Geometry geometry = (Geometry) feature.getDefaultGeometry();
            geoms.add(geometry.reverse());

        }
View Full Code Here

    private List<SimpleFeature> featureCollectionToList( SimpleFeatureCollection collection ) {
        List<SimpleFeature> featuresList = new ArrayList<SimpleFeature>();
        if (collection == null) {
            return featuresList;
        }
        SimpleFeatureIterator featureIterator = collection.features();
        while( featureIterator.hasNext() ) {
            SimpleFeature feature = featureIterator.next();
            featuresList.add(feature);
        }
        featureIterator.close();
        return featuresList;
    }
View Full Code Here

            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();
                         }
                    } finally {
                        if (featureIterator != null) {
                            featureIterator.close();
                        }
                    }   
                }
            } catch (IOException e) {
                e.printStackTrace();
View Full Code Here

        this.mt=mt;
    }

    public SimpleFeatureIterator features() {
       
        final SimpleFeatureIterator iter = source.features();

        return new SimpleFeatureIterator() {

            private SimpleFeature feature;

            public boolean hasNext() {
                while( feature==null ){
                    if ( !iter.hasNext() )
                        return false;
                    SimpleFeature next = iter.next();
                    if( next==null )
                        continue;
                    Geometry geometry=(Geometry) next.getAttribute(typeToUseAsGeometry.getName());
                    geometry = toCollection(geometry);
                    if (geometry != null) {
                        try {
                            geometry = JTS.transform(geometry, mt);
                        } catch (TransformException e) {
                            throw (RuntimeException) new RuntimeException(
                                    Messages.ReprojectingFeatureCollection_transformationError
                                            + next.getID()).initCause(e);
                        }
                    }
                    feature = new FeatureWrapper(next, schema, new Geometry[]{geometry},
                                new String[]{ schema.getGeometryDescriptor().getName().getLocalPart()});
                }
               
                return feature!=null;
            }

            public SimpleFeature next() {
                SimpleFeature tmp = feature;
                feature=null;
                monitor.worked(1);
                return tmp;
            }

            @Override
            public void close() {
                iter.close();
            }
           
        };
    }
View Full Code Here

                new SubProgressMonitor(monitor, 1));
        if (featureSource == null) {
            return;
        }
        SimpleFeatureCollection featureCollection = featureSource.getFeatures(selectedLayer.getQuery(true));
        SimpleFeatureIterator featureIterator = featureCollection.features();
        EditCommandFactory cmdFactory = EditCommandFactory.getInstance();
        List<UndoableMapCommand> cmdList = new LinkedList<UndoableMapCommand>();
        count = 0;
        while( featureIterator.hasNext() ) {
            SimpleFeature feature = featureIterator.next();
            Geometry geometry = (Geometry) feature.getDefaultGeometry();
            Geometry newGeometry = geometry.reverse();
            UndoableMapCommand setGeometryCmd = cmdFactory.createSetGeomteryCommand(feature, selectedLayer, newGeometry);
            cmdList.add(setGeometryCmd);
            count++;
View Full Code Here

             * @return True if the feature is in the store.
             */
            private boolean isFeatureOnStore( Filter id ) {

                SimpleFeatureCollection collection = null;
                SimpleFeatureIterator iter = null;
                try {
                    collection = layerList.get(0).getResource(SimpleFeatureSource.class, null).getFeatures(id);
                    iter = collection.features();
                    if (iter.hasNext()) {
                        return true;
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    if(iter != null) iter.close();
                }
                return false;
            }
        });
    }
View Full Code Here

                    display,
                    Messages.getString("OperationUtils_warning"), Messages.getString("OperationUtils_nofeaturesproblem"), MSGTYPE.WARNING); //$NON-NLS-1$ //$NON-NLS-2$
            return;
        }

        SimpleFeatureIterator featureIterator = featureCollection.features();
        EditCommandFactory cmdFactory = EditCommandFactory.getInstance();
        List<UndoableMapCommand> copyOverList = new LinkedList<UndoableMapCommand>();
        List<UndoableMapCommand> deleteOldList = new LinkedList<UndoableMapCommand>();
        int count = 0;
        while( featureIterator.hasNext() ) {
            SimpleFeature feature = featureIterator.next();
            UndoableMapCommand addFeatureCmd = cmdFactory.createAddFeatureCommand(feature, toLayer);
            copyOverList.add(addFeatureCmd);
            UndoableMapCommand deleteFeatureCmd = cmdFactory.createDeleteFeature(feature, selectedLayer);
            deleteOldList.add(deleteFeatureCmd);
            count++;
View Full Code Here

        this.monitor = monitor;
    }

    @Override
    public SimpleFeatureIterator features() {
        final SimpleFeatureIterator iterator = delegate.features();
       
        if( size == -1 ){
            size = delegate.size();
            monitor.beginTask(delegate.getID(), size );
        }
        return new SimpleFeatureIterator(){
            int index = 0;
            public boolean hasNext() {
                return iterator.hasNext();
            }
            public SimpleFeature next() {
                index++;
                if( index > progress){
                    progress = index;
                    monitor.worked(1);
                }
                return iterator.next();
            }
            public void close() {
                monitor.done();
                iterator.close();               
            }           
        };
    }
View Full Code Here

        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();
                    }
                } finally {
                    if (featureIterator != null) {
                        featureIterator.close();
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
View Full Code Here

TOP

Related Classes of org.geotools.data.simple.SimpleFeatureIterator

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.