@SuppressWarnings("PMD.SystemPrintln") public static void printImage(RenderedImage renderedImage) { RectIter rectIter = RectIterFactory.create(renderedImage, null); do { do { double value = rectIter.getSampleDouble(); System.out.print(value + " "); } while (!rectIter.nextPixelDone()); rectIter.startPixels(); } while (!rectIter.nextLineDone()); } }
/** * Creates a {@code WritableRectIter} for the specified source and destination rasters. * The given rectangle must be in the bounds of both rasters (this will not be verified). * * @param src The source raster. * @param dst The destination raster. * @param bounds The region of the rasters to iterate over. * @return An iterator that read sample from {@code src} and write sample to {@code dst}. * It will be an instance of {@code TransfertRectIter} if and only if the source * and destination rasters are not the same. * * @since 3.00 */ public static WritableRectIter create(Raster src, WritableRaster dst, Rectangle bounds) { WritableRectIter iter = RectIterFactory.createWritable(dst, bounds); if (src != dst) { iter = new TransfertRectIter(RectIterFactory.create(src, bounds), iter); } return iter; }
create( name, (min == null || max == null) ? RectIterFactory.create(raster, null) : null, raster.getSampleModel(), min,
/** * Creates a {@code WritableRectIter} for the specified source and destination images. * The given rectangle must be in the bounds of both images (this will not be verified). * * @param src The source image. * @param dst The destination image. * @param bounds The region of the images to iterate over. * @return An iterator that read samples from {@code src} and write samples to {@code dst}. * It will be an instance of {@code TransfertRectIter} if and only if the source * and destination images are not the same. * * @since 3.00 */ public static WritableRectIter create(RenderedImage src, WritableRenderedImage dst, Rectangle bounds) { if (dst instanceof BufferedImage) { /* * BufferedImage are always backed by a single raster. Consequently we are better to * delegate the work to create(RenderedImage, WritableRaster, Rectangle), which will * detects if the source uses the same raster than the destination. */ return create(src, ((BufferedImage) dst).getRaster(), bounds); } WritableRectIter iter = RectIterFactory.createWritable(dst, bounds); if (src != dst) { iter = new TransfertRectIter(RectIterFactory.create(src, bounds), iter); } return iter; }
create( name, RectIterFactory.create(image, null), image.getSampleModel(), null,
/** * Creates a {@code WritableRectIter} for the specified source image and destination raster. * The given rectangle must be in the bounds of both arguments (this will not be verified). * * @param src The source image. * @param dst The destination raster. * @param bounds The region of the image or raster to iterate over. * @return An iterator that read samples from {@code src} and write samples to {@code dst}. * It will be an instance of {@code TransfertRectIter} if and only if the source * and destination rasters are not the same. * * @since 3.00 */ public static WritableRectIter create(RenderedImage src, WritableRaster dst, Rectangle bounds) { final Raster tile = uniqueTile(src, bounds); if (tile == dst) { return create(tile, dst, bounds); } return new TransfertRectIter(RectIterFactory.create(src, bounds), RectIterFactory.createWritable(dst, bounds)); }
public RasterAsPointFeatureIterator(final RasterAsPointFeatureCollection fc) { // checks Utilities.ensureNonNull("fc", fc); // get elements this.fc = fc; this.fb = new SimpleFeatureBuilder(fc.getSchema()); this.size = fc.size; // create an iterator that only goes forward, it is the fastest one iterator = RectIterFactory.create(fc.gc2d.getRenderedImage(), null); // // start the iterator // iterator.startLines(); if (iterator.finishedLines()) { throw new NoSuchElementException("Index beyond size:" + index + ">" + size); } iterator.startPixels(); if (iterator.finishedPixels()) { throw new NoSuchElementException("Index beyond size:" + index + ">" + size); } // appo temp = new double[fc.numBands]; // grid convergence angle manager if (fc.gridConvergenceAngleCorrectionNeeded) { sourceCRSPosition = new DirectPosition2D(); targetCRSPosition = new DirectPosition2D(fc.targetCRS); } }
bounds.y = iy - top; final RectIter iter = RectIterFactory.create(image.getExtendedData(bounds, this.borderExtender), bounds); boolean[][] gaps = hasNoData ? new boolean[samples.length][samples[0].length] : null; for (; band < bandUp; band++) {
bounds.y = iy - top; final RectIter iter = RectIterFactory.create(image.getExtendedData(bounds, this.borderExtender), bounds); boolean[][] gaps = hasNoData ? new boolean[samples.length][samples[0].length] : null; for (; band < bandUp; band++) {
bounds.y = iy - top; final RectIter iter = RectIterFactory.create(image.getExtendedData(bounds, this.borderExtender), bounds); boolean[][] gaps = hasNoData ? new boolean[samples.length][samples[0].length] : null; for (; band < bandUp; band++) {
public RectIter create(RenderedImage image, Rectangle bounds) { if (image == null) { throw new IllegalArgumentException("image must not be null"); } if (bounds == null || bounds.isEmpty()) { return null; } return RectIterFactory.create(image, bounds); }
/** * Write the raster to file. * * @throws IOException */ private void writeRaster() throws IOException { // we need to cobble rasters of the same row together in order to // respect the way our writer works. final RectIter iterator = RectIterFactory.create(inputRenderedImage, null); // writing final Double noDataDouble = new Double(rasterWriter.getNoData()); final String noDataMarker = rasterWriter.getNoDataMarker(); rasterWriter.writeRaster(iterator, noDataDouble, noDataMarker); }
create(name, (min==null || max==null) ? RectIterFactory.create(raster, null) : null, raster.getSampleModel(), min, max, units, colors, dst, hints); return dst;
public RasterAsPointFeatureIterator(final RasterAsPointFeatureCollection fc) { //checks Utilities.ensureNonNull("fc", fc); //get elements this.fc= fc; this.fb = new SimpleFeatureBuilder(fc.getSchema()); this.size=fc.size; // create an iterator that only goes forward, it is the fastest one iterator= RectIterFactory.create(fc.gc2d.getRenderedImage(), null); // //start the iterator // iterator.startLines(); if(iterator.finishedLines()) throw new NoSuchElementException("Index beyond size:"+index+">"+size); iterator.startPixels(); if(iterator.finishedPixels()) throw new NoSuchElementException("Index beyond size:"+index+">"+size); // appo temp= new double[fc.numBands]; }
public void visit(GridCoverage2D inputCoverage, Integer bandIndex) { reset(); PlanarImage inputImage = (PlanarImage) inputCoverage.getRenderedImage(); RectIter readIter = RectIterFactory.create(inputImage, inputImage.getBounds()); readIter.startLines(); while (!readIter.finishedLines()) { readIter.startPixels(); while (!readIter.finishedPixels()) { double sampleValue = readIter.getSampleDouble(bandIndex); visit(Double.valueOf(sampleValue)); readIter.nextPixel(); } readIter.nextLine(); } }
public CoverageToPointFeatureIterator(GridCoverage2D coverage, int bandIndex, String valueField, boolean retainNoData, SimpleFeatureType schema) { this.bandIndex = bandIndex; this.valueField = valueField; this.retainNoData = retainNoData; this.noData = RasterHelper.getNoDataValue(coverage); this.builder = new SimpleFeatureBuilder(schema); this.typeName = coverage.getName().toString(); this.pixelType = RasterHelper.getTransferType(coverage); this.trans = new GridTransformer(coverage.getGridGeometry()); GridGeometry2D gridGeometry2D = coverage.getGridGeometry(); AffineTransform gridToCRS = (AffineTransform) gridGeometry2D.getGridToCRS2D(); width = Math.abs(gridToCRS.getScaleX()) / 2.0; height = Math.abs(gridToCRS.getScaleY()) / 2.0; PlanarImage inputImage = (PlanarImage) coverage.getRenderedImage(); this.readIter = RectIterFactory.create(inputImage, inputImage.getBounds()); this.bounds = inputImage.getBounds(); currentRow = 0; rowCount = inputImage.getHeight(); this.readIter.startLines(); }
public CoverageToPointFeatureIterator(GridCoverage2D coverage, int bandIndex, String valueField, boolean retainNoData, SimpleFeatureType schema) { this.bandIndex = bandIndex; this.valueField = valueField; this.retainNoData = retainNoData; this.noData = RasterHelper.getNoDataValue(coverage); this.builder = new SimpleFeatureBuilder(schema); this.typeName = coverage.getName().toString(); this.pixelType = RasterHelper.getTransferType(coverage); this.trans = new GridTransformer(coverage.getGridGeometry()); PlanarImage inputImage = (PlanarImage) coverage.getRenderedImage(); this.bounds = inputImage.getBounds(); this.readIter = RectIterFactory.create(inputImage, bounds); currentRow = 0; rowCount = inputImage.getHeight(); this.readIter.startLines(); }
private void assertResult(RenderedImage resultImage, String script) throws Exception { JiffleBuilder builder = new JiffleBuilder(); builder.script(script).dest("dest", WIDTH, WIDTH).run(); RenderedImage referenceImage = builder.getImage("dest"); RectIter resultIter = RectIterFactory.create(resultImage, null); RectIter referenceIter = RectIterFactory.create(referenceImage, null); do { do { assertEquals(resultIter.getSample(), referenceIter.getSample()); resultIter.nextPixelDone(); } while (!referenceIter.nextPixelDone()); resultIter.startPixels(); resultIter.nextLineDone(); referenceIter.startPixels(); } while (!referenceIter.nextLineDone()); } }
protected void assertImage(RenderedImage srcImg, RenderedImage destImg, Evaluator evaluator) { RectIter destIter = RectIterFactory.create(destImg, null); if (srcImg != null) { RectIter srcIter = RectIterFactory.create(srcImg, null); do { do { assertEquals(evaluator.eval(srcIter.getSampleDouble()), destIter.getSampleDouble(), TOL); destIter.nextPixelDone(); } while (!srcIter.nextPixelDone()); srcIter.startPixels(); destIter.startPixels(); destIter.nextLineDone(); } while (!srcIter.nextLineDone()); } else { do { do { assertEquals(evaluator.eval(0), destIter.getSampleDouble(), TOL); } while (!destIter.nextPixelDone()); destIter.startPixels(); } while (!destIter.nextLineDone()); } }
/** * Ensures that all sample values in every bands are either inside the given range, * or {@link Double#NaN}. * * @param minimum The lower bound of the range, inclusive. * @param maximum The upper bound of the range, inclusive. * @param image The image to test. * * @since 3.19 */ public static void assertSampleValuesInRange(final double minimum, final double maximum, final RenderedImage image) { final RectIter it = RectIterFactory.create(image, null); if (!it.finishedLines()) do { if (!it.finishedPixels()) do { if (!it.finishedBands()) do { final double value = it.getSampleDouble(); assertBetween("Sample value", minimum, maximum, value); } while (!it.nextBandDone()); it.startBands(); } while (!it.nextPixelDone()); it.startPixels(); } while (!it.nextLineDone()); }