Create spatiotemporal objects
In a trajectory scenario, a spatiotemporal object is a trajectory point with a spatial location, a timestamp, and other properties. In the HBase Ganos SDK, a spatiotemporal object maps to a SimpleFeature. Define the index schema before creating objects.
Build a SimpleFeature
Each SimpleFeature consists of an ID, a Geometry object, time information, and other properties. To create a spatiotemporal object, you need to:
Build a SimpleFeature using SimpleFeatureBuilder
Create Geometry objects (point, line, and polygon) using either a Coordinate object or a Well-Known Text (WKT) string
Set non-geometry properties on the feature
The Quick Start example encapsulates the GanosClient class, which handles index creation and trajectory point creation. To use the native GeoTools API directly, build a SimpleFeature with SimpleFeatureBuilder:
SimpleFeatureType sft = ....;
SimpleFeatureBuilder sfBuilder = new SimpleFeatureBuilder(sft);
builder.set("property_name", property_value);
...
builder.set("geom", Geometry); // Set the spatial object. "geom" is a fixed name.
SimpleFeature feature = builder.buildFeature(object_id + "_" + date.getTime());
Set the Geometry object
A Geometry object stores the spatial information for a SimpleFeature. In a trajectory scenario, a feature represents a trajectory point and can be a point, a line, or a polygon. Use the GeoTools GeometryFactory utility class to create Geometry objects.
Two methods are available for all feature types:
-
Coordinate object (recommended)
Construct a Coordinate object with explicit x and y values, then pass it to GeometryFactory. This method gives precise programmatic control over coordinates.
-
WKT string
Well-Known Text (WKT) is a text markup language for representing spatial objects. For example,
"POINT (1 1)"is a point at (1, 1),"LINESTRING(0 2, 2 0, 8 6)"is a line through three coordinate points, and"POLYGON((20 10, 30 0, 40 10, 30 20, 20 10))"is a polygon where the first and last coordinates are identical to form a closed ring. For more information, see this article. -
Point feature
-
Using a Coordinate object:
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)");
-
-
Line feature
-
Using a Coordinate object:
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(); Coordinate[] coords = new Coordinate[] {new Coordinate(0, 2), new Coordinate(2, 0), new Coordinate(8, 6) }; LineString line = geometryFactory.createLineString(coordinates); -
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 feature
-
Using a Coordinate object — the first and last coordinates must be identical to close the ring:
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) }; LinearRing ring = geometryFactory.createLinearRing( coords ); LinearRing holes[] = null; // use LinearRing[] to represent holes Polygon polygon = geometryFactory.createPolygon(ring, holes ); -
Alternative — using WKT:
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory( null ); WKTReader reader = new WKTReader( geometryFactory ); Polygon polygon = (Polygon) reader.read("POLYGON((20 10, 30 0, 40 10, 30 20, 20 10))");
-
Set other properties
SimpleFeature feature =...
feature.getUserData().put(Hints.USE_PROVIDED_FID, java.lang.Boolean.TRUE);