Package org.geotools.feature

Examples of org.geotools.feature.FeatureIterator


                    }
                } catch (IOException e) {
                    throw new WFSException(request, e);
                }

                FeatureIterator reader = null;
                int numberLocked = -1;

                try {
                    for (reader = features.features(); reader.hasNext();) {
                        SimpleFeature feature = (SimpleFeature) reader.next();

                        FeatureId fid = fid(feature.getID());
                        Id fidFilter = fidFilter(fid);

                        if (!(source instanceof FeatureLocking)) {
                            LOGGER.fine("Lock " + fid + " not supported by data store (authID:"
                                + fLock.getAuthorization() + ")");

                            response.addNotLockedFeature(fid);
                            // lockFailedFids.add(fid);
                        } else {
                            // DEFQuery is just some indirection, should be in
                            // the locking interface.
                            // int numberLocked =
                            // ((DEFQueryFeatureLocking)source).lockFeature(feature);
                            // HACK: Query.NO_NAMES isn't working in postgis
                            // right now,
                            // so we'll just use all.
                            Query query = new Query(meta.getName(), (Filter) fidFilter,
                                    Query.DEFAULT_MAX, Query.ALL_NAMES, lock.getHandle());

                            numberLocked = ((FeatureLocking) source).lockFeatures(query);

                            if (numberLocked == 1) {
                                LOGGER.fine("Lock " + fid + " (authID:" + fLock.getAuthorization()
                                    + ")");
                                response.addLockedFeature( fid);

                                // lockedFids.add(fid);
                            } else if (numberLocked == 0) {
                                LOGGER.fine("Lock " + fid + " conflict (authID:"
                                    + fLock.getAuthorization() + ")");
                                response.addNotLockedFeature(fid);

                                // lockFailedFids.add(fid);
                            } else {
                                LOGGER.warning("Lock " + numberLocked + " " + fid + " (authID:"
                                    + fLock.getAuthorization() + ") duplicated FeatureID!");
                                response.addLockedFeature(fid);

                                // lockedFids.add(fid);
                            }
                        }
                    }
                } catch (IOException ioe) {
                    throw new WFSException(request, ioe);
                } finally {
                    if (reader != null) {
                        reader.close();
                    }
                }

                // refresh lock times, so they all start the same instant and we
                // are nearer
View Full Code Here


        assertNotNull(ft);

        SimpleFeatureType schema = (SimpleFeatureType) ft.getFeatureType();
        assertEquals(Integer.class, schema.getDescriptor("cat").getType().getBinding());

        FeatureIterator it = ft.getFeatureSource(null, null).getFeatures().features();
        try {
            assertTrue(it.hasNext());
            while(it.hasNext()) {
                SimpleFeature f = (SimpleFeature) it.next();
                assertTrue(f.getAttribute("cat") instanceof Integer);
            }
        }
        finally {
            it.close();
        }
    }
View Full Code Here

        assertNotNull(ft);

        SimpleFeatureType schema = (SimpleFeatureType) ft.getFeatureType();
        assertEquals(Timestamp.class, schema.getDescriptor("CAT_ID").getType().getBinding());

        FeatureIterator it = ft.getFeatureSource(null, null).getFeatures().features();
        int year = 2;
        Calendar cal = Calendar.getInstance();
        cal.setTimeZone(TimeZone.getTimeZone("UTC"));
        try {
            // make sure we have something
            assertTrue(it.hasNext());
            // the first date will be bogus due to java date limitation
            it.next();
            while(it.hasNext()) {
                SimpleFeature f = (SimpleFeature) it.next();
                // class will be timestamp
                cal.setTime( (Date) f.getAttribute("CAT_ID"));
                assertEquals(year++,cal.get(Calendar.YEAR));
            }
        }
        finally {
            it.close();
        }
    }
View Full Code Here

        assertNotNull(ft);

        SimpleFeatureType schema = (SimpleFeatureType) ft.getFeatureType();
        assertTrue(Date.class.isAssignableFrom(schema.getDescriptor("timestamp").getType().getBinding()));

        FeatureIterator it = ft.getFeatureSource(null, null).getFeatures().features();
        try {
            assertTrue(it.hasNext());
            while(it.hasNext()) {
                SimpleFeature f = (SimpleFeature) it.next();
                assertTrue(f.getAttribute("timestamp") instanceof Date);
            }
        }
        finally {
            it.close();
        }
    }
View Full Code Here

               
        Filter filter = wms.getTimeElevationToFilter(times, elevations, timeWithStartEnd);
        FeatureCollection features = fs.getFeatures(filter);
       
        Set<Integer> results = new HashSet<Integer>();
        FeatureIterator it = features.features();
        while (it.hasNext()) {
            results.add( (Integer) it.next().getProperty("id").getValue());
        }
        assertTrue("expected " + Arrays.toString(expectedIds) + " but got " + results,
                results.containsAll(Arrays.asList(expectedIds)));
        assertTrue("expected " + Arrays.toString(expectedIds) + " but got " + results,
                Arrays.asList(expectedIds).containsAll(results));
View Full Code Here

        f.getUserData().put("foo", "bar");

        DefaultFeatureCollection features = new DefaultFeatureCollection(null, b.getFeatureType());
        features.add(f);

        FeatureIterator it = features.features();
       
        try {
            assertEquals("bar", it.next().getUserData().get("foo"));
        }
        finally {
            it.close();
        }

        ReprojectingFeatureCollection reprojected =
                new ReprojectingFeatureCollection(features, CRS.decode("EPSG:3005"));
        it = reprojected.features();
       
        try {
            assertEquals("bar", it.next().getUserData().get("foo"));
        }
        finally {
            it.close();
        }
    }
View Full Code Here

    public void testReadOnly() throws Exception {
        SecuredFeatureStore ro = new SecuredFeatureStore(store, WrapperPolicy.readOnlyHide(null));
       
        // let's check the iterator, should allow read but not remove
        FeatureCollection rofc = ro.getFeatures();
        FeatureIterator roit = rofc.features();
        roit.hasNext();
        roit.next();
   
        // check derived collections are still read only and share the same
        // challenge policy
        SecuredFeatureCollection sorted = (SecuredFeatureCollection) rofc
                .sort(SortBy.NATURAL_ORDER);
View Full Code Here

                fail("Should have failed with a security exception");
        }

        // let's check the iterator, should allow read but not remove
        FeatureCollection rofc = ro.getFeatures();
        FeatureIterator roit = rofc.features();
        roit.hasNext();
        roit.next();

        // check derived collections are still read only and share the same
        // challenge policy
        SecuredFeatureCollection sorted = (SecuredFeatureCollection) rofc
                .sort(SortBy.NATURAL_ORDER);
View Full Code Here

        FeatureTypeInfo fti = getCatalog().getFeatureTypeByName(MockData.BASIC_POLYGONS.getLocalPart());
        assertEquals("EPSG:4269", fti.getSRS());
        assertEquals(ProjectionPolicy.FORCE_DECLARED, fti.getProjectionPolicy());
        FeatureCollection fc = fti.getFeatureSource(null, null).getFeatures();
        assertEquals(CRS.decode("EPSG:4269"), fc.getSchema().getCoordinateReferenceSystem());
        FeatureIterator fi = fc.features();
        Feature f = fi.next();
        fi.close();
        assertEquals(CRS.decode("EPSG:4269"), f.getType().getCoordinateReferenceSystem());
    }
View Full Code Here

        FeatureTypeInfo fti = getCatalog().getFeatureTypeByName(MockData.POLYGONS.getLocalPart());
        assertEquals("EPSG:4326", fti.getSRS());
        assertEquals(ProjectionPolicy.REPROJECT_TO_DECLARED, fti.getProjectionPolicy());
        FeatureCollection fc = fti.getFeatureSource(null, null).getFeatures();
        assertEquals(CRS.decode("EPSG:4326"), fc.getSchema().getCoordinateReferenceSystem());
        FeatureIterator fi = fc.features();
        Feature f = fi.next();
       
        //test that geometry was actually reprojected
        Geometry g = (Geometry) f.getDefaultGeometryProperty().getValue();
        assertFalse(g.equalsExact(WKT.read(
                "POLYGON((500225 500025,500225 500075,500275 500050,500275 500025,500225 500025))")));
        fi.close();
        assertEquals(CRS.decode("EPSG:4326"), f.getType().getCoordinateReferenceSystem());
    }
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.