相关文章推荐
温暖的遥控器  ·  Python | ...·  1 年前    · 
潇洒的硬币  ·  node.js报错 ...·  2 年前    · 
小胡子的酱牛肉  ·  scrapy ...·  2 年前    · 
多情的烈酒  ·  解决: ...·  2 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams I use geotools to project rasters and it works for example

CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:3857");
GridCoverage2D projectedImage = (GridCoverage2D) Operations.DEFAULT.resample(gridCoverageImage,
                        targetCRS);

Now I moved my process in a web server controller with the exact same code :

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 /**

I'm having :

org.opengis.referencing.NoSuchAuthorityCodeException: No code "EPSG:3857"
from authority "EPSG" found for object of type "EngineeringCRS"

My 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> 

When I look into WEB-INF/lib, all jars are here including dependencies (gt-referencing, gt-metadata.....)

Tomcat : 8.0 Java 8 GeoTools : 18.2

It works fine when I'm not in a servlet container. Also, other utilities from geotools are working fine. For example, the cropping or the GridCoverage2D conversion work in this servlet container.

Could you please help me understand what's going on?

Thanks in advance

Any Idea ? I tried with different calls Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE); CRSAuthorityFactory factory = ReferencingFactoryFinder.getCRSAuthorityFactory("EPSG", hints); And then CoordinateReferenceSystem targetCRS = factory.createGeographicCRS(responseCrs.trim()); ==> Same Error – Geek Junior Aug 8, 2018 at 13:51 Yes it does, can you explain why would that be an issue ? and the relation between epsg-hsql and java.io.tempdir ? thanks – Geek Junior Aug 9, 2018 at 6:54 Thanks for your reply sir. Actually, after investigations it does not. So it maybe the problem comes from here. I tested with a File.createTempFile(...) and I have Access Denied Would you know how to make it default that tomcat can access java.io.tmpdir ? Thanks in advance – Geek Junior Aug 9, 2018 at 15:02

Your issue is most likely that Tomcat (or the user running it) doesn't have write permission to java.io.tmpdir which is where GeoTools unpacks the H2 EPSG database to when it first looks up an EPSG code.

You can either change the permissions on the temp directory to allow tomcat to write there or you can change the location it uses by changing the CATALINA_TMPDIR variable in catalina.sh or catalina.bat, or simply add Djava.io.tmpdir=c:\{yourDir} to your startup script.

This question also has some answers that may help.

I found a workaround even if it doesn't solve the initial issue (related to dependencies of geotools and the deployement into Tomcat)

don't use gt-epsg-hsql which leads your app searching for the EPSG code to decode into the HSQL database.

Rather than using CRS.decode(targetCrs);

CRS.parseWKT("PROJCS[\"WGS 84 / Plate Carree (deprecated)\",\r\n" + 
                "    GEOGCS[\"WGS 84\",\r\n" + 
                "        DATUM[\"WGS_1984\",\r\n" + 
                "            SPHEROID[\"WGS 84\",6378137,298.257223563,\r\n" + 
                "                AUTHORITY[\"EPSG\",\"7030\"]],\r\n" + 
                "            AUTHORITY[\"EPSG\",\"6326\"]],\r\n" + 
                "        PRIMEM[\"Greenwich\",0,\r\n" + 
                "            AUTHORITY[\"EPSG\",\"8901\"]],\r\n" + 
                "        UNIT[\"degree\",0.0174532925199433,\r\n" + 
                "            AUTHORITY[\"EPSG\",\"9122\"]],\r\n" + 
                "        AUTHORITY[\"EPSG\",\"4326\"]],\r\n" + 
                "    PROJECTION[\"Equirectangular\"],\r\n" + 
                "    UNIT[\"metre\",1,\r\n" + 
                "        AUTHORITY[\"EPSG\",\"9001\"]],\r\n" + 
                "    AXIS[\"X\",EAST],\r\n" + 
                "    AXIS[\"Y\",NORTH],\r\n" + 
                "    AUTHORITY[\"EPSG\",\"32662\"]]");

You can find all WKT related to every EPSG code here

If someone has an answer or an explanation to the original issue, i'd love to read it :)

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.