1

I'm having a weird situation. 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

Geek Junior
  • 137
  • 4
  • 11
  • 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 08 '18 at 13:51
  • does tomcat have write permission to `java.io.tempdir`? – Ian Turton Aug 08 '18 at 22:00
  • 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 09 '18 at 06:54
  • Geotools unpacks the epsg database there – Ian Turton Aug 09 '18 at 06: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 09 '18 at 15:02

2 Answers2

1

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); with

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 :)

Geek Junior
  • 137
  • 4
  • 11
1

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.

Ian Turton
  • 10,018
  • 1
  • 28
  • 47