GeoTools provides a clear separation between:
References:
Comparison to Java:
| Java Class System | GeoTools Feature Model | Java Beans System |
|---|---|---|
| static type system | dynamic type system | dynamic type system |
| Object | SimpleFeature | Object |
| (reflection) | Attribute | (reflection) |
| (reflection) | GeometryAttribute | (reflection) |
| Class | SimpleFeatureType | BeanInfo |
| Field | AttributeDescriptor | PropertyDescriptor |
| Field | GeometryAttributeDescriptor | PropertyDescriptor |
| Method | OperationType | MethodDescriptor |
| Field.getType() | AttributeDescriptor.getType().getBinding() | PropertyDescriptor.getPropertyType() |
| Field.getName() | AttributeDescriptor.getName().getLocalName() | PropertyDescriptor.getName() |
| Field.get( obj ) | expression.evaulate( feature, Class ) | descriptor.getReadMethod().invoke(obj) |
Java example:
class Flag { public Point location; public String name; public int classification; public double height; }; GeometryFactory geomFactory = JTSFactoryFinder.getGeometryFactory(); Flag here = new Flag(); here.location = geomFactory.createPoint( new Coordinate(23.3,-37.2) ); here.name = "Here"; here.classification = 3; here.height = 2.0;
Feature example:
SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName( "Flag" ); b.setCRS( DefaultGeographicCRS.WGS84 ); b.add( "location", Point.class ); b.add( "name", String.class ); b.add( "classification", Integer.class ); b.add( "height", Double.class ); SimpleFeatureType type = b.buildFeatureType(); GeometryFactory geomFactory = JTSFactoryFinder.getGeometryFactory(); SimpleFeatureBuilder f = new SimpleFeatureBuilder( type ); f.add( geomFactory.createPoint( new Coordinate(23.3,-37.2) ) ); f.add("here"); f.add(3); f.add(2.0); SimpleFeature feature = f.buildFeature("fid.1");