@Override public void createIndividuals() { LOG.info("Loading population from raster file {}", sourceFilename); try { File rasterFile = new File(sourceFilename); // determine file format and CRS, then load raster AbstractGridFormat format = GridFormatFinder.findFormat(rasterFile); AbstractGridCoverage2DReader reader = format.getReader(rasterFile); GridCoverage2D coverage = reader.read(null); this.coverageCRS = coverage.getCoordinateReferenceSystem(); GridGeometry2D gridGeometry = coverage.getGridGeometry(); GridEnvelope2D gridEnvelope = gridGeometry.getGridRange2D(); gridGeometry.getGridToCRS(); // because we may want to produce an empty raster rather than loading one, alongside the coverage we // store the row/col dimensions and the referenced envelope in the original coordinate reference system. this.cols = gridEnvelope.width; this.rows = gridEnvelope.height; this.createIndividuals0(); } catch (Exception ex) { throw new IllegalStateException("Error loading population from raster file: ", ex); } LOG.info("Done loading raster from file."); }
@Override public GridCoverage2D read(String coverageName, GeneralParameterValue[] parameters) throws IllegalArgumentException, IOException { // Default implementation for backwards compatibility if (coverageName.equalsIgnoreCase(this.coverageName)) { return read(parameters); } // Subclasses should do more checks on coverageName throw new IllegalArgumentException( "The specified coverageName " + coverageName + "is not supported"); }
.andReturn(new AffineTransform2D(gridToWorld)) .anyTimes(); expect(reader.read(EasyMock.anyObject(GeneralParameterValue[].class))).andReturn(null); expect(reader.getGridCoverageNames()).andReturn(new String[] {"TheCoverage"}); replay(reader);
public static GridCoverage2D openGridCoverage(File gridFile) { GridCoverage2D gc2D = null; // Reading the coverage through a file AbstractGridFormat format = GridFormatFinder.findFormat(gridFile); try { AbstractGridCoverage2DReader reader = format.getReader(gridFile); gc2D = reader.read(null); } catch (IllegalArgumentException e) { LOGGER.log(Level.FINE, e.getMessage(), e); } catch (IOException e) { LOGGER.log(Level.FINE, e.getMessage(), e); } catch (Exception e) { LOGGER.log(Level.FINE, e.getMessage(), e); } return gc2D; }
@Override public Object decode(InputStream input) throws Exception { // in order to read a grid coverage we need to first store it on disk File root = new File(System.getProperty("java.io.tmpdir", ".")); File f = File.createTempFile("wps", "tiff", root); FileOutputStream os = null; try { os = new FileOutputStream(f); IOUtils.copy(input, os); } finally { IOUtils.closeQuietly(os); } // and then we try to read it as a geotiff AbstractGridFormat format = GridFormatFinder.findFormat(f); if (format instanceof UnknownFormat) { throw new WPSException( "Could not find the GeoTIFF GT2 format, please check it's in the classpath"); } return format.getReader(f).read(null); }
@Override public Object decode(InputStream input) throws Exception { // in order to read a grid coverage we need to first store it on disk File root = new File(System.getProperty("java.io.tmpdir", ".")); File f = File.createTempFile("wps", "tiff", root); FileOutputStream os = null; try { os = new FileOutputStream(f); IOUtils.copy(input, os); } finally { IOUtils.closeQuietly(os); } // and then we try to read it as a geotiff AbstractGridFormat format = GridFormatFinder.findFormat(f); if (format instanceof UnknownFormat) { throw new WPSException( "Could not find the GeoTIFF GT2 format, please check it's in the classpath"); } return format.getReader(f).read(null); }
coverage = (GridCoverage2D) reader.read(readParams); } else { System.arraycopy(readParams, 0, readParams2, 0, length); readParams2[length] = readGGParam; coverage = (GridCoverage2D) reader.read(readParams2); coverage = (GridCoverage2D) reader.read(new GeneralParameterValue[] { readGGParam }); } else if(readGG != null) { coverage = (GridCoverage2D) reader.read(new GeneralParameterValue[] { readGGParam }); } else { coverage = (GridCoverage2D) reader.read(null);
@Override protected ICoverage readData() throws KlabException { if (coverage == null) { AbstractGridCoverage2DReader reader = _format.getReader(_file); try { RasterCoverage ret = new RasterCoverage(id, reader.read(null)); ((AbstractRasterCoverage)ret).setNodataValue(noData); return ret; } catch (Exception e) { throw new KlabUnsupportedOperationException("file " + _file + " cannot be read or does not have a supported raster format"); } } return coverage; }
gc = reader.read(null); RenderedImage image = gc.getRenderedImage();
gc = (GridCoverage2D) inReader.read(null); } catch (IOException e) { LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
/** * Creates the rgb style. * * @param reader the reader * @param raster the raster * @return the style */ private Style createRGBStyle(AbstractGridCoverage2DReader reader, WritableRaster raster) { RasterSymbolizer sym = sf.getDefaultRasterSymbolizer(); GridCoverage2D cov = null; try { cov = reader.read(null); } catch (IOException giveUp) { throw new RuntimeException(giveUp); } // We need at least three bands to create an RGB style int numBands = cov.getNumSampleDimensions(); if (numBands < 3) { createRGBImageSymbol(sym, cov, raster); } else { createRGBChannelSymbol(sym, cov, numBands); } return SLD.wrapSymbolizers(sym); }
private boolean renewCachedCoverage(DirectPosition centrePos) { final Rectangle queryRect = createQueryGridEnvelope(centrePos); if (queryRect.isEmpty()) { return false; } final AbstractGridCoverage2DReader reader = sourceRef.get(); GeneralParameterValue parameter = new Parameter( AbstractGridFormat.READ_GRIDGEOMETRY2D, new GridGeometry2D(new GridEnvelope2D(queryRect), reader.getOriginalGridToWorld(PixelInCell.CELL_CENTER), reader.getCrs())); try { cachedCoverage = (GridCoverage2D) reader.read(new GeneralParameterValue[]{parameter}); return cachedCoverage != null; } catch (Exception ex) { throw new RuntimeException(ex); } }
@Override protected SpatialFile newSpatialFile(File f, DataFormat format) { if (format instanceof GridFormat) { Granule g = new Granule(super.newSpatialFile(f, format)); //process the granule try { AbstractGridCoverage2DReader r = ((GridFormat)format).gridReader(g); try { //get the envelope GridCoverage2D cov = r.read(null); g.setEnvelope(cov.getEnvelope2D()); g.setGrid(cov.getGridGeometry()); cov.dispose(false); //compute time stamp g.setTimestamp(timeHandler.computeTimestamp(g)); return g; } finally { if (r != null) { r.dispose(); } } } catch (Exception e) { LOGGER.log(Level.WARNING, "Could not read file " + f + ", unable to get coverage info"); } } return super.newSpatialFile(f, format); }
@Override protected SpatialFile newSpatialFile(File f, DataFormat format) { if (format instanceof GridFormat) { Granule g = new Granule(super.newSpatialFile(f, format)); // process the granule try { AbstractGridCoverage2DReader r = ((GridFormat) format).gridReader(g); try { // get the envelope GridCoverage2D cov = r.read(null); g.setEnvelope(cov.getEnvelope2D()); g.setGrid(cov.getGridGeometry()); cov.dispose(false); // compute time stamp g.setTimestamp(timeHandler.computeTimestamp(g)); return g; } finally { if (r != null) { r.dispose(); } } } catch (Exception e) { LOGGER.log( Level.WARNING, "Could not read file " + f + ", unable to get coverage info"); } } return super.newSpatialFile(f, format); }
gc = (GridCoverage2D) reader.read(new GeneralParameterValue[] { tileSizeParam }); if (listener != null) { writeParameters
parameters.put(AbstractGridFormat.READ_GRIDGEOMETRY2D.getName().toString(), destinationGridGeometry); coverage = (GridCoverage2D) reader.read(CoverageUtils.getParameters(reader.getFormat() .getReadParameters(), parameters, true)); if ((coverage == null) || !(coverage instanceof GridCoverage2D)) {
new GridGeometry2D(new GeneralGridRange(destinationSize), destinationEnvelopeInSourceCRS)); final GridCoverage coverage = coverageReader.read(CoverageUtils.getParameters( coverageReader.getFormat().getReadParameters(), parameters, true));