gpt4 book ai didi

java - 从 Java 中的 InputStream 读取 ESRI shapefile

转载 作者:太空宇宙 更新时间:2023-11-04 09:12:36 24 4
gpt4 key购买 nike

我有一个 Web 应用程序,应该从用户的磁盘读取 shapefile。我使用 MultipartFile 类 ( https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/multipart/MultipartFile.html ) 来上传它。据我了解,不可能从 MultipartFile 恢复文件路径。这给我带来了一个问题,因为我使用以下代码来解释 shapefile 内容(我附加了至关重要的构造函数):

    private ShapeFile(final File srcFile) {
try {
final Map<String, Serializable> params = ImmutableMap.of("url", srcFile.toURI().toURL());
dataStore = new ShapefileDataStoreFactory().createDataStore(params);
final String typeName = dataStore.getTypeNames()[0];
featureType = dataStore.getSchema(typeName);
featureSource = dataStore.getFeatureSource(typeName);
} catch (IOException exception) {
throw new RuntimeException(exception);
}
}

shapefile 在构造函数中需要 File,并且 File 与文件的绝对路径严格关联。因此,我无法使用 MultipartFile 并基于此在内存中(即不在文件系统中)创建 File 。我能做的是从 MultipartFilegetInputStream()getBytes() 获取 InputStream

有没有办法修改 Shapefile 构造函数,使其接受 InputStream 或字节表?我想避免创建临时文件。

感谢您的建议。

最佳答案

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

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

关于java - 从 Java 中的 InputStream 读取 ESRI shapefile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59499090/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com