All Products
Search
Document Center

Create a spatio-temporal object

Last Updated: Jul 09, 2021

In spatio-temporal trajectory scenarios, a spatio-temporal object is considered as a trajectory point that contains the information about the spatial location, time, and other attributes. In Lindorm Ganos SDK, a spatio-temporal object is mapped to a SimpleFeature object. After you define the schema of a collection, you can create a SimpleFeature object.

Each SimpleFeature object consists of attributes, such as ID, Geometry, and time information. In the Quick start topic, the GanosClient class is encapsulated in the sample code to help you perform operations such as creating indexes and trajectory points. We recommend that you use the sample code to simplify coding. If you use the native GeoTools API, you can create a SimpleFeature object by using the SimpleFeatureBuilder class, as shown in the following sample code:

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);
builder.set("Attribute name", Attribute value);
builder.set("geom", Geometry);  // Create a spatial object. The attribute name is always geom.
SimpleFeature feature = builder.buildFeature(object_id + "_" + date.getTime());
            

Create a Geometry object

When you create a SimpleFeature object, you also need to create a Geometry object, as shown in the preceding sample code. The Geometry object is contained in the SimpleFeature object. The Geometry object stores the spatial information of features such as points, lines, and polygons. These features can be considered as trajectory points in spatio-temporal trajectory scenarios. The GeoTools API provides the GeometryFactory class to help you create Geometry objects. You can use one of the following methods to create a Geometry object:

  • Use a Coordinate object.

The Coordinate object represents a coordinate point. We recommend that you use this method.

  • Use well-known text (WKT).

WKT is a text markup language that is used to represent spatial objects. For example, the string "POINT (1 1)" represents a point whose coordinates are (1, 1). The string "LINESTRING(0 2, 2 0, 8 6)" represents a line that is composed of the three points represented by the following coordinates: (0 2), (2 0), (8 6). The string "POLYGON((20 10, 30 0, 40 10, 30 20, 20 10))" represents a polygon. The coordinates of the first point are the same the coordinates of the last point in this string. This way, a polygon is formed. For more information, visit https://en.wikipedia.org/wiki/Well-known_text.

Point

You can use one of the following methods to create a point:

  • Use a Coordinate object.

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

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

Line

You can use one of the following methods to create a line:

  • Use 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);        
  • Use WKT.

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

Polygon

You can create use one of the following methods to create a polygon:

  • Use a Coordinate object.

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;
Polygon polygon = geometryFactory.createPolygon(ring, holes );
  • Use 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))");

Configure other attributes

You can specify other custom information by using the UserData field of the SimpleFeature object. For example, Lindorm Ganos provides a wide range of built-in hints:

  • Use a custom feature ID to reduce storage consumption.

SimpleFeature feature =...
feature.getUserData().put(Hints.USE_PROVIDED_FID, java.lang.Boolean.TRUE);