org.geotools.data.crs.ForceCoordinateSystemFeatureResults Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gt-main Show documentation
Show all versions of gt-main Show documentation
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 );
/*
* GeoTools - The Open Source Java GIS Toolkit
* http://geotools.org
*
* (C) 2003-2016, 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.crs;
import java.io.IOException;
import java.util.Iterator;
import org.geotools.data.store.ReprojectingFeatureCollection;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureTypes;
import org.geotools.feature.SchemaException;
import org.geotools.feature.collection.AbstractFeatureCollection;
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.opengis.feature.FeatureVisitor;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
/**
* ForceCoordinateSystemFeatureResults provides a CoordinateReferenceSystem for FeatureTypes.
*
* ForceCoordinateSystemFeatureReader is a wrapper used to force GeometryAttributes to a user
* supplied CoordinateReferenceSystem rather then the default supplied by the DataStore.
*
*
Example Use:
*
*
* ForceCoordinateSystemFeatureResults results =
* new ForceCoordinateSystemFeatureResults( originalResults, forceCS );
*
* CoordinateReferenceSystem originalCS =
* originalResults.getFeatureType().getDefaultGeometry().getCoordinateSystem();
*
* CoordinateReferenceSystem newCS =
* reader.getFeatureType().getDefaultGeometry().getCoordinateSystem();
*
* assertEquals( forceCS, newCS );
*
*
* @author aaime
* @version $Id$
*/
public class ForceCoordinateSystemFeatureResults extends AbstractFeatureCollection {
FeatureCollection results;
public ForceCoordinateSystemFeatureResults(
FeatureCollection results,
CoordinateReferenceSystem forcedCS)
throws IOException, SchemaException {
this(results, forcedCS, false);
}
public ForceCoordinateSystemFeatureResults(
FeatureCollection results,
CoordinateReferenceSystem forcedCS,
boolean forceOnlyMissing)
throws IOException, SchemaException {
super(forceType(origionalType(results), forcedCS, forceOnlyMissing));
this.results = results;
}
private static SimpleFeatureType origionalType(
FeatureCollection results) {
while (true) {
if (results instanceof ReprojectFeatureResults) {
results = ((ReprojectFeatureResults) results).getOrigin();
}
if (results instanceof ForceCoordinateSystemFeatureResults) {
results = ((ForceCoordinateSystemFeatureResults) results).getOrigin();
}
break;
}
return results.getSchema();
}
public Iterator openIterator() {
return new ForceCoordinateSystemIterator(results.features(), getSchema());
}
@SuppressWarnings("PMD.CloseResource")
public void closeIterator(Iterator close) {
if (close == null) return;
if (close instanceof ForceCoordinateSystemIterator) {
ForceCoordinateSystemIterator iterator = (ForceCoordinateSystemIterator) close;
iterator.close();
}
}
public int size() {
return results.size();
}
private static SimpleFeatureType forceType(
SimpleFeatureType startingType,
CoordinateReferenceSystem forcedCS,
boolean forceOnlyMissing)
throws SchemaException {
if (forcedCS == null) {
throw new NullPointerException("CoordinateSystem required");
}
CoordinateReferenceSystem originalCs =
startingType.getGeometryDescriptor() != null
? startingType.getGeometryDescriptor().getCoordinateReferenceSystem()
: null;
if (forcedCS.equals(originalCs)) {
return startingType;
} else {
return FeatureTypes.transform(startingType, forcedCS, forceOnlyMissing);
}
}
/** @see org.geotools.data.FeatureResults#getBounds() */
public ReferencedEnvelope getBounds() {
ReferencedEnvelope env = results.getBounds();
if (env == null) {
return null;
}
env = new ReferencedEnvelope(env, getSchema().getCoordinateReferenceSystem());
return env;
}
/** @see org.geotools.data.FeatureResults#collection() */
// public SimpleFeatureCollection collection() throws IOException {
// SimpleFeatureCollection collection = FeatureCollections.newCollection();
//
// try {
// FeatureReader reader = reader();
//
// while (reader.hasNext()) {
// collection.add(reader.next());
// }
// } catch (NoSuchElementException e) {
// throw new DataSourceException("This should not happen", e);
// } catch (IllegalAttributeException e) {
// throw new DataSourceException("This should not happen", e);
// }
//
// return collection;
// }
/** Returns the feature results wrapped by this ForceCoordinateSystemFeatureResults */
public FeatureCollection getOrigin() {
return results;
}
public void accepts(
org.opengis.feature.FeatureVisitor visitor, org.opengis.util.ProgressListener progress)
throws IOException {
if (canDelegate(visitor)) {
results.accepts(visitor, progress);
} else {
super.accepts(visitor, progress);
}
}
protected boolean canDelegate(FeatureVisitor visitor) {
return ReprojectingFeatureCollection.isGeometryless(visitor, schema);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy