HBase Ganos uses the SimpleFeature class to specify spatial features. Each SimpleFeature class contains an ID, a Geometry object, and other properties. The GeoTools API provides the SimpleFeatureBuilder class to help users create SimpleFeature objects.

Build a SimpleFeature class

SimpleFeatureType sft = .... ;
SimpleFeatureBuilder sfBuilder = new SimpleFeatureBuilder(sft);
builder.set("property name", property value);
 ...
builder.set("geom", Geometry);
SimpleFeature feature = builder.buildFeature(object_id + "_" + date.getTime());

Note: When you create a SimpleFeature class, HBase Ganos generates a 128-bit UUID as the default Feature ID. To save storage space, you can run the following command to define your own Feature ID:

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

Create a Geometry object

Each SimpleFeature contains a Geometry object, which indicates the spatial object of a feature. The following figure shows the Entity Relationship Diagram (ER) of various Geometry spatial objects. For more information, visit http://docs.geotools.org/stable/userguide/library/jts/geometry.html.

The GeoTools API provides the GeometryFactory class to help you create Geometry objects. You can create Geometry objects in the following ways:

  • The Point feature. Method 1: Create a Geometry object by using a Coordinate object.
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
Coordinate coord = new Coordinate(1, 1);
Point point = geometryFactory.createPoint(coord);

Method 2: Create a Geometry object by using the Well-known text (WKT). The WKT is a text markup language that is used to specify vector spatial objects, spatial referencing systems, and the transformation between spatial reference systems. For more information, visit https://en.wikipedia.org/wiki/Well-known_text.

 GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
 WKTReader reader = new WKTReader(geometryFactory);
 Point point = (Point) reader.read("POINT (1 1)");
  • The LineString feature. Method 1: Create a Geometry object 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);

Method 2: Create a Geometry object by using the WKT.

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
WKTReader reader = new WKTReader( geometryFactory );
LineString line = (LineString) reader.read("LINESTRING(0 2, 2 0, 8 6)");
  • The Polygon feature. Method 1: Create a Geometry object 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 );

Method 2: Create a Geometry object by using the 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))");

2. Write data in the database

HBase Ganos writes data by using the SimpleFeatureWriter class in the GeoTools API. SimpleFeatureWriter supports transactions and can be built by calling the getFeatureWriterAppend method of DataStore.

  • Insert a single SimpleFeature structure:
SimpleFeatureType sft = .... ;
SimpleFeatureWriter writer=(SimpleFeatureWriter)ds.getFeatureWriterAppend(sft.getTypeName(), Transaction.AUTO_COMMIT);
SimpleFeature toWrite=writer.next();
toWrite.setAttributes(feature.getAttributes());
toWrite.getUserData().putAll(feature.getUserData());
writer.write();
writer.close();
  • Insert multiple SimpleFeature structures:

HBase Ganos allows you to insert multiple SimpleFeature structures at a time. You can use the SimpleFeatureStore class of the GeoTools API to implement this operation:

List<SimpleFeature> features=...
SimpleFeatureStore featureStore = (SimpleFeatureStore) ds.getFeatureSource(sft.getTypeName());
List<FeatureId> featureIds = featureStore.addFeatures(new ListFeatureCollection(sft,features));