| Upgrade to 2.3 | Upgrade to 2.4 | Upgrade to 2.5 |
|---|
The following is needed when upgrading to 2.5:
- Transition to JTSFactory
- Transition to GeoAPI ProgressListener
- Transition to GeoAPI SimpleFeature
- Transition to GeoAPI AttributeType and AttributeDescriptor
- Transition to Name and FeatureSource.getName()
- Transition to Generics in DataStore API
- DataStore: works only with SimpleFeature capable implementations
- DataAccess: works both with SimpleFeature and normal Feature capable implementations
Transition to JTSFactory
BEFORE:
GeometryFactory factory = new FactoryFinder.getGeometryFactory( null );
AFTER:
GeometryFactory factory = new JTSFactoryFinder.getGeometryFactory( null );
Transition to GeoAPI ProgressListener
Before (GeoTools 2.2 Code)
progress.setDescription( message );
After (GeoTools 2.4 Code)
progress.setTask( new SimpleInternationalString( message ) );
- Search Replace
Search Replace import org.geotools.util.ProgressListener import org.opengis.util.ProgressListener - Update
- setTask( new SimpleInternationalString( message ) ); // was setDescription( message );
Transition to GeoAPI SimpleFeature
We have (finally) made the move to an improved feature model. Please take the opportunity to change your existing code
to use org.opengis.feature.simple.SimpleFeature. The existing GeoTools Feature interface is still in use; but it has been updated in place to extend SimpleFeature.
Before (GeoTools 2.4 Code)
import org.geotools.feature.FeatureType; ... CoordianteReferenceSystem crs = CRS.decode("EPSG:4326"); final AttributeType GEOM = AttributeTypeFactory.newAttributeType("Location",Point.class,true, null,null,crs ); final AttributeType NAME = AttributeTypeFactory.newAttributeType("Name",String.class, true ); final FeatureType FLAG = FeatureTypeFactory.newFeatureType(new AttributeType[] { GEOM, NAME },"Flag"); Feature flag1 = FLAG.create( "flag.1", new Object[]{ point, "Here" } ); AttributeType attributes[] = FLAG.getAttributeTypes(); AttributeType location = FLAG.getAttribute("Location"); String label = location.getName(); Class binding = location.getType(); Geometry geom = flag1.getDefaultGeometry();
After (GeoTools 2.5 Code)
import org.opengis.feature.simple.SimpleFeatureType; ... SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.setName( "Flag" ); builder.setNamespaceURI( "http://localhost/" ); builder.setCRS( "EPSG:4326" ); builder.add( "Location", Point.class ); builder.add( "Name", String.class ); SimpleFeatureType FLAG = builder.buildFeatureType(); SimpleFeature flag1 = SimpleFeatureBuilder.build( FLAG, new Object[]{ point, "Here"}, "flag.1" ); List<AttributeDescriptor> attributes = FLAG.getAttributes(); AttributeDescriptor location = FLAG.getAttribute("Location"); String label = location.getLocationName(); Class binding = location.getType().getBinding(); Geometry geom = (Geometry) flag1.getDefaultGeometry();
- Search Replace
Search Replace \bFeature\b SimpleFeature \bFeatureType\b SimpleFeatureType - Fix the imports
- Control-Shift-O in Eclipse IDE
- Add casts as required for getDefaultGeometry()
For more code examples please see:
Transition to GeoAPI AttributeType and AttributeDescriptor
The concept of an AttributeType has been split into two now (allowing you to reuse common types).
BEFORE (GeoTools 2.4 Code)
import org.geotools.feature.AttributeType; ... GeometryAttributeType att = (GeometryAttributeType) AttributeTypeBuilder.newAttributeDescriptor( geomTypeName, targetGeomType, isNillable, Integer.MAX_VALUE, Collections.EMPTY_LIST, crs );
AFTER (GeoTools 2.5 Code)
import org.geotools.feature.AttributeTypeBuilder; import org.opengis.feature.type.AttributeDescriptor ... AttributeTypeBuilder build = new AttributeTypeBuilder(); build.setName( geomTypeName ); build.setBinding( targetGeomType ); build.setNillable(true); build.setCRS(crs); GeometryType type = build.buildGeometryType(); GeometryDescriptor attribute = build.buildDescriptor( geomTypeName, type );
Transition to Name and FeatureSource.getName()
BEFORE (GeoTools 2.4 Code)
DataStore ds = ... String []typeNames = ds.getTypeNames(); SimpleFeatureType type = ds.getSchema(typeNames[0]); assert type.getTypeName() == typeNames[0]; FeatureSource source = ds.getFeatureSource(type.getTypeName());
AFTER (GeoTools 2.5 Code)
import org.opengis.feature.type.Name; ... DataStore ds = ... List<Name> featureNames = ds.getNames(); SimpleFeatureType type = ds.getSchema(featureNames.get(0)); // type.getName() may or may not be equal to featureNames.get(0), assume not. If they're its just an implementation detail. FeatureSource source = ds.getFeatureSource(featureNames.get(0));
Transition to Generics in DataStore API
BEFORE (GeoTools 2.4 Code)
DataStore ds = ... FeatureSource source = ds.getSource(typeName); FeatureStore store = (FeatureStore)source; FeatureLocking locking = (FeatureLocking)source; FeatureCollection collection = source.getFeatures(); FeatureIterator features = collection.features(); while(features.hasNext){ SimpleFeature feature = features.next(); } Transaction transaction = Transaction.AUTO_COMMIT; FeatureReader reader = ds.getFeatureReader(new DefaultQuery(typeName), transaction); FeatureWriter writer = ds.getFeatureWriter(typeName, transaction);
AFTER (GeoTools 2.5 Code)
DataStore: works only with SimpleFeature capable implementations
import org.opengis.feature.type.Name; ... java.util.Map paramsMap = ... DataStore ds = DataStoreFinder.getDataStore(paramsMap); Name featureName = new org.geotools.feature.Name(namespace, localName); FeatureSource<SimpleFeatureType, SimpleFeature> source = ds.getSource(featureName); FeatureStore<SimpleFeatureType, SimpleFeature> store = (FeatureStore)source; FeatureLocking<SimpleFeatureType, SimpleFeature> locking = (FeatureLocking)source; FeatureCollection<SimpleFeatureType, SimpleFeature> collection = source.getFeatures(); FeatureIterator<SimpleFeature> features = collection.features(); while(features.hasNext){ SimpleFeature feature = features.next(); } Transaction transaction = Transaction.AUTO_COMMIT; FeatureReader<SimpleFeatureType, SimpleFeature> reader = ds.getFeatureReader(new DefaultQuery(typeName), transaction); FeatureWriter<SimpleFeatureType, SimpleFeature> writer = ds.getFeatureWriter(typeName, transaction);
DataAccess: works both with SimpleFeature and normal Feature capable implementations
import org.opengis.feature.FeatureType; import org.opengis.feature.Feature; import org.opengis.feature.type.Name; ... java.util.Map paramsMap = ... DataAccess<FeatureType, Feature> ds = DataAccessFinder.getDataAccess(paramsMap); Name featureName = new org.geotools.feature.Name(namespace, localName); FeatureSource<FeatureType, Feature> source = ds.getSource(featureName); FeatureStore<FeatureType, Feature> store = (FeatureStore)source; FeatureLocking<FeatureType, Feature> locking = (FeatureLocking)source; FeatureCollection<FeatureType, Feature> collection = source.getFeatures(); FeatureIterator<Feature> features = collection.features(); while(features.hasNext){ Feature feature = features.next(); } //No DataAccess.getFeatureReader/Writer, respecting the layered architecture, will need to use //DataAccess.getFeatureSource().getFeatureReader() instead (waiting for Justins proposal though) //Transaction transaction = Transaction.AUTO_COMMIT; //FeatureReader<FeatureType, Feature> reader = ds.getFeatureReader(new DefaultQuery(typeName), transaction); //FeatureWriter<FeatureType, Feature> writer = ds.getFeatureWriter(typeName, transaction);


