Package org.geotools.data.simple

Examples of org.geotools.data.simple.SimpleFeatureIterator


        }
    }

    private List<SimpleFeature> toList(SimpleFeatureCollection collection) {
        List<SimpleFeature> features = Lists.newArrayList();
        SimpleFeatureIterator iterator = collection.features();
        try {
            while (iterator.hasNext()) {
                features.add(iterator.next());
            }
        } finally {
            iterator.close();
        }
        return features;
    }
View Full Code Here


        private void doRead() throws IOException {
            final String typeName = pointType.getTypeName();
            SimpleFeatureSource featureSource;
            featureSource = dataStore.getFeatureSource(typeName);
            SimpleFeatureCollection fc = featureSource.getFeatures();
            SimpleFeatureIterator features = fc.features();
            while (features.hasNext()) {
                SimpleFeature next = features.next();
            }
            features.close();
        }
View Full Code Here

    }

    @Test
    public void testFeatureIdsAreVersioned() throws IOException {
        SimpleFeatureCollection collection = pointsSource.getFeatures(Query.ALL);
        SimpleFeatureIterator features = collection.features();

        Set<FeatureId> ids = Sets.newHashSet();
        try {
            while (features.hasNext()) {
                SimpleFeature next = features.next();
                FeatureId identifier = next.getIdentifier();
                ids.add(identifier);
            }
        } finally {
            features.close();
        }

        List<NodeRef> refs = toList(repo.command(LsTreeOp.class).setReference(pointsName)
                .setStrategy(Strategy.FEATURES_ONLY).call());
View Full Code Here

        Query query = new Query();
        query.setCoordinateSystem(sourceCRS);
        query.setCoordinateSystemReproject(WGS84);
        SimpleFeatureCollection featureCollection = featureSource.getFeatures(query);
       
        SimpleFeatureIterator it = featureCollection.features();
       
        PointSet ret = new PointSet(featureCollection.size());
        int i=0;
        while (it.hasNext()) {
            SimpleFeature feature = it.next();
            Geometry geom = (Geometry) feature.getDefaultGeometry();
           
            PointFeature ft = new PointFeature();
            ft.setGeom(geom);
            for(Property prop : feature.getProperties() ){
View Full Code Here

            Query query = new Query();
            query.setCoordinateSystem(sourceCRS);
            query.setCoordinateSystemReproject(WGS84);
            SimpleFeatureCollection featureCollection = featureSource.getFeatures(query);

            SimpleFeatureIterator it = featureCollection.features();
            int i = 0;
            while (it.hasNext()) {
                SimpleFeature feature = it.next();
                Geometry geom = (Geometry) feature.getDefaultGeometry();
                Point point = null;
                if (geom instanceof Point) {
                    point = (Point) geom;
                } else if (geom instanceof Polygon) {
                    point = ((Polygon) geom).getCentroid();
                } else if (geom instanceof MultiPolygon) {
                    point = ((MultiPolygon) geom).getCentroid();
                } else {
                    throw new RuntimeException("Shapefile must contain either points or polygons.");
                }
                String label;
                if (labelAttribute == null) {
                    label = Integer.toString(i);
                } else {
                    label = feature.getAttribute(labelAttribute).toString();
                }
                double input = 0.0;
                if (inputAttribute != null) {
                    Number n = (Number) feature.getAttribute(inputAttribute);
                    input = n.doubleValue();
                }
                Individual individual = new Individual(label, point.getX(), point.getY(), input);
                this.addIndividual(individual);
                i += 1;
            }
            LOG.debug("loaded {} features", i);
            it.close();
        } catch (Exception ex) {
            LOG.error("Error loading population from shapefile: {}", ex.getMessage());
            throw new RuntimeException(ex);
        }
        LOG.debug("Done loading shapefile.");
View Full Code Here

        Query query = new Query(typeName);

        final String sortAtt = "INT32_COL";
        SortBy[] sortBy;
        SimpleFeatureIterator features;

        sortBy = new SortBy[] { ff.sort(sortAtt, ASCENDING) };
        query.setSortBy(sortBy);
        features = fs.getFeatures(query).features();
        try {
            Integer previous = Integer.valueOf(Integer.MIN_VALUE);
            while (features.hasNext()) {
                Integer intVal = (Integer) features.next().getAttribute(sortAtt);
                assertTrue(previous + " < " + intVal + "?", previous.intValue() < intVal.intValue());
                previous = intVal;
            }
        } finally {
            features.close();
        }

        sortBy = new SortBy[] { ff.sort(sortAtt, DESCENDING) };
        query.setSortBy(sortBy);
        features = fs.getFeatures(query).features();
        try {
            Integer previous = Integer.valueOf(Integer.MAX_VALUE);
            while (features.hasNext()) {
                Integer intVal = (Integer) features.next().getAttribute(sortAtt);
                assertTrue(previous + " > " + intVal + "?", previous.intValue() > intVal.intValue());
                previous = intVal;
            }
        } finally {
            features.close();
        }

        sortBy = new SortBy[] { ff.sort(sortAtt, DESCENDING), ff.sort("FLOAT32_COL", ASCENDING) };
        query.setSortBy(sortBy);
        features = fs.getFeatures(query).features();
        try {
            Integer previous = Integer.valueOf(Integer.MAX_VALUE);
            while (features.hasNext()) {
                Integer intVal = (Integer) features.next().getAttribute(sortAtt);
                assertTrue(previous + " > " + intVal + "?", previous.intValue() > intVal.intValue());
                previous = intVal;
            }
        } finally {
            features.close();
        }
    }
View Full Code Here

        SimpleFeatureSource source;
        source = store.getFeatureSource(typeName);
        SimpleFeatureCollection features;
        features = source.getFeatures(emptyAttNameFilter);

        SimpleFeatureIterator iterator = features.features();
        try {
            assertTrue(iterator.hasNext());
        } finally {
            iterator.close();
        }
    }
View Full Code Here

        assertFalse(env2.isNull());
        env1 = results.getBounds();
        assertNotNull(env1);
        assertFalse(env1.isNull());

        SimpleFeatureIterator reader = results.features();
        assertTrue(reader.hasNext());

        try {
            assertNotNull(reader.next());
        } catch (NoSuchElementException ex) {
            ex.printStackTrace();
            fail(ex.getMessage());
        }

        reader.close();
    }
View Full Code Here

    private void testFilter(Filter filter, SimpleFeatureSource fsource, int expected)
            throws IOException {
        SimpleFeatureCollection fc = fsource.getFeatures(filter);

        SimpleFeatureIterator fi = fc.features();
        try {
            int numFeat = 0;
            while (fi.hasNext()) {
                fi.next();
                numFeat++;
            }

            String failMsg = "Fully fetched features size and estimated num features count does not match";
            assertEquals(failMsg, expected, numFeat);
        } finally {
            fi.close();
        }
    }
View Full Code Here

                    output, hints);
            }else{
              throw new IOException("Bounding box required for the FeatureCollection");
            }

            SimpleFeatureIterator i = fc.features();
            Element e = null;

            while (i.hasNext()) {
                SimpleFeature f = i.next();
                output.startElement(GMLSchema.NAMESPACE, "featureMember", null);

                if (e == null) { // first time
                    e = output.findElement(f.getFeatureType().getTypeName());
                    // should go to an abstract FT eventually
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.