如何在OpenShift中访问形状文件



我在OpenShift中部署的jar中有shapefiles。我可以使用"File sourceFile = new ClassPathResource("src/main/resources/countryborders .shp). getfile ();"从我的本地环境访问这些文件。然而,在OpenShift中,我的服务抱怨找不到它。我已经尝试过InputStream,但我在IDE中得到一个错误,因为该文件不是文本文件。下面是我的代码:

File sourceFile = new ClassPathResource("src/main/resources/CountryBoundaries.shp").getFile();
FileDataStore store = FileDataStoreFinder.getDataStore(sourceFile);
featureSource = store.getFeatureSource();
GeometryDescriptor geomDesc = featureSource.getSchema().getGeometryDescriptor();
attrName = geomDesc.getLocalName();

我错过了什么?我将感谢任何帮助,因为我已经为此挣扎了很长一段时间了。谢谢。

我找到了一个解决方案,将URL更改为URI,然后执行toURL()。见下文:

URI sourceFile = new ClassPathResource("PoliticalSubdivisionBoundaries.shp").getURI();
FileDataStore store = FileDataStoreFinder.getDataStore(sourceFile.toURL());
featureSource = store.getFeatureSource(); 
GeometryDescriptor geomDesc = featureSource.getSchema().getGeometryDescriptor();
attrName = geomDesc.getLocalName(); 

希望这对将来的人有所帮助。Shapefiles是复杂的,不能像使用inputStream等通常的方式访问。干杯!

最新更新