Added by jgarnett, last edited by jgarnett on Dec 07, 2007  (view change)

Labels

 
(None)

The GeoTools "feature model" was replaced in GeoTools 2.4, prior versions of GeoTools made use of:

  • org.geotools.feature.Feature
  • org.geotools.feature.FeatureType
  • org.geotools.feature.FeatureTypeFactory
  • org.geotools.feature.AttributeTypeFactory

These classes and constructs are very old, and predate the common use of patterns and modern naming conventions. You will find that FeatureTypeFactory is actually a Builder, and although AttributeTypeFactory should allow you to substitute different implementation in practise it is a singleton and locked down to produce the following:

  • org.geotools.feature.DefaultFeature

CurrentDocumentation

Creating a FeatureType

CoordianteReferenceSystem crs = CRS.decode("EPSG:4326");
final AttributeType GEOM = AttributeTypeFactory.newAttributeType("Location",Point.class,true, null,null,crs );
final AttributeType ID = AttributeTypeFactory.newAttributeType("ID",Integer.class, false, 14, 0 );
final AttributeType NAME = AttributeTypeFactory.newAttributeType("Name",String.class, true );

final FeatureType FLAG = FeatureTypeFactory.newFeatureType(new AttributeType[] { GEOM, ID, NAME },"Flag");

Creating a Feature

Feature feature = featureType.create( new Object[]{ new Point( 0 , 0 ), 12, "My Name" );

Using FeatureType to determine CRS

FeatureType schema = feature.getFeatureType();
GeometryAttribtueType geomType = featureType.getDefaultGeometry();

CoordinateReferenceSystem crs = geomType.getCoordinateReferenceSystem();