GeoTools : FM DataStore Port Guide

Copy DataStore Plug-in from Trunk

In order to minimize missing out on improvments and bug fixes from trunk, before beginning a data store port you should copy the latest and greatest version from trunk.

Icon

Be sure to make that trunk itself is in sync with the current stable branch (2.2.x) before proceeding. This can be done by either emailing the list and asking or checking the version control logs.

You can copy over the plugin with the following svn commands.

[~/devel/geotools/fm/plugin]% svn remove shapefile
[~/devel/geotools/fm/plugin]% svn commit -m "grabbing up to data copy from trunk" .
[~/devel/geotools/fm/plugin]% svn copy -m "porting to fm branch" http://svn.geotools.org/geotools/trunk/gt/plugin/shapefile http://svn.geotools.org/geotools/branches/fm/plugin
[~/devel/geotools/fm/plugin]% svn update .

Get the Plug-in to Compile

The first task is getting code to compile. If you are keen on TDD (Test Driven Development) you will start with tests. (smile). Here are some guidelines and tips that will help.

org.geotools.feature

The org.geotools.feature interfaces are now gone and replaced with org.opengis.feature and org.opengis.feature.type. So references to the old Feature and FeatureType can pretty much be replaced mechanically.

FeatureType

As stated above org.geotools.feature.FeatureType has been removed and placed with org.opengis.feature.FeatureType. In the new model, the old FeatureType best maps to org.opengis.feature.simple.SimpleFeatureType. The following table maps the methods across. In some cases no such mapping exists so the alternative is listed.

FeatureType

SimpleFeatureType

Alternative

getTypeName()

getName().getLocalPart()

getNamespace()

getName().getNamespaceURI()

isDescendedFrom(URI,String)

(error)

Types.isSuperType(AttributeType,AttributeType)

isDescendedFrom(FeatureType)

(error)

Types.isSuperType(AttributeType,AttributeType)

isAbstract()

(tick)

getAnscestors()

getSuper()

getDefaultGeometry()

defaultGeometry()

getAttributeCount()

getNumberOfAttributes()

getAttributeType(String)

get(String)

find(AttributeType)

(error)

find(String)

(error)

getAttributeType(int)

get(int)

getAttributeTypes()

types()

hasAttributeType(String)

(error)

get(String) != null

duplicate(Feature)

(error)

SimpleFeatures.duplicate(SimpleFeature,SimpleFeature)

create(Object[])

(error)

SimpleFeatures.create(SimpleFeatureType,Object[],String

create(Object[], String)

(error)

SimpleFeatures.create(SimpleFeatureType,Object[],String)

Feature

Similar to FeatureType, org.geotools.feature.Feature maps to org.opengis.feature.simple.SimpleFeature.

Feature

SimpleFeature

Alternative

getParent()

(error)

 

setParent(FeatureCollection

(error)

 

getFeatureType()

getType()

 

getID()

(tick)

 

getAttributes(Object[])

values()

 

getAttribute(String)

get(String)

 

getAttribute(int)

get(int)

 

setAttribute(String,Object)

set(String,Object)

 

setAttribute(int,Object)

set(int,Object)

 

getNumberOfAttributes()

(tick)

 

getDefaultGeometry()

defaultGeometry()

 

setDefaultGeometry(Geometry)

defaultGeometry(Object)

 

getBounds()

(tick)

 

FeatureType Creation

Creating feature types is done with SimpleFeatureTypeBuilder.

TypeFactory factory = ...

SimpleTypeBuilder builder = new SimpleTypeBuilder( factory );
builder.setName( "myType" );
builder.setNamespaceURI( "http://mynamespace" );
builder.add( "the_geom" , Point.class );
builder.add( "foo" , Integer.class );
builder.add( "bar" , String.class );

SimpleFeatureType type = builder.simple();

Feature Creation

Creating features is done with SimpleFeatureBuilder

TypeFactory factory = ...
SimpleFeatureType type = ...

SimpleFeatureBuilder builder = new SimpleFeatureBuilder( factory );
builder.setType( type );
builder.add( new Point( 1,1 ) );
builder.add( new Integer( 1 ) );
builder.add( "one" );

SimpleFeature feature = (SimpleFeatureType) builder.build( "fid" );

org.geotools.data

DataStore

The datastore api has mostly maintained backwards compatability. The changes have to do with naming. Methods that accepted a String to reference a FeatureType, no accept a TypeName.

DataStore
  /**
  * @deprecated use {@link #getSchema(TypeName)}
  */
  FeatureType getSchema(String typeName) throws IOException;

 /**
  * Retreive FeatureType metadata by <code>typeName</code>.
  * <br>
  * <p>
  * Retrieves the Schema information as a FeatureType object.
  * </p>
  *
  * @param typeName The qualified name of the type.
  * 
  * @return FeatureType for the provided typeName
  * 
  * @throws IOException If typeName cannot be found
  */
  FeatureType getSchema(TypeName typeName) throws IOException;

AbstractDataStore

The above methods referencing FeatureType by a single String have been deprecated and finalized. So any subclasses of AbstractDataStore are broken and must convert the internal name storage to the TypeName system.