Search in sources :

Example 1 with NullProgressListener

use of org.geotools.util.NullProgressListener in project polymap4-core by Polymap4.

the class RFeatureCollection method accepts.

@Override
public void accepts(FeatureVisitor visitor, ProgressListener progress) throws IOException {
    // prevent call of size() if no progress is given
    float _size = progress != null ? size() : 0;
    progress = progress != null ? progress : new NullProgressListener();
    Iterator it = null;
    try {
        float position = 0;
        progress.started();
        for (it = iterator(); !progress.isCanceled() && it.hasNext(); ) {
            if (_size > 0) {
                progress.progress(position++ / _size);
            }
            try {
                visitor.visit((Feature) it.next());
            } catch (Exception e) {
                log.warn("Error while visiting features.", e);
                progress.exceptionOccurred(e);
            }
        }
    } finally {
        progress.complete();
    }
}
Also used : NullProgressListener(org.geotools.util.NullProgressListener) FeatureIterator(org.geotools.feature.FeatureIterator) Iterator(java.util.Iterator) DelegateFeatureIterator(org.geotools.feature.collection.DelegateFeatureIterator) IOException(java.io.IOException)

Example 2 with NullProgressListener

use of org.geotools.util.NullProgressListener in project chordatlas by twak.

the class Footprints method test.

public static void test() throws IOException, SAXException, ParserConfigurationException {
    // create the parser with the gml 2.0 configuration
    org.geotools.xml.Configuration configuration = new org.geotools.gml2.GMLConfiguration();
    org.geotools.xml.Parser parser = new org.geotools.xml.Parser(configuration);
    InputStream xml = new FileInputStream("/home/twak/data/around_ucl_buildings.gml");
    // parse
    FeatureCollection fc = (FeatureCollection) parser.parse(xml);
    fc.accepts(new AbstractFeatureVisitor() {

        public void visit(Feature feature) {
            System.out.println(feature);
        // SimpleFeature f = (Feature) i.next();
        // 
        // Point point = (Point) f.getDefaultGeometry();
        // String name = (String) f.getAttribute( "name" );
        }
    }, new NullProgressListener());
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Feature(org.opengis.feature.Feature) FileInputStream(java.io.FileInputStream) NullProgressListener(org.geotools.util.NullProgressListener) FeatureCollection(org.geotools.feature.FeatureCollection) AbstractFeatureVisitor(org.geotools.feature.collection.AbstractFeatureVisitor)

Aggregations

NullProgressListener (org.geotools.util.NullProgressListener)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Iterator (java.util.Iterator)1 FeatureCollection (org.geotools.feature.FeatureCollection)1 FeatureIterator (org.geotools.feature.FeatureIterator)1 AbstractFeatureVisitor (org.geotools.feature.collection.AbstractFeatureVisitor)1 DelegateFeatureIterator (org.geotools.feature.collection.DelegateFeatureIterator)1 Feature (org.opengis.feature.Feature)1