猿问

无法使用 tomcat 获得 CRS:

我有一个奇怪的情况。我使用 geotools 来投影栅格,例如它的工作原理


CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:3857");


GridCoverage2D projectedImage = (GridCoverage2D) Operations.DEFAULT.resample(gridCoverageImage,

                        targetCRS);

现在我使用完全相同的代码将我的进程移到了 Web 服务器控制器中:


public ResponseEntity<InputStreamResource> getProjectedImage(@RequestParam 

String filename, @RequestParam String targetCrs){

     File file = new File(filename);

     CoordinateReferenceSystem targetCRS = CRS.decode(targetCrs);

     /** Some process to return file /**

}

我有:


org.opengis.referencing.NoSuchAuthorityCodeException: No code "EPSG:3857"

from authority "EPSG" found for object of type "EngineeringCRS"

我的 pom.xml


   <dependency>

        <groupId>org.geotools</groupId>

        <artifactId>gt-shapefile</artifactId>

        <version>18.2</version>

    </dependency>

    <dependency>

        <groupId>org.geotools</groupId>

        <artifactId>gt-epsg-hsql</artifactId>

        <version>18.2</version>

    </dependency>   

    <dependency>

        <groupId>org.geotools</groupId>

        <artifactId>gt-coverage</artifactId>

        <version>18.2</version>

    </dependency>     

    <dependency>

        <groupId>org.geotools</groupId>

        <artifactId>gt-geotiff</artifactId>

        <version>18.2</version>

    </dependency>   

    <dependency>

        <groupId>org.geotools</groupId>

        <artifactId>gt-image</artifactId>

        <version>18.2</version>

    </dependency>

    <dependency>

        <groupId>org.geotools</groupId>

        <artifactId>gt-wms</artifactId>

        <version>18.2</version>

    </dependency> 

当我查看 WEB-INF/lib 时,所有 jar 都在这里,包括依赖项(gt-reference、gt-metadata .....)


Tomcat:8.0 Java 8 地理工具:18.2


当我不在 servlet 容器中时它工作正常。此外,来自 geotools 的其他实用程序运行良好。例如,裁剪或 GridCoverage2D 转换在这个 servlet 容器中工作。


你能帮我理解发生了什么吗?


慕勒3428872
浏览 463回答 2
2回答

波斯汪

您的问题很可能是 Tomcat(或运行它的用户)没有写入权限,java.io.tmpdir这是 GeoTools 在第一次查找 EPSG 代码时将 H2 EPSG 数据库解压到的地方。您可以更改临时目录的权限以允许 tomcat 在那里写入,或者您可以通过更改或 中的CATALINA_TMPDIR变量来更改它使用的位置,或者简单地添加到您的启动脚本中。catalina.shcatalina.batDjava.io.tmpdir=c:\{yourDir}这个问题也有一些可能有帮助的答案。

开心每一天1111

我找到了一个解决方法,即使它不能解决最初的问题(与 geotools 的依赖关系和部署到 Tomcat 中有关)不要使用 gt-epsg-hsql,这会导致您的应用搜索 EPSG 代码以解码到 HSQL 数据库中。而不是CRS.decode(targetCrs); 与CRS.parseWKT("PROJCS[\"WGS 84 / Plate Carree (deprecated)\",\r\n" +&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "&nbsp; &nbsp; GEOGCS[\"WGS 84\",\r\n" +&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "&nbsp; &nbsp; &nbsp; &nbsp; DATUM[\"WGS_1984\",\r\n" +&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SPHEROID[\"WGS 84\",6378137,298.257223563,\r\n" +&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AUTHORITY[\"EPSG\",\"7030\"]],\r\n" +&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AUTHORITY[\"EPSG\",\"6326\"]],\r\n" +&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "&nbsp; &nbsp; &nbsp; &nbsp; PRIMEM[\"Greenwich\",0,\r\n" +&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AUTHORITY[\"EPSG\",\"8901\"]],\r\n" +&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "&nbsp; &nbsp; &nbsp; &nbsp; UNIT[\"degree\",0.0174532925199433,\r\n" +&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AUTHORITY[\"EPSG\",\"9122\"]],\r\n" +&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "&nbsp; &nbsp; &nbsp; &nbsp; AUTHORITY[\"EPSG\",\"4326\"]],\r\n" +&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "&nbsp; &nbsp; PROJECTION[\"Equirectangular\"],\r\n" +&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "&nbsp; &nbsp; UNIT[\"metre\",1,\r\n" +&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "&nbsp; &nbsp; &nbsp; &nbsp; AUTHORITY[\"EPSG\",\"9001\"]],\r\n" +&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "&nbsp; &nbsp; AXIS[\"X\",EAST],\r\n" +&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "&nbsp; &nbsp; AXIS[\"Y\",NORTH],\r\n" +&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "&nbsp; &nbsp; AUTHORITY[\"EPSG\",\"32662\"]]");您可以在此处找到与每个 EPSG 代码相关的所有 WKT如果有人对原始问题有答案或解释,我很乐意阅读它:)
随时随地看视频慕课网APP

相关分类

Java
我要回答