upgrade to 2.3 - STEMLab/geotools GitHub Wiki
The following is needed when upgrading to 2.3:
Transition to FeatureCollection
FeatureResults was deprecated for the 2.1 release, and it is passing out
of existence for 2.3. All methods were deprecated and their
replacements documented.
Before (GeoTools 2.1 Code)
public example(FeatureSource featureSource) throws IOException ){
FeatureResults results = featureSource.getFeatures();
int count = results.getCount();
FeatureCollection collection = results.collection();
FeatureReader reader = results.reader();
try {
while( reader.hasNext() ){
Feature feature = reader.next();
}
}
finally {
reader.close();
}
}
Quick Alternative (GeoTools 2.3 Code)
FeatureCollection results = featureSource.getFeatures();
int count = results.size();
FeatureCollection collection = results;
FeatureIterator reader = results.features();
try {
while( reader.hasNext() ){
Feature feature = reader.next();
}
}
finally {
reader.close();
}
}
-
Search and replace:
- search: FeatureResults replace: FeatureCollection
-
Transition to:
- results.size(); // was results.getCount()
- results; // was results.collection()
- FeatureIterator // was FeatureReader
- results.features() // was results.reader()
You may need to remove IOException handling code.
Recommended Alternative (GeoTools 2.x Code)
You can also transition directly to use of java.util.Iterator; this will put you in better standing for the transition to GeoAPI FeatureCollection.
Iterator reader = results.iterator();
try {
while( reader.hasNext() ){
Feature feature = (Feature) reader.next();
}
}
finally {
results.close( reader );
}
}
- Transition to Iterator
- (Feature) reader.next(); // was reader.next();
- results.close( reader ); // was reader.close();
Transition to GridCoverageRenderer
It seems we did not meet our guidlines here and the GridCoveargeAPI has been moved and completly changed!
BEFORE (GeoTools 2.2 code)
import org.geotools.renderer.lite.GridCoverageRenderer;
...
GridCoverageRenderer renderer = new GridCoverageRenderer(gc, crs);
renderer.paint(graphics);
AFTER (GeoTools 2.3 code)
import org.geotools.renderer.lite.gridcoverage2d.GridCoverageRenderer;
...
GridCoverageRenderer renderer = new GridCoverageRenderer( viewportCRS, imageAreaBBox, paintArea );
StyleFactory factory = CommonFactoryFinder.getStyleFactory(null);
RasterSymbolizer rasterSymbolizer = factory.createRasterSymbolizer();
renderer.paint( destination, gc, rasterSymbolizer );