我有一个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
。我能做的是从InputStream
,MultipartFile
或getInputStream()
中获取getBytes()
。
是否有一种方法可以修改Shapefile
构造函数,使其接受InputStream
或字节表?我想避免创建一个临时文件。
谢谢您的建议。
MultiPartFile
是一个由多个部分发送的单个文件,MultiPartFile
是至少3个文件的集合,最多可能包含12个文件,这些文件具有相同的基本名称并具有各种扩展名,例如ShapeFile,[C0 ],.shp
,.shx
等
因此无法从.dbf
或字节集合构造.prj
对象,因为构造函数需要一次从3个文件读取以将几何(ShapeFile
)与属性(InputStream
)关联在一起索引和其他信息分散在其余文件中。