Create spatiotemporal objects

Updated at:

In spatio-temporal trajectory scenarios, a spatio-temporal object represents a trajectory point that captures spatial location, time, and additional attributes. In the Lindorm GanosBase SDK, each spatio-temporal object maps to a SimpleFeature object, which consists of an ID, a Geometry, and time information.

The GanosClient class in the Quick start topic wraps index creation and feature insertion. Use GanosClient for typical scenarios, and the native GeoTools API only when you need direct control over feature construction.

How it works

SimpleFeature objects are built from a SimpleFeatureType that defines the schema, then populated using SimpleFeatureBuilder. Each feature holds:

Component Description
ID A unique identifier in the format object_id + "_" + date.getTime()
Geometry Spatial data (point, line, or polygon) stored in an attribute named geom
Time A Date attribute (for example, dtg) with temporal semantics
Additional attributes Any custom fields defined in the schema

Create a SimpleFeature

Define a schema spec string, then use SimpleFeatureBuilder to construct the feature.

// Schema spec format: "fieldName:Type[:options],..."
// Use SimpleFeatureTypes (GeoMesa class) rather than GeoTools DataUtilities —
// DataUtilities does not apply GeoMesa-specific spec options such as geomesa.logical.time
String spec = "name:String,dtg:Date,*geom:Point:srid=4326;geomesa.logical.time='false'";

SimpleFeatureType sft = SimpleFeatureTypes.createType("mySft", spec);

SimpleFeatureBuilder sfBuilder = new SimpleFeatureBuilder(sft);
sfBuilder.set("name", "trajectory-01");        // custom attribute
sfBuilder.set("dtg", new Date());              // time attribute
sfBuilder.set("geom", point);                  // spatial attribute — always named "geom"

// Feature ID format: object_id + "_" + timestamp
SimpleFeature feature = sfBuilder.buildFeature(objectId + "_" + date.getTime());

Create a Geometry object

A Geometry stores the spatial representation of a feature. Use JTSFactoryFinder.getGeometryFactory() to get a GeometryFactory, then create Point, LineString, or Polygon objects.

Two methods are available:

  • Coordinate object (recommended) — construct geometry programmatically using coordinate values

  • Well-known text (WKT) — parse geometry from a human-readable string

WKT quick reference

Geometry type WKT example
Point POINT (1 1)
LineString LINESTRING(0 2, 2 0, 8 6)
Polygon POLYGON((20 10, 30 0, 40 10, 30 20, 20 10))

For the full WKT specification, see Well-known text representation of geometry.

Point

Using a Coordinate object (recommended):

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
Coordinate coord = new Coordinate(1, 1);
Point point = geometryFactory.createPoint(coord);

Alternative — using WKT:

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
WKTReader reader = new WKTReader(geometryFactory);
Point point = (Point) reader.read("POINT (1 1)");

LineString

Using a Coordinate array (recommended):

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
Coordinate[] coords = new Coordinate[] {
    new Coordinate(0, 2),
    new Coordinate(2, 0),
    new Coordinate(8, 6)
};
LineString line = geometryFactory.createLineString(coords);

Alternative — using WKT:

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
WKTReader reader = new WKTReader(geometryFactory);
LineString line = (LineString) reader.read("LINESTRING(0 2, 2 0, 8 6)");

Polygon

Using a Coordinate array (recommended):

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
Coordinate[] coords = new Coordinate[] {
    new Coordinate(4, 0),
    new Coordinate(2, 2),
    new Coordinate(4, 4),
    new Coordinate(6, 2),
    new Coordinate(4, 0)   // first and last coordinates must match to close the polygon
};
LinearRing ring = geometryFactory.createLinearRing(coords);
LinearRing[] holes = null;
Polygon polygon = geometryFactory.createPolygon(ring, holes);

Alternative — using WKT:

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null);
WKTReader reader = new WKTReader(geometryFactory);
// First and last coordinate pairs must be identical to form a closed polygon
Polygon polygon = (Polygon) reader.read("POLYGON((20 10, 30 0, 40 10, 30 20, 20 10))");

Configure additional attributes

Attach custom metadata to a SimpleFeature using its UserData map. Lindorm GanosBase provides built-in hints through the Hints class.

Use a custom feature ID to reduce storage consumption:

SimpleFeature feature = sfBuilder.buildFeature(objectId + "_" + date.getTime());
feature.getUserData().put(Hints.USE_PROVIDED_FID, Boolean.TRUE);