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
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
- 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:
- 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)");
- Use a Coordinate object.
- 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)");
- Use a Coordinate object.
- Polygon
You can 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; // use LinearRing[] to represent holes 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))");
- Use a Coordinate object.
Configure other attributes
SimpleFeature feature =...
feature.getUserData().put(Hints.USE_PROVIDED_FID, java.lang.Boolean.TRUE);