In spatio-temporal trajectory scenarios, a spatio-temporal object is considered as a trajectory point that contains information about the spatial location, time, and other attributes. In the SDK provided by ApsaraDB for HBase Ganos (HBase Ganos), a spatio-temporal object is mapped to a SimpleFeature object. After you define the schema of an index table, you can create a SimpleFeature object.

Create a SimpleFeature object

Each SimpleFeature object consists of ID, geometry, time, and other attribute information. In the sample code provided in the Quick start topic, the GanosClient class is encapsulated to help you perform operations such as creating indexes and trajectory points. We recommend that you use the sample code. This helps you 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:
SimpleFeatureType sft = ....;
SimpleFeatureBuilder sfBuilder = new SimpleFeatureBuilder(sft);
builder.set("Attribute name", Attribute value);
 ...
builder.set("geom", Geometry);  // Create a spatial object. Set the attribute name to 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 objects such as points, lines, and polygons. These objects 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.

    A 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, POINT (1 1) represents a point whose coordinates are (1, 1). LINESTRING(0 2, 2 0, 8 6) represents a line that is composed of three points. The points are represented by the following coordinates: (0, 2), (2, 0), (8, 6). POLYGON((20 10, 30 0, 40 10, 30 20, 20 10)) represents a polygon. In this string, the coordinates of the first point are the same as the coordinates of the last point. This way, a polygon is formed. For more information, see Well-known text representation of geometry.

  • Point
    You can use one of the following methods to create a point:
    1. Use a Coordinate object.
      GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
      Coordinate coord = new Coordinate(1, 1);
      Point point = geometryFactory.createPoint(coord);          
    2. 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:
    1. 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);            
    2. 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 use one of the following methods to create a polygon:
    1. 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; // use LinearRing[] to represent holes
      Polygon polygon = geometryFactory.createPolygon(ring, holes );            
    2. 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 in the UserData field of a SimpleFeature object. HBase Ganos provides built-in hints. For example, you can use the FeatureID hint. This can help you save storage space.
SimpleFeature feature =...
feature.getUserData().put(Hints.USE_PROVIDED_FID, java.lang.Boolean.TRUE);