Package dev.avelar.mapnik
Class RasterGrid
java.lang.Object
dev.avelar.mapnik.RasterGrid
A grid of numbers over an area, such as an elevation model, read from a file without GDAL. Pure
Java: it needs no native library, so it works anywhere. Turn it into a
GrayImage to colour
and draw it.
RasterGrid dem = RasterGrid.read(Paths.get("dem.tif"));
try (GrayImage g = dem.toGrayImage()) {
Image picture = ramp.colorize(g);
}
Supported files:
- Esri ASCII grid (
.asc): the header withncols,nrows, the lower left corner or centre,cellsizeand optionalNODATA_value. - GeoTIFF (
.tif,.tiff): classic TIFF (not BigTIFF), strips or tiles, 8, 16, 32 and 64-bit unsigned, signed and floating point samples, compression none, deflate, LZW and PackBits, with the horizontal and floating-point predictors. The first band is read. The extent comes from the model tiepoint and pixel scale (or transformation) tags, and the projection from the GeoKey directory when it is an EPSG code.
IllegalArgumentException
that says so.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longThe most pixels one grid may hold: more would need gigabytes ofdoubles. -
Method Summary
Modifier and TypeMethodDescriptionextent()The area the grid covers, in its projection, or null if the file does not say.doubleget(int x, int y) One value.intheight()noData()The value that means "no data", if the file names one.double[]range()Smallest and largest value as{min, max}, ignoring NaN and the no-data value.static RasterGridRead a file, choosing the format by its extension:.asc,.tifor.tiff.static RasterGridRead the text of an Esri ASCII grid.static RasterGridstatic RasterGridreadGeoTiff(byte[] data) static RasterGridreadGeoTiff(Path file) srs()The projection asepsg:<code>, or null if the file has none or it is not an EPSG code.AGrayImageof the file's own pixel type.toGrayImage(GrayImage.Type type) AGrayImageof the given type.type()The pixel type that holds the file's values exactly.doublevalueAt(double mapX, double mapY) The value under a map position, or NaN if it is outside the extent or the grid has none.double[]values()Every value, row by row from the top left.intwidth()
-
Field Details
-
MAX_PIXELS
public static final long MAX_PIXELSThe most pixels one grid may hold: more would need gigabytes ofdoubles.- See Also:
-
-
Method Details
-
width
public int width() -
height
public int height() -
values
public double[] values()Every value, row by row from the top left. This is the array itself, not a copy. -
noData
The value that means "no data", if the file names one. -
extent
The area the grid covers, in its projection, or null if the file does not say. -
srs
The projection asepsg:<code>, or null if the file has none or it is not an EPSG code. -
type
The pixel type that holds the file's values exactly. -
range
public double[] range()Smallest and largest value as{min, max}, ignoring NaN and the no-data value. Throws if none. -
get
public double get(int x, int y) One value. ThrowsIndexOutOfBoundsExceptionoutside the grid. -
valueAt
public double valueAt(double mapX, double mapY) The value under a map position, or NaN if it is outside the extent or the grid has none. -
toGrayImage
AGrayImageof the file's own pixel type. Close it. -
toGrayImage
AGrayImageof the given type. Values that do not fit the type (a float grid into an integer image, say) are refused, not wrapped. Close it. -
read
Read a file, choosing the format by its extension:.asc,.tifor.tiff.- Throws:
IOException
-
readGeoTiff
- Throws:
IOException
-
readGeoTiff
-
readAscii
- Throws:
IOException
-
readAscii
Read the text of an Esri ASCII grid.
-