In the trajectory scenario, a spatio-temporal object is considered as a trajectory point, which contains the spatial location, time, and other attributes. In the HBase Ganos SDK, 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 contains an ID, Geometry, time information and other attributes. In the Quick start topic, the GanosClient class is encapsulated in the sample code to help you create 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:

SimpleFeatureType sft = .... ;
SimpleFeatureBuilder sfBuilder = new SimpleFeatureBuilder(sft);
builder.set("attribute name", attribute value);
 ...
builder.set("geom", Geometry);  // Create a spatial object. Keep the default format of the geom attribute name.
SimpleFeature feature = builder.buildFeature(object_id + "_" + date.getTime());
			

Create a Geometry object

When you create a SimpleFeature object, you need to create a geometry object, as shown in the preceding sample code. The Geometry is contained in the SimpleFeature object. The Geometry stores the spatial information of features. These features include Point, Line, and Plane features, which can be considered as trajectory points in the trajectory scenario. The GeoTools API provides the GeometryFactory class to help you create Geometry objects. You can create Geometry objects in the following ways:

  • Create a Geometry object by using a Coordinate object.

This object represents a coordinate point. We recommend that you set the Geometry object in this way.

  • Create a Geometry object by using Well-known text (WKT).

WKT is a text markup language that is used to specify spatial objects. For example, the string "POINT (1 1)" specifies a Point feature with coordinates 1, 1. The string "LINESTRING(0 2, 2 0, 8 6)" specifies a Line feature that is composed of three coordinates. The string "POLYGON((20 10, 30 0, 40 10, 30 20, 20 10))" specifies a Plane feature, and the first coordinate and last coordinate of which are the same and form a circle. For more information, visit https://en.wikipedia.org/wiki/Well-known_text.

  • Point feature

You can create Point features in the following ways:

  • Create a Point feature by using a Coordinate object.
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
Coordinate coord = new Coordinate(1, 1);
Point point = geometryFactory.createPoint(coord);
			
  • Create a Point feature by using WKT.
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
 WKTReader reader = new WKTReader(geometryFactory);
 Point point = (Point) reader.read("POINT (1 1)");
			
  • Line feature

You can create Line features in the following ways:

  • Create a Line feature by 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);
			
  • Create a Line feature by using WKT.
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
WKTReader reader = new WKTReader( geometryFactory );
LineString line = (LineString) reader.read("LINESTRING(0 2, 2 0, 8 6)");
			
  • Plane feature

You can create Plane features in the following ways:

  • Create a Plane feature by using 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 );
			
  • Create a Plane feature by 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))");
			

Configure other attributes

You can set other custom information by using the UserData column of the SimpleFeature. For example, HBase Ganos provides many built-in hints, as shown in the following section:

  • Disable an index. For more information, see the Create an index and Disable an index topics.
  • Use a custom FeatureID that saves the storage space.
SimpleFeature feature =...
feature.getUserData().put(Hints.USE_PROVIDED_FID, java.lang.Boolean.TRUE);