从Java的InputStream中读取ESRI shapefile

问题描述 投票:1回答:1

我有一个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。我能做的是从InputStreamMultipartFilegetInputStream()中获取getBytes()

是否有一种方法可以修改Shapefile构造函数,使其接受InputStream或字节表?我想避免创建一个临时文件。

谢谢您的建议。

java spring shapefile geotools
1个回答
0
投票

MultiPartFile是一个由多个部分发送的单个文件,MultiPartFile是至少3个文件的集合,最多可能包含12个文件,这些文件具有相同的基本名称并具有各种扩展名,例如ShapeFile,[C0 ],.shp.shx

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

© www.soinside.com 2019 - 2024. All rights reserved.