Monday, December 17, 2007

How to get the numbers out of a GRASS raster map in JGrass

// Get the current active region from the mapset path
Window originalActiveRegion = Window.getActiveWindowFromMapset(mapsetPath);

// adapt the region to a poligonal geometry extracted from a feature,
// let's say basinBounds
Window readRegion = Window.adaptActiveRegionToEnvelope(basinsBounds,

// shrink the active region to the needed part in order to make the scripts work
// without overhead
Window.writeActiveWindowToMapset(mapsetPath, readRegion);

// create the reader
JGrassRasterMapReader jgReader = new JGrassRasterMapReader(readRegion,
elevationMapName, mapsetName, locationPath, monitor);

// read the data
RasterData rasterData = null;
if ( && jgReader.hasMoreData()) {
rasterData = jgReader.getNextData();

// and rasterdata is just a wrapper around a matrix based dataset,
// so just loop over it with two nested for loop in rows and cols.
// this was done just to make migration to geotools coverage
// easier at some point
Post a Comment