Package dev.avelar.mapnik
Class GrayImage
java.lang.Object
dev.avelar.mapnik.GrayImage
- All Implemented Interfaces:
AutoCloseable
An image with one number per pixel: an elevation grid, a temperature field, a count, a grey picture.
It is the data a raster layer would give you, held in memory, so that no GDAL is needed. Colour it
with a
RasterColorizer to draw it, or read the values back as an array.
try (GrayImage dem = GrayImage.create(GrayImage.Type.FLOAT32, 256, 256)) {
dem.write(heights); // double[256 * 256], row by row from the top left
Image picture = RasterColorizer.create().stop(0, "blue").stop(2000, "white").colorize(dem);
}
Values go in and out as doubles. The integer types hold whole numbers in their range, and
a value that does not fit is refused with an exception instead of wrapping around. Not thread-safe.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()colorize(RasterColorizer colorizer) Colour the image with the stops ofcolorizer.colorize(RasterColorizer colorizer, Double nodata) Ascolorize(RasterColorizer); pixels equal tonodataget the colorizer's default colour.static GrayImagecreate(GrayImage.Type type, int width, int height) A new image with every pixel 0.static GrayImagecreate(GrayImage.Type type, int width, int height, double initial) A new image with every pixel set toinitial.doubleget(int x, int y) One pixel.intheight()static GrayImageof(GrayImage.Type type, int width, int height, double[] values) A new image of the given size with these values, row by row from the top left.double[]range()The smallest and largest value as{min, max}, ignoring NaN.double[]range(double nodata) Asrange(), also ignoring pixels equal tonodata.double[]read()Every pixel, row by row from the top left.set(int x, int y, double value) Set one pixel.type()intwidth()write(double[] values) Replace every pixel.
-
Method Details
-
create
A new image with every pixel 0. -
create
A new image with every pixel set toinitial. -
of
A new image of the given size with these values, row by row from the top left. -
width
public int width() -
height
public int height() -
type
-
get
public double get(int x, int y) One pixel. ThrowsMapnikExceptionif the position is outside the image. -
set
Set one pixel. ThrowsMapnikExceptionif the position is outside the image or the value does not fit the type. -
read
public double[] read()Every pixel, row by row from the top left. -
write
Replace every pixel.valuesmust hold width times height numbers, row by row from the top left. If any value does not fit the type, nothing changes. -
range
public double[] range()The smallest and largest value as{min, max}, ignoring NaN. Throws if there is none. -
range
public double[] range(double nodata) Asrange(), also ignoring pixels equal tonodata. -
colorize
Colour the image with the stops ofcolorizer. Same asRasterColorizer.colorize(dev.avelar.mapnik.GrayImage). -
colorize
Ascolorize(RasterColorizer); pixels equal tonodataget the colorizer's default colour. -
close
public void close()- Specified by:
closein interfaceAutoCloseable
-