Build SimpleFeature
HBase Ganos uses the SimpleFeature class to specify spatial features. Each SimpleFeature
consists of ID,Geometry object and other attributes. GeoTools API provides SimpleFeatureBuilder
classes to help users create SimpleFeature objects.
SimpleFeatureType sft = ....; SimpleFeatureBuilder sfBuilder = new SimpleFeatureBuilder(sft); builder.set("attribute name", attribute value); ... builder.set("geom", geometry); SimpleFeature feature = builder.buildFeature(object_id + "_" + date.getTime());
Note
When building SimpleFeature, Ganos generates a 128-bit UUID as the Feature ID by default.
In order to save storage space, users can specify their own ID. The following statement
can be used for specific methods.
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. For the definition of each spatial entity object of Geometry, please refer to Official documents.
The GeoTools API provides the GeometryFactory class to help you create Geometry objects.
You can create Geometry objects in the following ways:
- Point
- Use a Coordinate object.
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(); Coordinate coord = new Coordinate(1, 1); Point point = geometryFactory.createPoint(coord);
- Description by WKT: WKT(Well-known text) is a text markup language used to represent
the conversion between vector space objects, space reference systems and space reference
systems
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(); WKTReader reader = new WKTReader(geometryFactory); Point point = (Point) reader.read("POINT (1 1)");
- Use a Coordinate object.
- 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);
- Describe by 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
- 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 );
- Describe by 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.
Data insertion into ApsaraDB RDS
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
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();
- Batch insert SimpleFeature
HBase Ganos supports batch insertion of SimpleFeature through SimpleFeatureStore classes in GeoTools API.
List<SimpleFeature> features=... SimpleFeatureStore featureStore = (SimpleFeatureStore) ds.getFeatureSource(sft.getTypeName()); List<FeatureId> featureIds = featureStore.addFeatures(new ListFeatureCollection(sft,features));