@Test @Category(UnitTest.class) public void scaleRasterNearestFloat() throws IOException { int scale; MrGeoRaster scaled; for (scale = 1; scale < 15; scale++) { scaled = numberedFloat.scale(width * scale, height * scale, false, new double[]{Double.NaN}); compareResult(scale, scaled); } for (scale = 2; scale < 8; scale++) { scaled = numberedFloat.scale(width / scale, height / scale, false, new double[]{Double.NaN}); compareResult(1.0 / scale, scaled); } }
public MrGeoRaster scale(int dstWidth, int dstHeight, boolean interpolate, double[] nodatas) throws MrGeoRasterException { MrGeoRaster src = this; double scaleW = (double) dstWidth / src.width; double scaleH = (double) dstHeight / src.height; while (true) { int dw; int dh; double scale = Math.max(scaleW, scaleH); if (interpolate) { if (scale > 2.0) { dw = (int) (src.width * 2.0); dh = (int) (src.height * 2.0); } else if (scale < 0.50) { dw = (int) (src.width * 0.50); dh = (int) (src.height * 0.50); } else { dw = dstWidth; dh = dstHeight; } } else { dw = dstWidth; dh = dstHeight; } MrGeoRaster dst = createCompatibleRaster(dw, dh); switch (datatype) { case DataBuffer.TYPE_BYTE: case DataBuffer.TYPE_INT: case DataBuffer.TYPE_SHORT: case DataBuffer.TYPE_USHORT: if (interpolate) { Bilinear.scaleInt(src, dst, nodatas); } else { Nearest.scaleInt(src, dst); } break; case DataBuffer.TYPE_FLOAT: if (interpolate) { Bilinear.scaleFloat(src, dst, nodatas); } else { Nearest.scaleFloat(src, dst); } break; case DataBuffer.TYPE_DOUBLE: if (interpolate) { Bilinear.scaleDouble(src, dst, nodatas); } else { Nearest.scaleDouble(src, dst); } break; default: throw new RasterWritableException("Error trying to scale raster. Bad raster data type"); } if (dst.width == dstWidth && dst.height == dstHeight) { return dst; } src = dst; scaleW = (double) dstWidth / src.width; scaleH = (double) dstHeight / src.height; } }
MrGeoRaster implements Serializable { public MrGeoRaster scale(int dstWidth, int dstHeight, boolean interpolate, double[] nodatas) throws MrGeoRasterException { MrGeoRaster src = this; double scaleW = (double) dstWidth / src.width; double scaleH = (double) dstHeight / src.height; while (true) { int dw; int dh; double scale = Math.max(scaleW, scaleH); if (interpolate) { if (scale > 2.0) { dw = (int) (src.width * 2.0); dh = (int) (src.height * 2.0); } else if (scale < 0.50) { dw = (int) (src.width * 0.50); dh = (int) (src.height * 0.50); } else { dw = dstWidth; dh = dstHeight; } } else { dw = dstWidth; dh = dstHeight; } MrGeoRaster dst = createCompatibleRaster(dw, dh); switch (datatype) { case DataBuffer.TYPE_BYTE: case DataBuffer.TYPE_INT: case DataBuffer.TYPE_SHORT: case DataBuffer.TYPE_USHORT: if (interpolate) { Bilinear.scaleInt(src, dst, nodatas); } else { Nearest.scaleInt(src, dst); } break; case DataBuffer.TYPE_FLOAT: if (interpolate) { Bilinear.scaleFloat(src, dst, nodatas); } else { Nearest.scaleFloat(src, dst); } break; case DataBuffer.TYPE_DOUBLE: if (interpolate) { Bilinear.scaleDouble(src, dst, nodatas); } else { Nearest.scaleDouble(src, dst); } break; default: throw new RasterWritableException("Error trying to scale raster. Bad raster data type"); } if (dst.width == dstWidth && dst.height == dstHeight) { return dst; } src = dst; scaleW = (double) dstWidth / src.width; scaleH = (double) dstHeight / src.height; } } }
MrGeoRaster implements Serializable { public MrGeoRaster scale(int dstWidth, int dstHeight, boolean interpolate, double[] nodatas) throws MrGeoRasterException { MrGeoRaster src = this; double scaleW = (double) dstWidth / src.width; double scaleH = (double) dstHeight / src.height; while (true) { int dw; int dh; double scale = Math.max(scaleW, scaleH); if (interpolate) { if (scale > 2.0) { dw = (int) (src.width * 2.0); dh = (int) (src.height * 2.0); } else if (scale < 0.50) { dw = (int) (src.width * 0.50); dh = (int) (src.height * 0.50); } else { dw = dstWidth; dh = dstHeight; } } else { dw = dstWidth; dh = dstHeight; } MrGeoRaster dst = createCompatibleRaster(dw, dh); switch (datatype) { case DataBuffer.TYPE_BYTE: case DataBuffer.TYPE_INT: case DataBuffer.TYPE_SHORT: case DataBuffer.TYPE_USHORT: if (interpolate) { Bilinear.scaleInt(src, dst, nodatas); } else { Nearest.scaleInt(src, dst); } break; case DataBuffer.TYPE_FLOAT: if (interpolate) { Bilinear.scaleFloat(src, dst, nodatas); } else { Nearest.scaleFloat(src, dst); } break; case DataBuffer.TYPE_DOUBLE: if (interpolate) { Bilinear.scaleDouble(src, dst, nodatas); } else { Nearest.scaleDouble(src, dst); } break; default: throw new RasterWritableException("Error trying to scale raster. Bad raster data type"); } if (dst.width == dstWidth && dst.height == dstHeight) { return dst; } src = dst; scaleW = (double) dstWidth / src.width; scaleH = (double) dstHeight / src.height; } } MrGeoRaster(int width, int height, int bands, int datatype, byte[] data, int dataoffset); }
MrGeoRaster implements Serializable { public MrGeoRaster scale(int dstWidth, int dstHeight, boolean interpolate, double[] nodatas) throws MrGeoRasterException { MrGeoRaster src = this; double scaleW = (double) dstWidth / src.width; double scaleH = (double) dstHeight / src.height; while (true) { int dw; int dh; double scale = Math.max(scaleW, scaleH); if (interpolate) { if (scale > 2.0) { dw = (int) (src.width * 2.0); dh = (int) (src.height * 2.0); } else if (scale < 0.50) { dw = (int) (src.width * 0.50); dh = (int) (src.height * 0.50); } else { dw = dstWidth; dh = dstHeight; } } else { dw = dstWidth; dh = dstHeight; } MrGeoRaster dst = createCompatibleRaster(dw, dh); switch (datatype) { case DataBuffer.TYPE_BYTE: case DataBuffer.TYPE_INT: case DataBuffer.TYPE_SHORT: case DataBuffer.TYPE_USHORT: if (interpolate) { Bilinear.scaleInt(src, dst, nodatas); } else { Nearest.scaleInt(src, dst); } break; case DataBuffer.TYPE_FLOAT: if (interpolate) { Bilinear.scaleFloat(src, dst, nodatas); } else { Nearest.scaleFloat(src, dst); } break; case DataBuffer.TYPE_DOUBLE: if (interpolate) { Bilinear.scaleDouble(src, dst, nodatas); } else { Nearest.scaleDouble(src, dst); } break; default: throw new RasterWritableException("Error trying to scale raster. Bad raster data type"); } if (dst.width == dstWidth && dst.height == dstHeight) { return dst; } src = dst; scaleW = (double) dstWidth / src.width; scaleH = (double) dstHeight / src.height; } } MrGeoRaster(int width, int height, int bands, int datatype, byte[] data, int dataoffset); static MrGeoRaster createEmptyRaster(int width, int height, int bands, int datatype); static MrGeoRaster createEmptyRaster(int width, int height, int bands, int datatype, double nodata); static MrGeoRaster createEmptyRaster(int width, int height, int bands, int datatype, double[] nodatas); static MrGeoRaster createRaster(int width, int height, int bands, int datatype, byte[] data, int dataOffset); static MrGeoRaster fromRaster(Raster raster); static MrGeoRaster fromDataset(Dataset dataset); static MrGeoRaster fromDataset(Dataset dataset, int x, int y, int width,
    int height); final MrGeoRaster createCompatibleRaster(int width, int height); final MrGeoRaster createCompatibleEmptyRaster(int width, int height, double nodata); final MrGeoRaster createCompatibleEmptyRaster(int width, int height, double[] nodata); final int width(); final int height(); final int bands(); final int datatype(); final int dataoffset(); final int datasize(); final int datalength(); final MrGeoRaster clip(int x, int y, int width, int height); final MrGeoRaster clip(int x, int y, int width, int height, int band); final void copyFrom(int srcx, int srcy, int width, int height, MrGeoRaster src, int dstx, int dsty); final void copyFrom(int srcx, int srcy, int srcBand, int width, int height, MrGeoRaster src,
    int dstx, int dsty, int dstBand); final void fill(double value); final void fill(double[] values); final void fill(int band, double value); MrGeoRaster scale(int dstWidth,
    int dstHeight, boolean interpolate, double[] nodatas); final MrGeoRaster reduce(int xfactor, int yfactor, Aggregator aggregator, double[] nodatas); final void mosaic(MrGeoRaster other, double[] nodata); final Dataset toDataset(); final Dataset toDiskBasedDataset(Bounds bounds, double[] nodatas,
    int xoffset, int yoffset, int outWidth, int outHeight); final Dataset toDataset(Bounds bounds, double[] nodatas); void copyToDataset(Dataset ds, int dsWidth, int dsHeight, Bounds fullBounds, Bounds bounds,
    int tilesize, int zoomlevel, int gdaltype); final Raster toRaster(); abstract byte getPixelByte(int x, int y, int band); abstract short getPixelShort(int x, int y, int band); abstract short getPixeUShort(int x, int y, int band); abstract int getPixelInt(int x, int y, int band); abstract float getPixelFloat(int x, int y, int band); abstract double getPixelDouble(int x, int y, int band); abstract void setPixel(int x, int y, int band, byte pixel); abstract void setPixel(int x, int y, int band, short pixel); abstract void setPixel(int x, int y, int band, int pixel); abstract void setPixel(int x, int y, int band, float pixel); abstract void setPixel(int x, int y, int band, double pixel); abstract int bytesPerPixel(); }
MrGeoRaster implements Serializable { public MrGeoRaster scale(int dstWidth, int dstHeight, boolean interpolate, double[] nodatas) throws MrGeoRasterException { MrGeoRaster src = this; double scaleW = (double) dstWidth / src.width; double scaleH = (double) dstHeight / src.height; while (true) { int dw; int dh; double scale = Math.max(scaleW, scaleH); if (interpolate) { if (scale > 2.0) { dw = (int) (src.width * 2.0); dh = (int) (src.height * 2.0); } else if (scale < 0.50) { dw = (int) (src.width * 0.50); dh = (int) (src.height * 0.50); } else { dw = dstWidth; dh = dstHeight; } } else { dw = dstWidth; dh = dstHeight; } MrGeoRaster dst = createCompatibleRaster(dw, dh); switch (datatype) { case DataBuffer.TYPE_BYTE: case DataBuffer.TYPE_INT: case DataBuffer.TYPE_SHORT: case DataBuffer.TYPE_USHORT: if (interpolate) { Bilinear.scaleInt(src, dst, nodatas); } else { Nearest.scaleInt(src, dst); } break; case DataBuffer.TYPE_FLOAT: if (interpolate) { Bilinear.scaleFloat(src, dst, nodatas); } else { Nearest.scaleFloat(src, dst); } break; case DataBuffer.TYPE_DOUBLE: if (interpolate) { Bilinear.scaleDouble(src, dst, nodatas); } else { Nearest.scaleDouble(src, dst); } break; default: throw new RasterWritableException("Error trying to scale raster. Bad raster data type"); } if (dst.width == dstWidth && dst.height == dstHeight) { return dst; } src = dst; scaleW = (double) dstWidth / src.width; scaleH = (double) dstHeight / src.height; } } MrGeoRaster(int width, int height, int bands, int datatype, byte[] data, int dataoffset); static MrGeoRaster createEmptyRaster(int width, int height, int bands, int datatype); static MrGeoRaster createEmptyRaster(int width, int height, int bands, int datatype, double nodata); static MrGeoRaster createEmptyRaster(int width, int height, int bands, int datatype, double[] nodatas); static MrGeoRaster createRaster(int width, int height, int bands, int datatype, byte[] data, int dataOffset); static MrGeoRaster fromRaster(Raster raster); static MrGeoRaster fromDataset(Dataset dataset); static MrGeoRaster fromDataset(Dataset dataset, int x, int y, int width,
    int height); final MrGeoRaster createCompatibleRaster(int width, int height); final MrGeoRaster createCompatibleEmptyRaster(int width, int height, double nodata); final MrGeoRaster createCompatibleEmptyRaster(int width, int height, double[] nodata); final int width(); final int height(); final int bands(); final int datatype(); final int dataoffset(); final int datasize(); final int datalength(); final MrGeoRaster clip(int x, int y, int width, int height); final MrGeoRaster clip(int x, int y, int width, int height, int band); final void copyFrom(int srcx, int srcy, int width, int height, MrGeoRaster src, int dstx, int dsty); final void copyFrom(int srcx, int srcy, int srcBand, int width, int height, MrGeoRaster src,
    int dstx, int dsty, int dstBand); final void fill(double value); final void fill(double[] values); final void fill(int band, double value); MrGeoRaster scale(int dstWidth,
    int dstHeight, boolean interpolate, double[] nodatas); final MrGeoRaster reduce(int xfactor, int yfactor, Aggregator aggregator, double[] nodatas); final void mosaic(MrGeoRaster other, double[] nodata); final Dataset toDataset(); final Dataset toDiskBasedDataset(Bounds bounds, double[] nodatas,
    int xoffset, int yoffset, int outWidth, int outHeight); final Dataset toDataset(Bounds bounds, double[] nodatas); void copyToDataset(Dataset ds, int dsWidth, int dsHeight, Bounds fullBounds, Bounds bounds,
    int tilesize, int zoomlevel, int gdaltype); final Raster toRaster(); abstract byte getPixelByte(int x, int y, int band); abstract short getPixelShort(int x, int y, int band); abstract short getPixeUShort(int x, int y, int band); abstract int getPixelInt(int x, int y, int band); abstract float getPixelFloat(int x, int y, int band); abstract double getPixelDouble(int x, int y, int band); abstract void setPixel(int x, int y, int band, byte pixel); abstract void setPixel(int x, int y, int band, short pixel); abstract void setPixel(int x, int y, int band, int pixel); abstract void setPixel(int x, int y, int band, float pixel); abstract void setPixel(int x, int y, int band, double pixel); abstract int bytesPerPixel();  }