【问题标题】:How to recover features of a shape in memory using GeoTools?如何使用 GeoTools 恢复内存中形状的特征?
【发布时间】:2020-01-28 22:50:24
【问题描述】:

查看 geotools 快速入门后:https://docs.geotools.org/latest/userguide/tutorial/quickstart/intellij.html

它显示了使用以下代码恢复形状特征的示例:

File file = new File("myfile.shp");

FileDataStore store = FileDataStoreFinder.getDataStore(file);
SimpleFeatureSource featureSource = store.getFeatureSource();
FeatureCollection collection = featureSource.getFeatures();

FeatureIterator iterator = collection.features();

但是,此代码依赖于 File。在我的真实项目中,形状内容以字节数组的形式提供给我,我无法创建临时文件。那么,如何访问功能?

这是我目前的代码

public static Map<String,Vector<String>> getAllPropsValues(byte[] fileContent){
   //Some other code here

   DataStore store = DataStoreFinder.getDataStore(fileContent); //<-- how to replace this line
   SimpleFeatureSource featureSource = store.getFeatureSource();
   FeatureCollection collection = featureSource.getFeatures();

   FeatureIterator iterator = collection.features();

   //other things here
}

【问题讨论】:

标签: java datastore geotools


【解决方案1】:

ShapeFile 是至少 3 个,可能最多 12 个文件的集合,这些文件共享一个共同的基本名称并具有各种扩展名,例如 .shp、.shx、.dbf、.prj 等。

因此不可能从 InputStream 或字节集合构造 ShapeFile 对象,因为构造函数需要一次读取 3 个文件以使用索引和其他信息将几何 (.shp) 与属性 (.dbf) 联系起来分散在其余文件中。

【讨论】:

    猜你喜欢
    • 2018-03-06
    • 1970-01-01
    • 2014-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多