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

org.geotools.data.store.FeatureWriterIterator 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 );

The 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.data.store;

import java.io.IOException;
import java.util.Iterator;
import java.util.NoSuchElementException;
import org.geotools.data.FeatureWriter;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;

/**
 * An iterator wrapper for a FeatureWriter - for use with an AbstractFeatureCollection.
 *
 * 

There is no reason modify this class, subclasses that wish to work with a custom iterator need * just that - a custom iterator. * *

* *

The use of this class against a SimpleFeatureSource not backed by a Transaction may *really* * cut into performance. Consider if you will the overhead involved in writing out each feature into * a temporary file (when the user may not even modify anything). * * @author jgarnett * @since 2.1.RC0 */ final class FeatureWriterIterator implements Iterator { FeatureWriter writer; public FeatureWriterIterator(FeatureWriter writer) { this.writer = writer; } public boolean hasNext() { try { if (writer == null) { return false; } writer.write(); // write out any "changes" made if (writer.hasNext()) { return true; } else { close(); return false; // auto close because we don't trust client // code to call close } } catch (IOException e) { close(); return false; // failure sounds like lack of next to me } } public SimpleFeature next() { if (writer == null) { throw new NoSuchElementException("Iterator has been closed"); } try { return writer.next(); } catch (IOException io) { NoSuchElementException problem = new NoSuchElementException("Could not obtain the next feature:" + io); problem.initCause(io); throw problem; } } public void remove() { try { writer.remove(); } catch (IOException problem) { throw (IllegalStateException) new IllegalStateException("Could not remove feature").initCause(problem); } } /** * This method only needs package visability as only AbstractFeatureCollection is trusted enough * to call it. */ void close() { if (writer != null) { try { writer.close(); } catch (IOException e) { // sorry but iterators die quitely in the night } writer = null; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy