Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Java-DataStoreFinder.getDataStore(connectParameters)中运行时从zip文件读取ESRI shapefile将返回null_Java_Null_Unzip_Geotools - Fatal编程技术网

在Java-DataStoreFinder.getDataStore(connectParameters)中运行时从zip文件读取ESRI shapefile将返回null

在Java-DataStoreFinder.getDataStore(connectParameters)中运行时从zip文件读取ESRI shapefile将返回null,java,null,unzip,geotools,Java,Null,Unzip,Geotools,我们正在构建一项服务,用于上载包含ESRI形状文件的zip文件。该服务应该能够读取shapefile并处理其内容。因此,我构建了一个类,将zip文件解压缩到临时文件夹(System.getProperty(“java.io.tmpdir”)的子文件夹) 另一个类从解压类调用解压方法,然后尝试使用Geotools读取解压后的shapefile。它使用Geotools DataStoreFinder.getDataStore(Map params)方法从解压缩的shapefile创建数据存储。这里出

我们正在构建一项服务,用于上载包含ESRI形状文件的zip文件。该服务应该能够读取shapefile并处理其内容。因此,我构建了一个类,将zip文件解压缩到临时文件夹(System.getProperty(“java.io.tmpdir”)的子文件夹)

另一个类从解压类调用解压方法,然后尝试使用Geotools读取解压后的shapefile。它使用Geotools DataStoreFinder.getDataStore(Map params)方法从解压缩的shapefile创建数据存储。这里出现了问题:getDataStore方法返回null。我测试了网址,看起来不错。从中派生URL的文件是一个文件,应用程序可以读取该文件(使用shapefile.exists()、shapefile.isFile()、shapefile.canRead()进行测试)。那么,有什么不对呢?为什么要返回null

以下是(相关)代码:

导入java.io.File;
导入java.io.IOException;
导入java.net.URL;
导入java.util.HashMap;
导入java.util.HashSet;
导入java.util.Map;
导入java.util.Set;
导入org.geotools.data.DataStore;
导入org.geotools.data.DataStoreFinder;
导入org.geotools.data.FeatureSource;
导入org.geotools.feature.FeatureCollection;
导入org.geotools.feature.FeatureIterator;
导入org.opengis.feature.simple.SimpleFeature;
导入org.opengis.feature.simple.SimpleFeatureType;
导入com.geodan.equis.entity.dataset.BasicFeature;
导入com.geodan.equs.exception.equsexception;
导入com.geodan.equs.processor.equsprocessor;
导入com.geodan.util.io.UnzipUtils;
导入com.lividsolutions.jts.geom.Geometry;
公共类ShapefileProcessor实现EqualProcessor
{
私有静态最终文件临时解压目录=新文件(
System.getProperty(“java.io.tmpdir”)+File.separator
+“atlas_temp_unzip_dir”);
公共静态集导入功能(最终文件zipFile)
抛出EqualException
{
//检查输入文件是否具有zipfile扩展名
如果(!zipFile.getName().endsWith(“.zip”))
{
抛出新的EqualException(
“该文件不是zipfile。无法处理。”);
}
//解压缩文件
尝试
{
解压(zipFile,TEMP_unzip_DIR);
}
捕获(IOException错误)
{
抛出新的EqualException(“zipfile无法解压缩。”,错误);
}
//验证解压缩的文件夹是否包含shapefile并返回它
文件shapefile=新文件(“”);
尝试
{
shapefile=findShapefile(临时解压目录);
}
捕获(IOException错误)
{
抛出新的EqualException(
“zipfile不包含形状文件。无法处理其内容。”,
误差);
}
//从shapefile中收集特征并将其放入迭代器中
特征迭代器特征迭代器;
尝试
{
featureIterator=readShapefile(shapefile);
}
捕获(相等例外e)
{
抛出新的EqualException(e.getMessage(),e);
}
//在FeatureIterator中创建一个填充了要素的集合
设置要素=createFeatureSet(要素迭代器);
返回特性;
}
私有静态文件findShapefile(文件解压缩路径)引发IOException
{
文件shapefile=新文件(“”);
//在解压文件夹中查找第一个.shp文件
File[]unzippedFiles=unzipPath.listFiles();
对于(int i=0;i
虽然您的代码似乎正确,但我发现我们的代码库中关键行的实现略有不同:

Map<String, Object> map = new HashMap<>();
map.put(ShapefileDataStoreFactory.URLP.key, url);
map.put(ShapefileDataStoreFactory.CREATE_SPATIAL_INDEX.key, Boolean.TRUE);
DataStore shapefileStore = DataStoreFinder.getDataStore(map);
Map Map=newhashmap();
map.put(ShapefileDataStoreFactory.URLP.key,url);
map.put(ShapefileDataStoreFactory.CREATE\u SPATIAL\u INDEX.key,Boolean.TRUE);
DataStore shapefileStore=DataStoreFinder.getDataStore(map);

只需像这样使用
ShapefileDataStore
的构造函数即可:

// URL url = file.toURI().toURL();
DataStore shapefileStore = new ShapefileDataStore(url)
你的代码是正确的
// URL url = file.toURI().toURL();
DataStore shapefileStore = new ShapefileDataStore(url)
DataStore shapefileStore = new ShapefileDataStore(url)
Iterator availableStores =  DataStoreFinder.getAvailableDataStores();