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