private File localReproject( WcsReaderRequest request, File containingDirectory, String baseFilename) throws NoSuchAuthorityCodeException, FactoryException, IOException { InputStream input = null; File tmpFile = null; try { BoundWcsRequest geotiffRequest = request.bind(_wcsUrl).withFormat("geotiff"); BoundWcsRequest requestNativeFormat = geotiffRequest.withCRS(geotiffRequest.getNativeCRSs().iterator().next()); requestNativeFormat.assertLegalSize(_maxCoverageExtractionSize); input = requestNativeFormat.getCoverage(); File file = null; file = new File(containingDirectory, baseFilename + "." + request.fileExtension()); LOG.debug("Writing GridCoverage obtained from " + _wcsUrl + " to file " + file); tmpFile = File.createTempFile(baseFilename, ".tif"); writeToFile(tmpFile, input); transformCoverage(tmpFile, file, request, requestNativeFormat, true); return file; } finally { if (tmpFile != null) FileUtils.delete(tmpFile); if (input != null) IOUtils.closeQuietly(input); } }
private BoundWcsRequest negotiateResponseCRS(BoundWcsRequest request) throws IOException { Set<String> crss = request.getSupportedResponseCRSs(); // Hack. It will work so long as backing servers // are GeoServers if (crss.isEmpty() && request.getNativeCRSs().isEmpty()) return request; if (!crss.contains(request.getResponseEpsgCode())) { String newCrs = "EPSG:4326"; if (request.getNativeCRSs().isEmpty()) { Iterator<String> crsIter = crss.iterator(); if (!crss.contains(newCrs) && crsIter.hasNext()) { newCrs = crsIter.next(); } else { } } else { newCrs = request.getNativeCRSs().iterator().next(); } return request.withCRS(newCrs); } return request; }