@Override public GridCoverage2D getGridCoverage() { try { // There is a serious standardization failure around the axis order of WGS84. See issue #1930. // GeoTools assumes strict EPSG axis order of (latitude, longitude) unless told otherwise. // Both NED and SRTM data use the longitude-first axis order, so OTP makes grid coverages // for unprojected DEMs assuming coordinates are in (longitude, latitude) order. Hints forceLongLat = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE); GeoTiffFormat format = new GeoTiffFormat(); GeoTiffReader reader = format.getReader(path, forceLongLat); coverage = reader.read(null); LOG.info("Elevation model CRS is: {}", coverage.getCoordinateReferenceSystem2D()); } catch (IOException e) { throw new RuntimeException("Error getting coverage automatically. ", e); } return coverage; }
public void write(OutputStream outStream) { try { long t0 = System.currentTimeMillis(); GeoTiffWriteParams wp = new GeoTiffWriteParams(); wp.setCompressionMode(GeoTiffWriteParams.MODE_EXPLICIT); wp.setCompressionType("LZW"); ParameterValueGroup params = new GeoTiffFormat().getWriteParameters(); params.parameter(AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName().toString()).setValue(wp); new GeoTiffWriter(outStream).write(coverage, (GeneralParameterValue[]) params.values().toArray(new GeneralParameterValue[1])); //new GeoTiffWriter(outStream).write(coverage, null); //wasn't this line writing twice and trashing compressed version? long t1 = System.currentTimeMillis(); LOG.debug("wrote geotiff in {}msec", t1-t0); } catch (Exception e) { LOG.error("exception while preparing geotiff : {}", e.getMessage()); throw new WebApplicationException(e); } } };
public void writeGeotiff(String fileName, ResultSet results) { LOG.info("writing geotiff."); float[][] imagePixelData = new float[rows][cols]; for (int row = 0; row < rows; row++) { for (int col = 0; col < cols; col++) { int index = row * cols + col; float pixel = (float) (results.results[index]); if (unitySeconds > 0) pixel /= unitySeconds; imagePixelData[row][col] = pixel; } } GridCoverage2D coverage = new GridCoverageFactory().create("OTPAnalyst", imagePixelData, refEnvelope); try { GeoTiffWriteParams wp = new GeoTiffWriteParams(); wp.setCompressionMode(GeoTiffWriteParams.MODE_EXPLICIT); wp.setCompressionType("LZW"); ParameterValueGroup params = new GeoTiffFormat().getWriteParameters(); params.parameter(AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName().toString()).setValue(wp); GeoTiffWriter writer = new GeoTiffWriter(new File(fileName)); writer.write(coverage, (GeneralParameterValue[]) params.values().toArray(new GeneralParameterValue[1])); } catch (Exception e) { LOG.error("exception while writing geotiff.", e); } LOG.info("done writing geotiff."); }
public Format getFormat() { return new GeoTiffFormat(); }
/** @see org.opengis.coverage.grid.GridCoverageReader#getFormat() */ public Format getFormat() { return new GeoTiffFormat(); }
/** * Creates and returns a new instance of the <CODE>GeoTiffFormat</CODE> class if the required * libraries are present. If JAI and JAI Image I/O are not present, will throw an <CODE> * UnsupportedOperationException</CODE>. * * @return <CODE>GeoTiffFormat</CODE> object. * @throws UnsupportedOperationException if this format is unavailable. */ public AbstractGridFormat createFormat() { if (!isAvailable()) { throw new UnsupportedOperationException( "The GeoTiff plugin requires the JAI and JAI ImageI/O libraries!"); } return new GeoTiffFormat(); }
/** * @see org.opengis.coverage.grid.GridCoverageReader#getFormat() */ public Format getFormat() { return new GeoTiffFormat(); }
public Format getFormat() { return new GeoTiffFormat(); }
final GeoTiffFormat format = new GeoTiffFormat(); final GeoTiffWriteParams wp = new GeoTiffWriteParams();
final GeoTiffFormat format = new GeoTiffFormat(); final GeoTiffWriteParams wp = new GeoTiffWriteParams();
/** * Creates and returns a new instance of the <CODE>GeoTiffFormat</CODE> * class if the required libraries are present. If JAI and JAI Image I/O are * not present, will throw an <CODE>UnsupportedOperationException</CODE>. * * @return <CODE>GeoTiffFormat</CODE> object. * * @throws UnsupportedOperationException * if this format is unavailable. */ public AbstractGridFormat createFormat() { if (!isAvailable()) { throw new UnsupportedOperationException( "The GeoTiff plugin requires the JAI and JAI ImageI/O libraries!"); } return new GeoTiffFormat(); }
private void saveCoverage(IState state, File file, Iterable<IScale.Locator> locators) throws KlabException { SpaceExtent space = (SpaceExtent) state.getSpace(); if (space.getGrid() != null) { GridCoverage2D coverage = GISOperations.stateToCoverage(state, locators); if (coverage != null) { if (!file.toString().endsWith(".tif") && !file.toString().endsWith(".tiff")) { file = new File(file + ".tif"); } GridCoverageWriter writer = new GeoTiffFormat().getWriter(file); try { writer.write(coverage, null); } catch (Exception e) { throw new KlabIOException(e); } } } }
private void writeGeotiff(GeoTiffWriter geoTiffWriter, GridCoverage coverage){ GeoTiffFormat format = new GeoTiffFormat();
/** Write this grid out in GeoTIFF format */ public void writeGeotiff (OutputStream out) { try { float[][] data = new float[height][width]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { data[y][x] = (float) grid[x][y]; } } ReferencedEnvelope env = getMercatorEnvelopeMeters(); GridCoverage2D coverage = new GridCoverageFactory().create("GRID", data, env); GeoTiffWriteParams wp = new GeoTiffWriteParams(); wp.setCompressionMode(GeoTiffWriteParams.MODE_EXPLICIT); wp.setCompressionType("LZW"); ParameterValueGroup params = new GeoTiffFormat().getWriteParameters(); params.parameter(AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName().toString()).setValue(wp); GeoTiffWriter writer = new GeoTiffWriter(out); writer.write(coverage, params.values().toArray(new GeneralParameterValue[1])); writer.dispose(); out.close(); } catch (Exception e) { throw new RuntimeException(e); } }
@DescribeResult(name = "coverageLocation", description = "URL at which raster can be accessed") public URL execute( @DescribeParameter(name = "coverage", description = "Input raster") GridCoverage2D coverage) throws IOException { final File file = File.createTempFile(coverage.getName().toString(), ".tif", storage.getStorage()); // TODO check file prior to writing GeoTiffWriter writer = new GeoTiffWriter(file); // setting the write parameters for this geotiff final ParameterValueGroup params = new GeoTiffFormat().getWriteParameters(); params.parameter(AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName().toString()).setValue( DEFAULT_WRITE_PARAMS); final GeneralParameterValue[] wps = (GeneralParameterValue[]) params.values().toArray( new GeneralParameterValue[1]); try { writer.write(coverage, wps); } finally { try { writer.dispose(); } catch (Exception e) { // we tried, no need to fuss around this one } } return storage.getURL(file); }
/** Write this grid out in GeoTIFF format */ public void writeGeotiff (OutputStream out) { try { float[][] data = new float[height][width]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { data[y][x] = (float) grid[x][y]; } } ReferencedEnvelope env = getMercatorEnvelopeMeters(); GridCoverage2D coverage = new GridCoverageFactory().create("GRID", data, env); GeoTiffWriteParams wp = new GeoTiffWriteParams(); wp.setCompressionMode(GeoTiffWriteParams.MODE_EXPLICIT); wp.setCompressionType("LZW"); ParameterValueGroup params = new GeoTiffFormat().getWriteParameters(); params.parameter(AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName().toString()).setValue(wp); GeoTiffWriter writer = new GeoTiffWriter(out); writer.write(coverage, params.values().toArray(new GeneralParameterValue[1])); writer.dispose(); out.close(); } catch (Exception e) { throw new RuntimeException(e); } }
public void encode(OutputStream output) throws ServiceException, IOException { if (sourceCoverage == null) { throw new IllegalStateException("It seems prepare() has not been called" + " or has not succeed"); } final GeoTiffFormat format = new GeoTiffFormat(); final GeoTiffWriteParams wp = new GeoTiffWriteParams(); wp.setCompressionMode(GeoTiffWriteParams.MODE_EXPLICIT); wp.setCompressionType("LZW"); wp.setCompressionQuality(0.75F); wp.setTilingMode(GeoToolsWriteParams.MODE_EXPLICIT); wp.setTiling(256, 256); final ParameterValueGroup writerParams = format.getWriteParameters(); writerParams.parameter(AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName().toString()) .setValue(wp); GridCoverageWriter writer = format.getWriter(output); writer.write(sourceCoverage, (GeneralParameterValue[]) writerParams.values().toArray(new GeneralParameterValue[1])); writer.dispose(); this.sourceCoverage.dispose(false); this.sourceCoverage = null; } }
@DescribeResult(name = "coverageLocation", description = "URL at which raster can be accessed") public URL execute( @DescribeParameter(name = "coverage", description = "Input raster") GridCoverage2D coverage) throws IOException { String fileName = coverage.getName().toString() + ".tif"; final Resource resource = resources.getOutputResource(null, fileName); // setting the write parameters for this geotiff final ParameterValueGroup params = new GeoTiffFormat().getWriteParameters(); params.parameter(AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName().toString()) .setValue(DEFAULT_WRITE_PARAMS); final GeneralParameterValue[] wps = params.values().toArray(new GeneralParameterValue[1]); // TODO check file prior to writing try (OutputStream os = resource.out()) { GeoTiffWriter writer = new GeoTiffWriter(os); try { writer.write(coverage, wps); } finally { writer.dispose(); } } return new URL(resources.getOutputResourceUrl(fileName, "image/tiff")); } }
final GeoTiffFormat format = new GeoTiffFormat();
assertEquals("image/tiff;subtype=\"geotiff\"", response.getContentType()); GeoTiffFormat format = new GeoTiffFormat(); AbstractGridCoverage2DReader reader = format.getReader(getBinaryInputStream(response));