Package org.geotools.feature

Examples of org.geotools.feature.FeatureIterator


                new Coordinate(0.0, 51.5) });
        DWithin filter = ff.dwithin(ff.property(aname("geo")), ff.literal(line), 130000d, "metre");
        FeatureCollection features = dataStore.getFeatureSource(tname("geopoint")).getFeatures(
                filter);
        assertEquals(1, features.size());
        FeatureIterator fi = features.features();
        assertTrue(fi.hasNext());
        SimpleFeature feature = (SimpleFeature) fi.next();
        assertEquals("Reykjavik", feature.getAttribute("name"));
        fi.close();
    }
View Full Code Here


        checkSingleResult(features, "r3");
    }

    protected void checkSingleResult(FeatureCollection features, String name) {
        assertEquals(1, features.size());
        FeatureIterator fr = features.features();
        assertTrue(fr.hasNext());
        SimpleFeature f = (SimpleFeature) fr.next();
        assertNotNull(f);
        assertEquals(name, f.getAttribute(aname("name")));
        assertFalse(fr.hasNext());
        fr.close();
    }
View Full Code Here

       
        // let's change the mul param
        Query q = new Query(Query.ALL);
        q.setHints(new Hints(Hints.VIRTUAL_TABLE_PARAMETERS, Collections.singletonMap("mul", "10")));
        q.setSortBy(new SortBy[] {ff.sort(aname("mulflow"), SortOrder.ASCENDING)});
        FeatureIterator fi = null;
        try {
            fi = fsView.getFeatures(q).features();
            assertTrue(fi.hasNext());
            SimpleFeature f = (SimpleFeature) fi.next();
            assertEquals(30.0, ((Number) f.getAttribute(aname("mulflow"))).doubleValue(), 0.1);
            assertTrue(fi.hasNext());
            f = (SimpleFeature) fi.next();
            assertEquals(45.0, ((Number) f.getAttribute(aname("mulflow"))).doubleValue(), 0.1);
        } finally {
            fi.close();
        }
       
    }
View Full Code Here

        FeatureCollection features = fs.getFeatures();
       
        assertTrue( features.getBounds().isNull() );
        assertEquals( 0, features.size() );
       
        FeatureIterator i = features.features();
        try {
            assertFalse(i.hasNext());
        } finally {
            i.close();
        }       
    }
View Full Code Here

       
        assertEquals( 2, fs.getPrimaryKey().getColumns().size() );
        assertTrue( fs.getPrimaryKey().getColumns().get(0) instanceof NonIncrementingPrimaryKeyColumn );
        assertTrue( fs.getPrimaryKey().getColumns().get(1) instanceof NonIncrementingPrimaryKeyColumn );
       
        FeatureIterator i = fs.getFeatures().features();
       
        for ( int j = 1; i.hasNext(); j++ ) {
            SimpleFeature f = (SimpleFeature) i.next();
           
            assertEquals( tname("assignedmultipk") + "." + j + "." + (j + 1) , f.getID() );
        }
       
        i.close();
    }
View Full Code Here

            query.setCoordinateSystemReproject(getMapContent().getCoordinateReferenceSystem());
            FeatureSource featureSource = getLayer().getFeatureSource();
            Collection<PropertyDescriptor> descriptors = featureSource.getSchema().getDescriptors();

            FeatureCollection queryResult = featureSource.getFeatures(query);
            FeatureIterator iter = queryResult.features();

            try {
                while (iter.hasNext()) {
                    Feature f = iter.next();
                    result.newFeature(f.getIdentifier().getID());
                    for (PropertyDescriptor desc : descriptors) {
                        Name name = desc.getName();
                        Object value = f.getProperty(name).getValue();

                        if (value != null) {
                            if (value instanceof Geometry) {
                                result.setFeatureValue(name, value.getClass().getSimpleName());
                            } else {
                                result.setFeatureValue(name, value);
                            }
                        } else {
                            result.setFeatureValue(name, "null");
                        }
                    }
                }

            } finally {
                iter.close();
            }
        }

        return result;
    }
View Full Code Here

        int band = 0;
        Set<Double> outsideValues = Collections.singleton(0D);
        SimpleFeatureCollection fc = process.execute(cov, 0, Boolean.TRUE, null, null, null, null);
        assertEquals(3, fc.size());
       
        FeatureIterator iter = fc.features();
        try {
            while (iter.hasNext()) {
                SimpleFeature feature = (SimpleFeature) iter.next();
                Polygon poly = (Polygon) feature.getDefaultGeometry();
                int value = ((Number) feature.getAttribute("value")).intValue();
                assertEquals(perimeters[value - 1], (int) (poly.getBoundary().getLength() + 0.5));
                assertEquals(areas[value - 1], (int) (poly.getArea() + 0.5));
            }
        } finally {
            iter.close();
        }
    }
View Full Code Here

        trans.scale(scaleFactor, scaleFactor);
        g2d.transform(trans);
        g2d.setStroke(new BasicStroke(0));

        if (fc != null) {
            FeatureIterator it = fc.features();

            while (it.hasNext()) {
                SimpleFeature f = (SimpleFeature) it.next();
                LineString geom = (LineString) f.getDefaultGeometry();
                Coordinate start = geom.getCoordinateN(0);
                Coordinate current;

                for (int i = 1; i < geom.getNumPoints(); i++) {
View Full Code Here

        VersioningDataStore synch = (VersioningDataStore) getCatalog().getDataStoreByName("synch")
                .getDataStore(null);
        FeatureSource<SimpleFeatureType, SimpleFeature> fs = synch.getFeatureSource(SYNCH_HISTORY);
        FeatureCollection fc = fs.getFeatures(ff.equals(ff.property("table_name"), ff
                .literal("restricted")));
        FeatureIterator fi = fc.features();
        SimpleFeature f = (SimpleFeature) fi.next();
        fi.close();

        assertEquals(12l, f.getAttribute("central_revision"));
    }
View Full Code Here

    }
   
    void buildIndex(Connection conn) throws Exception {
        Statement st = null;
        PreparedStatement ps = null;
        FeatureIterator fi = null;
        try {
            st = conn.createStatement();
            st.execute("CREATE TABLE FEATUREIDX(" //
                    + "X NUMBER, " //
                    + "Y NUMBER, " //
                    + "FID VARCHAR(64), " //
                    + "ORDER_FIELD " + h2Type + ")");
            st.execute("CREATE INDEX FEATUREIDX_COORDS ON FEATUREIDX(X, Y)");
            st.execute("CREATE INDEX FEATUREIDX_ORDER_FIELD ON FEATUREIDX(ORDER_FIELD)");

            // prepare this statement so that the sql parser has to deal
            // with it just once
            ps = conn.prepareStatement("INSERT INTO "
                    + "FEATUREIDX(X, Y, FID, ORDER_FIELD) VALUES (?, ?, ?, ?)");

            // build an optimized query, loading only the necessary attributes
            GeometryDescriptor geom = fs.getSchema()
                    .getGeometryDescriptor();
            CoordinateReferenceSystem nativeCrs = geom
                    .getCoordinateReferenceSystem();
            Query q = new Query();
           
            if (geom.getLocalName().equals(attribute)) {
                q.setPropertyNames(new String[] { geom.getLocalName() });
            } else {
                q.setPropertyNames(new String[] { attribute, geom.getLocalName() });
            }
           
            // setup the eventual transform
            MathTransform tx = null;
            double[] coords = new double[2];
            if (!CRS.equalsIgnoreMetadata(nativeCrs, WGS84))
                tx = CRS.findMathTransform(nativeCrs, WGS84, true);

            // read all the features and fill the index table
            // make it so the insertion is a single big transaction, should
            // be faster,
            // provided it does not kill H2...
            conn.setAutoCommit(false);
            fi = fs.getFeatures(q).features();
            while (fi.hasNext()) {
                // grab the centroid and transform it in 4326 if necessary
                SimpleFeature f = (SimpleFeature) fi.next();
                Geometry g = (Geometry) f.getDefaultGeometry();
                Point centroid = g.getCentroid();
               
                //robustness check for bad geometries
                if ( Double.isNaN( centroid.getX() ) || Double.isNaN( centroid.getY() ) ) {
                    LOGGER.warning( "Could not calculate centroid for feature " + f.getID() + "; g =  " + g.toText() );
                    continue;
                }
               
                coords[0] = centroid.getX();
                coords[1] = centroid.getY();
                if (tx != null)
                    tx.transform(coords, 0, coords, 0, 1);

                // insert
                ps.setDouble(1, coords[0]);
                ps.setDouble(2, coords[1]);
                ps.setString(3, f.getID());
                ps.setObject(4, getSortAttributeValue(f));
                ps.execute();
            }
            // todo: commit every 1000 features or so. No transaction is
            // slower, but too big transaction imposes a big overhead on the db
            conn.commit();
           
            // hum, shall we kick H2 so that it updates the statistics?
        } finally {
            conn.setAutoCommit(true);
            JDBCUtils.close(st);
            JDBCUtils.close(ps);
            if (fi != null)
                fi.close();
        }
    }
View Full Code Here

TOP

Related Classes of org.geotools.feature.FeatureIterator

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.