全部产品

写入时空对象

更新时间:2019-08-12 10:02:01

写入时空对象

在索引表创建完成、时空对象创建完成后,即可调用数据写入接口将数据写入到HBase Ganos中。

单条记录写入

HBase Ganos通过GeoTools API中的SimpleFeatureWriter写入单条数据,SimpleFeatureWriter支持事务,可以通过DataStore的getFeatureWriterAppend方法获取。

  1. SimpleFeatureType sft = ....;
  2. SimpleFeatureWriter writer=(SimpleFeatureWriter)ds.getFeatureWriterAppend(sft.getTypeName(), Transaction.AUTO_COMMIT);
  3. SimpleFeature toWrite=writer.next();
  4. toWrite.setAttributes(feature.getAttributes());
  5. toWrite.getUserData().putAll(feature.getUserData());
  6. writer.write();
  7. writer.close();

批量写入

HBase Ganos支持批量插入SimpleFeature,通过GeoTools API中的SimpleFeatureStore类实现:

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

可参考「快速入门」章节中的代码示例