Added by jgarnett, last edited by jgarnett on Jul 10, 2008  (view change)

Labels

 

Working with GIS data can be difficulty, understanding the GeoTools library is also hard - DataUtilitis a facade classes which can help simplify common data wrangling chores.

References:

FeatureType Utilities

DataUtilities.createType

This is great for quickly whipping up a FeatureType when making test cases. The correct thing to do is breakout a FeatureBuilder, and call a bunch of methods.

If you just want to do something quickly try the following:

FeatureType lineType = DataUtilities.createType("LINE", "centerline:LineString,name:\"\",id:0");

I admit that looks a bit strange, you can also use a Java class names if it makes you happy:

FeatureType schema = DataUtilities.createType("EDGE", "edge:Polygon,name:String,timestamp:java.util.Date");

If you need to set the coordinate reference system as well:

FeatureType lineType = DataUtilities.createType("LINE", "centerline:LineString:srid=32615,name:\"\",id:0");

Now we don't want to see you writing code to build up your initial "definition" String, that means you are doing something general (and dynamic!) and should go figure out [SimpleFeatureTypeBuilder|03 SimpleFeatureTypeBuilder and SimpleFeatureBuilder.

DataUtilties.subType

There are actually a couple subType methods depending on how complicated you want to get.

FeatureType schema = DataUtilities.createType("EDGE", "edge:Polygon,name:String");
CoordinateReferenceSystem crs = CRS.decode( "EPSG:4326" );

schema = DataUtilities.subType( schema, null, crs );

You can also get a bit more complicated and choose exactly which attributes you want.

FeatureType schema = DataUtilities.createType("EDGE", "edge:Polygon,name:String,timestamp:java.util.Date");

schema = DataUtilities.subType( schema, new String[]{"edge","name"}, null );

DataUtilities.schema

You can use this method to quickly get a representation of a FeatureType:

System.out.println("FeatureType: " + DataUtilities.spec(featureType));

The representation is the same one used by createType above.

Features

DataUtilities.collection

DataUtilities has helper methods to turn almost anything into a FeatureCollection, this is really helpful when working with an API that expects a FeatureCollection.

Feature[] array;
...
return DataUtilties.collection( array );

Do be careful some of these implementations suck everything into memory! With GIS data sizes this will eventually break your application.

DataUtilities.reader

The FeatureReader API is on its way out (think Iterator<Feature> with IOExceptions), however DataUtilities sill lets you convert a perfectly good collection to this format.

FeatureCollection collection;

return DataUtilities.reader( collection );