All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.geotools.feature.FeatureReaderIterator Maven / Gradle / Ivy

Go to download

The main module contains the GeoTools public interfaces that are used by other GeoTools modules (and GeoTools applications). Where possible we make use industry standard terms as provided by OGC and ISO standards. The formal GeoTools public api consists of gt-metadata, jts and the gt-main module. The main module contains the default implementations that are available provided to other GeoTools modules using our factory system. Factories are obtained from an appropriate FactoryFinder, giving applications a chance configure the factory used using the Factory Hints facilities. FilterFactory ff = CommonFactoryFinder.getFilterFactory(); Expression expr = ff.add( expression1, expression2 ); If you find yourself using implementation specific classes chances are you doing it wrong: Expression expr = new AddImpl( expression1, expressiom2 );

There is a newer version: 24.2-oss84-1
Show newest version
/*
 *    GeoTools - The Open Source Java GIS Toolkit
 *    http://geotools.org
 *
 *    (C) 2004-2008, Open Source Geospatial Foundation (OSGeo)
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation;
 *    version 2.1 of the License.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 */
package org.geotools.feature;

import java.io.Closeable;
import java.io.IOException;
import java.util.Iterator;
import java.util.NoSuchElementException;
import org.geotools.data.FeatureReader;
import org.opengis.feature.Feature;
import org.opengis.feature.type.FeatureType;

/**
 * An iterator that wraps around a FeatureReader.
 *
 * 

The Iterator's hasNext() will return false if the wrapped feature reader's hasNext method * throws an exception. If next() throws an exception a NoSuchElementException will be thrown. * *

{@link #close()} shall be called before disposing the iterator. Before propagating an * exception from {@link #next()} or eating an exception from the underlying feature reader at * {@link #hasNext()}, this iterator will auto-close. * * @author jeichar * @author Jody Garnett * @author Gabriel Roldan */ public class FeatureReaderIterator implements Iterator, Closeable { FeatureReader reader; public FeatureReaderIterator(FeatureReader reader) { this.reader = reader; } public boolean hasNext() { try { if (reader == null) return false; if (reader.hasNext()) { return true; } else { // auto close because we don't trust // client code to call closed :-) close(); return false; } } catch (Exception e) { close(); return false; // failure sounds like lack of next to me } } public F next() { if (reader == null) { throw new NoSuchElementException("Iterator has been closed"); } try { return reader.next(); } catch (IOException io) { close(); NoSuchElementException problem = new NoSuchElementException("Could not obtain the next feature:" + io); problem.initCause(io); throw problem; } catch (org.opengis.feature.IllegalAttributeException create) { close(); NoSuchElementException problem = new NoSuchElementException("Could not create the next feature:" + create); problem.initCause(create); throw problem; } } /** If this is a problem, a different iterator can be made based on FeatureWriter */ public void remove() { throw new UnsupportedOperationException("Modification of contents is not supported"); } /** Close the reader please. */ public void close() { if (reader != null) { try { reader.close(); } catch (Exception e) { // sorry but iterators die quitely in the night } reader = null; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy