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