Package org.geotools.data.simple

Examples of org.geotools.data.simple.SimpleFeatureIterator


            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();

        List<IDocument> documents = hotlink.getDocuments(tasmania, new NullProgressMonitor());
        assertEquals("image document found", 2, documents.size());

        // IDocument imageDocument = documents.get(0);
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

            // Transform bounds into Graticule CRS
            bounds = bounds.transform(graticule.getCRS(), true);

            // Get squares inside bounds
            SimpleFeatureIterator it = squares(bounds, size);

//            // Initialize border tick positions
//            List<Geometry> ticks = new ArrayList<Geometry>();
//
//            // Get map borders as geometry in graticule CRS
//            Geometry outer = JTS.toGeometry(bounds);
//            Geometry inner = JTS.toGeometry(expand(bounds,-500));

            // Draw one squares at the time (only top and left lines are drawn)
            while (it.hasNext()) {

                // Initialize states
                int i = 0;
                Point current = null;

                // Initialize lines
                List<Line> lines = new ArrayList<Line>(2);
                List<Label> labels = new ArrayList<Label>(2);

                // Get next geometry
                Geometry geom = (Geometry) it.next().getDefaultGeometry();

                // Get coordinates in graticule CRS
                Coordinate[] coords = geom.getCoordinates();

                // Get x-coordinate label from upper left corner
View Full Code Here

    }
   
    @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;
            private FeatureWrapper feature;
            public boolean hasNext() {
                while( feature == null ) {
                    if( !iterator.hasNext() )
                        return false;
                    SimpleFeature next = iterator.next();
                    if( next==null )
                        continue;
                    Geometry geometry = (Geometry) next.getDefaultGeometry();
                    if( geometry!=null ){
                            try {
                                geometry = JTS.transform(geometry, mt);
                            } catch (TransformException e) {
                                throw (RuntimeException) new RuntimeException(
                                        Messages.ReprojectingFeatureCollection_transformationError + next.getID()).initCause(e);
                            }
                    }
                    GeometryDescriptor defaultGeometry2 = featureType.getGeometryDescriptor();
                    Name name = defaultGeometry2.getName();
                    String localPart = name.getLocalPart();
                    feature = new FeatureWrapper(next, featureType, new Geometry[]{geometry},
                                new String[]{ localPart});
                }
                return feature!=null;
            }
            public SimpleFeature next() {
                index++;
                if( index > progress){
                    progress = index;
                    monitor.worked(1);
                }
                FeatureWrapper tmp = feature;
                feature=null;
                return tmp;
            }
            public void close() {
                monitor.done();
                iterator.close();               
            }           
        };
    }
View Full Code Here

                SimpleFeatureCollection featureCollection = lineSource.getFeatures(iLayer.getFilter());
                GeometryDescriptor geometryDescriptor = featureCollection.getSchema().getGeometryDescriptor();
                if (!SLD.isLine(geometryDescriptor)) {
                    break;
                }
                SimpleFeatureIterator featureIterator = featureCollection.features();
                if (featureIterator.hasNext()) {
                    lineFeature = featureIterator.next();
                }

            }
            if (geoResource.canResolve(GridCoverage.class)) {
                coverage = (GridCoverage2D) geoResource.resolve(GridCoverage.class, monitor);
View Full Code Here

    }

    private Map<String, SimpleFeature> idToFeatureMap(SimpleFeatureCollection features) {
        Map<String, SimpleFeature> result = Maps.newHashMap();

        final SimpleFeatureIterator features1 = features.features();
        while (features1.hasNext()) {
            final SimpleFeature feature = features1.next();
            result.put(feature.getID(), feature);
        }
        return result;
    }
View Full Code Here

            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!
View Full Code Here

            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
View Full Code Here

    @JSFunction
    public FeatureCollection map(final Function function) {
        final Scriptable scope = getParentScope();
        final Context context = getCurrentContext();
        final SimpleFeatureIterator mappedIterator = new SimpleFeatureIterator() {

            SimpleFeatureIterator iterator = collection.features();

            public SimpleFeature next() throws NoSuchElementException {
                Feature feature = new Feature(scope, iterator.next());
                Object[] args = {feature};
                Object newFeature = function.call(context, scope, scope, args);
                if (!(newFeature instanceof Feature)) {
                    throw ScriptRuntime.constructError("Error",
                            "Map function must return a feature");
                }
                return (SimpleFeature) ((Feature) newFeature).unwrap();
            }
           
            public boolean hasNext() {
                return iterator.hasNext();
            }
           
            public void close() {
                iterator.close();
            }
        };
        SimpleProcessingCollection mappedCollection = new SimpleProcessingCollection() {
           
            @Override
            public int size() {
                return collection.size();
            }
           
            @Override
            public ReferencedEnvelope getBounds() {
                return collection.getBounds();
            }
           
            @Override
            public SimpleFeatureIterator features() {
                return mappedIterator;
            }
           
            @Override
            protected SimpleFeatureType buildTargetFeatureType() {
                SimpleFeatureIterator iterator = collection.features();
                SimpleFeatureType featureType = null;
                if (iterator.hasNext()) {
                    Feature feature = new Feature(scope, iterator.next());
                    Object[] args = {feature};
                    try {
                        Object newFeature = function.call(context, scope, scope,
                                args);
                        if (!(newFeature instanceof Feature)) {
                            throw ScriptRuntime.constructError("Error",
                                    "Map function must return a feature");
                        }
                        featureType = (SimpleFeatureType) ((Feature) newFeature)
                               .getSchema().unwrap();
                    } finally {
                        iterator.close();
                    }
                }
                return featureType;
            }
        };
View Full Code Here

        // add features
        Context cx = getCurrentContext();
        Scriptable scope = getParentScope();
        Scriptable features = cx.newArray(scope, 0);
        SimpleFeatureIterator iterator = collection.features();
        int i = -1;
        while (iterator.hasNext()) {
            ++i;
            Feature feature = new Feature(scope, iterator.next());
            Scriptable featureConfig = feature.getConfig();
            featureConfig.delete("schema"); // to be added at top level
            features.put(i, features, featureConfig);
        }
        config.put("features", config, features);
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.