Model¶
GeoTools provides a clear separation between:
data model -
feature
responsible for holding valuesquery model -
filter
andexpression
used to select content and drill in and retrieve valuesmetadata model -
feature type
describing contents in sufficient details for validation and query construction
References:
gt-main feature code examples
gt-main filter code examples
Comparison to Java:
The data structure Feature is used to hold information. Each Feature “belongs to” a
FeatureType
which is used to describe valid contents. This is a dynamic type system becauseFeatureType
is a data structure we can define at runtime.The data structure Object is used to hold information. Each Object “belongs to” a Class which is used to describe valid contents. This is a static type system because Class is a data structure we need to compile before the application is started.
Java Class System |
GeoTools Feature Model |
Java Beans System |
---|---|---|
static type system |
dynamic type system |
dynamic type system |
|
|
Object |
(reflection) |
|
(reflection) |
(reflection) |
|
(reflection) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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");