Import spatiotemporal data into HBase Ganos using the GeoTools API: build a SimpleFeature, attach a Geometry object, and write it to the store as a single record or a bulk insert.
Build a SimpleFeature
HBase Ganos represents each spatial feature as a SimpleFeature — an object that holds an ID, a Geometry object, and typed properties. Use SimpleFeatureBuilder from the GeoTools API to construct one:
SimpleFeatureType sft = ....;
SimpleFeatureBuilder builder = new SimpleFeatureBuilder(sft);
builder.set("property_name", propertyValue);
...
builder.set("geom", Geometry);
SimpleFeature feature = builder.buildFeature(object_id + "_" + date.getTime());
By default, Ganos generates a 128-bit universally unique identifier (UUID) as the feature ID. To use a custom ID instead and save storage space, set the USE_PROVIDED_FID hint before writing:
SimpleFeature feature = ...
feature.getUserData().put(Hints.USE_PROVIDED_FID, java.lang.Boolean.TRUE);
Create a Geometry object
Each SimpleFeature carries one Geometry object that describes the spatial location or shape. For the full specification of Geometry spatial entity objects, see Geometry.
Use GeometryFactory from the GeoTools API to create Geometry objects. Two construction methods are available for each geometry type: from a Coordinate object or from well-known text (WKT). WKT is a text markup language for representing vector geometry, spatial reference systems, and coordinate transforms.
-
Point features
-
From a Coordinate object:
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(); Coordinate coord = new Coordinate(1, 1); Point point = geometryFactory.createPoint(coord); -
From WKT:
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(); WKTReader reader = new WKTReader(geometryFactory); Point point = (Point) reader.read("POINT (1 1)");
-
-
Line features
-
From 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(coords); -
From WKT:
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(); WKTReader reader = new WKTReader(geometryFactory); LineString line = (LineString) reader.read("LINESTRING(0 2, 2 0, 8 6)");
-
-
Polygon features
-
From 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); -
From 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))");
-
Write features to the store
HBase Ganos writes features through SimpleFeatureWriter from the GeoTools API. SimpleFeatureWriter supports transactions; obtain a writer via the getFeatureWriterAppend method on DataStore.
-
Insert a single SimpleFeature:
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(); -
Bulk insert SimpleFeatures using
SimpleFeatureStore:List<SimpleFeature> features = ... SimpleFeatureStore featureStore = (SimpleFeatureStore) ds.getFeatureSource(sft.getTypeName()); List<FeatureId> featureIds = featureStore.addFeatures(new ListFeatureCollection(sft, features));