java - 如何使用 GeoTools 恢复内存中形状的特征?

标签 java datastore geotools

查看 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
}

最佳答案

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

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

关于java - 如何使用 GeoTools 恢复内存中形状的特征?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59948712/

相关文章:

java - 我在 'com/google/type/LatLng' 和 'com/google/protobuf/GeneratedMessage' 之间存在类型不匹配,并且无法说出原因

node.js - 从 Google Cloud Datastore 中删除实体

java - 使用 Java Topology Suite 或 GeoTools 解析 GeoJSON 文件

java - 如何将信封移动到特定点?

java - 在 map 上显示连接点的线 - 接收空 map

java - Feign 客户端在 Spring boot/Crawler4j 应用程序中总是抛出空指针异常

java - HTTPS/SSL POST 方法在开发者机器上工作,但在服务器上不工作 - java

java - 有谁知道如何在JAVA中使用iText创建两个并行表?

Java PhantomJSDriver 禁用控制台中的所有日志

python - 如何使用python和ndb模型循环以下数据存储数据并返回到json.dumps?