Package org.geotools.data.simple

Examples of org.geotools.data.simple.SimpleFeatureIterator


        SimpleFeatureCollection fc = (SimpleFeatureCollection) parse();
        assertNotNull(fc);

        assertEquals(2, fc.size());

        SimpleFeatureIterator i = fc.features();
        try {
            SimpleFeature f = (SimpleFeature) i.next();
            assertEquals("fid.1", f.getID());
   
            f = (SimpleFeature) i.next();
            assertEquals("fid.2", f.getID());
        } finally {
            i.close();
        }
    }
View Full Code Here


        params.put("user", "geotools");
        params.put("passwd", "geotools");

        assertTrue(CoverageSlicesCatalog.INTERNAL_STORE_SPI.canProcess(params));
        DataStore ds = null;
        SimpleFeatureIterator it = null;
        try {
            // create the store
            ds = CoverageSlicesCatalog.INTERNAL_STORE_SPI.createDataStore(params);
            assertNotNull(ds);

            // load typenames
            final String[] typeNames = ds.getTypeNames();
            assertNotNull(typeNames);
            assertEquals(20, typeNames.length);
            assertEquals("atmospheric_water_vapor", typeNames[2]);
            assertEquals("cloud_top_temperature", typeNames[5]);
            assertEquals("integrated_ozone", typeNames[11]);

            // work with surface emissivity
            final SimpleFeatureSource fs = ds.getFeatureSource("surface_emissivity");
            assertNotNull(fs);
            final SimpleFeatureType schema = fs.getSchema();
            assertNotNull(schema);

            // queries
            // simple
            assertTrue(fs.getCount(Query.ALL) > 0);

            // complex
            final Query q = new Query();
            q.setTypeName("surface_emissivity");
            q.setFilter(ff.greaterOrEqual(ff.property("new"), ff.literal(0)));
            assertTrue(fs.getCount(q) > 0);

            final SimpleFeatureCollection fc = fs.getFeatures(q);
            assertFalse(fc.isEmpty());
            it = fc.features();
            while (it.hasNext()) {
                final SimpleFeature feat = it.next();

                assertTrue((Integer)feat.getAttribute("new")>=0);

            }

        } finally {
            if (ds != null) {
                ds.dispose();
            }

            if (it != null) {
                it.close();
            }
        }

    }
View Full Code Here

        SimpleFeatureSource featureSource = store.getFeatureSource("locations");

        Filter filter = CQL.toFilter("CITY = 'Denver'");
        SimpleFeatureCollection features = featureSource.getFeatures(filter);
        System.out.println("found :" + features.size() + " feature");
        SimpleFeatureIterator iterator = features.features();
        try {
            while (iterator.hasNext()) {
                SimpleFeature feature = iterator.next();
                Geometry geometry = (Geometry) feature.getDefaultGeometry();
                System.out.println(feature.getID() + " default geometry " + geometry);
            }
        } catch (Throwable t) {
            iterator.close();
        }

        // example5 end
        System.out.println("\nexample5 end\n");
    }
View Full Code Here

     * Update features imageIndex by referring them to a specific offset
     * @param collection
     * @param offset
     */
    private void updateFeaturesIndex(final ListFeatureCollection collection, final int offset) {
        final SimpleFeatureIterator featuresIt = collection.features();
        SimpleFeature feature = null;
        while (featuresIt.hasNext()) {
            feature = featuresIt.next();
            Integer index = (Integer) feature.getAttribute(CoverageSlice.Attributes.INDEX);
            feature.setAttribute(CoverageSlice.Attributes.INDEX, index + offset);
        }
    }
View Full Code Here

    @Test
    public void testInfiniteLoopAvoidance() throws Exception {
        final Exception sentinel = new RuntimeException("This is the one that should be thrown in hasNext()");
       
        // setup the mock necessary to have the renderer hit into the exception in hasNext()
        SimpleFeatureIterator it2 = createNiceMock(SimpleFeatureIterator.class);
        expect(it2.hasNext()).andThrow(sentinel).anyTimes();
        replay(it2);
       
        SimpleFeatureCollection fc = createNiceMock(SimpleFeatureCollection.class);
        expect(fc.features()).andReturn(it2);
        expect(fc.size()).andReturn(200);
View Full Code Here

        FeatureId featureId = ff.featureId("streams.84");
        Id filter = ff.id(Collections.singleton(featureId));
        SimpleFeatureCollection features = ds.getFeatureSource().getFeatures(filter);

        SimpleFeatureIterator iter = features.features();
        ReferencedEnvelope bounds;
        try {
            bounds = new ReferencedEnvelope(iter.next().getBounds());
        } finally {
            iter.close();
        }

        FeatureId id = featureId;
        filter = ff.id(Collections.singleton(id));
View Full Code Here

    /**
     * run the walker on the store
     */
    public void run() {

        SimpleFeatureIterator it = null;
        try {

            configHandler.indexingPreamble();
            startTransaction();

            // start looking into catalog
            final GranuleCatalog catalog = configHandler.getCatalog();
            for (String typeName : catalog.getTypeNames()) {

                // how many rows for this feature type?
                final Query query = new Query(typeName);
                int numFiles = catalog.getGranulesCount(query);
                if (numFiles <= 0) {
                    // empty table?
                    LOGGER.log(Level.FINE, "No rows in the typeName: " + typeName);
                    continue;
                }
                setNumFiles(numFiles);

                // cool, now let's walk over the features
                final SimpleFeatureCollection coll = catalog.getGranules(query);
                // create an iterator
                it = coll.features();
                // TODO setup index name

                while (it.hasNext()) {
                    // get next element
                    final SimpleFeature feature = it.next();

                    // String
                    // locationAttrName=config.getCatalogConfigurationBean().getLocationAttribute();
                    String locationAttrName = configHandler.getRunConfiguration().getParameter(
                            Prop.LOCATION_ATTRIBUTE);
                    Object locationAttrObj = feature.getAttribute(locationAttrName);
                    File file = null;
                    if (locationAttrObj instanceof String) {
                        final String path = (String) locationAttrObj;
                        if (Boolean.getBoolean(configHandler.getRunConfiguration().getParameter(
                                Prop.ABSOLUTE_PATH))) {
                            // absolute files
                            file = new File(path);
                            // check this is _really_ absolute
                            if (!checkFile(file)) {
                                file = null;
                            }
                        }
                        if (file == null) {
                            // relative files
                            file = new File(configHandler.getRunConfiguration().getParameter(
                                    Prop.ROOT_MOSAIC_DIR), path);
                            // check this is _really_ relative
                            if (!(file.exists() && file.canRead() && file.isFile())) {
                                // let's try for absolute, despite what the config says
                                // absolute files
                                file = new File(path);
                                // check this is _really_ absolute
                                if (!(checkFile(file))) {
                                    file = null;
                                }
                            }
                        }

                        // final check
                        if (file == null) {
                            // SKIP and log
                            // empty table?
                            super.skipFile(path);
                            continue;
                        }

                    } else if (locationAttrObj instanceof File) {
                        file = (File) locationAttrObj;
                    } else {
                        eventHandler.fireException(new IOException(
                                "Location attribute type not recognized for column name: "
                                        + locationAttrName));
                        stop();
                        break;
                    }

                    // process this file
                    handleFile(file);
                }

            } // next table

            // close transaction
            // did we cancel?
            if (getStop()) {
                rollbackTransaction();
            } else {
                commitTransaction();
            }

        } catch (Exception e) {
            LOGGER.log(Level.WARNING, "Failure occurred while collecting the granules", e);
            try {
                rollbackTransaction();
            } catch (IOException e1) {
                throw new IllegalStateException(e1);
            }
        } finally {
            // close read iterator
            if (it != null) {
                try {
                    it.close();
                } catch (Exception e) {
                    LOGGER.log(Level.FINE, e.getLocalizedMessage(), e);
                }
            }
            // close transaction
View Full Code Here

    /**
     * Returns the first feature in the given feature collection.
     */
    protected SimpleFeature firstFeature(SimpleFeatureCollection fc) {
        SimpleFeatureIterator features = fc.features();
        SimpleFeature next = features.next();
        features.close();
        return next;
    }
View Full Code Here

 
  /**
   * Visits all features in the collection.
   */
  public void accepts(FeatureVisitor visitor, ProgressListener progress) throws IOException {
      SimpleFeatureIterator feats = features();
      try {
            while( feats.hasNext() ) {
                SimpleFeature f = feats.next();
                visitor.visit(f);
            }
        } finally {
            feats.close();
        }
   
  }
View Full Code Here

  /**
   * @returns a feature iterator that iterators over all features in the collection
   */
  public SimpleFeatureIterator features() {
    SimpleFeatureIterator iter = new DelegateSimpleFeatureIterator(this, openIterator());
    iterators.add(iter);
    return iter;
  }
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.