SpatialAnalysis Class
iLand\spatialAnalysis_doc.js:2
The SpatialAnalysis
class encapsulates special spatial analysis operations in iLand. For example, the class
contains methods to conduct patch size analysis, or calculate the Rumple index.
An instance of the object is available in the global Javascript context with the name SpatialAnalysis
.
Example
SpatialAnalysis.saveRumpleGrid('temp/rumple.asc');
Item Index
Properties
Methods
patches
-
grid
-
min_size
Perform a patch analysis on the input grid
and return a Grid with unique patch IDs
assigned to each patch (starting with 1, 2, 3, ...). A 'patch' is a number of adjacent pixels with a value > 0. In other words,
all connected non-zero areas are flagged with unique Ids in the output grid.
Internally, a simple flood-fill algorithm searching in the Moore-neighborhood (8 neighbors) is used and applied repeatedly.
If a patch has a size which is smaller than min_size
, the cells of the grid are set to 0, and the patch is not recorded. A list of all
patches (and patchsizes) is available with the patchsizes property.
See also: patchsizes
Parameters:
-
grid
Gridgrid to analyze
-
min_size
Integerignore patches with an area below
min_size
pixels.
saveCrownCoverGrid
-
filename
Generate a map of the crown cover ( at 2m resolution), and save an average (100m) to filename
(ESRI ASCII format).
For each tree, the tree crown (as defined by the 'reader' stamp, which defines for 2m pixels the share
of pixels that are covered by the crown) is additively plotted on a 2m grid.
If that sum is larger then 0.5 (i.e. 50%), a pixel is consiedered as 'covered'.
The resulting grid provides for each 100m cell a fraction of 'covered' pixels. Note that 2m cells that are out of the project area
are not counted (i.e., the resulting crown cover refers only to the stockable area of the resource unit).
Parameters:
-
filename
Stringtarget filename (relative to project folder)
saveCrownCoverGrid
-
filename
-
mask
Generate a map of the crown cover ( at 2m resolution), and save an average to filename
(ESRI ASCII format).
For each tree, the tree crown (as defined by the 'reader' stamp, which defines for 2m pixels the share
of pixels that are covered by the crown) is additively plotted on a 2m grid.
If that sum is larger then 0.5 (i.e. 50%), a pixel is consiedered as 'covered'.
The grid
is used as a mask: the resulting grid uses the cell size of grid
and also the spatial extent.
The resulting grid provides for each 100m cell a fraction of 'covered' pixels.
Example:
// create a grid:
var mask = new Grid();
mask.create(100, 60, 10); // cell-size 10m, 100 x 60 cells
mask.setOrigin(100,1020); // define the origin, the grid covers (100/1020)-(1100/1620)
SpatialAnalysis.saveCrownCoverGrid('temp/test.asc', mask); // save the crown cover grid
saveRumpleGrid
-
filename
Calculate the Rumple-Index for the landscape with a spatial resolution of 10m (i.e., the cells of the iLand height grid)
and extract a 100m grid (average over the 10m cells). Store the grid to filename
(ESRI ASCII format).
The Rumple-Index is a spatial index relating surface area to ground area. In forestry, it is a indicator of vertical heterogeneity. In iLand, the Rumple Index is the variability of the maximum tree height on 10m level (i.e. the "Height"-Grid). The RumpleIndex is calculated for each resource unit and also for the full project area.
See also: rumpleIndex
Parameters:
-
filename
Stringtarget filename (relative to project folder)
Properties
patchsizes
Arrayinteger
The patchsizes
property provides a list of with the number of pixels of each extracted patch in a prior call to See also: patches.
The first entry of the array is the number of pixels of the patch ID 1, etc.
See also: patches
Example:
// let 'wind_grid' be a grid of wind damages, non-zero pixels had some kind of damage (the damage map has a 10m resolution)
// now run the patch analysis and keep damaged areas >4 px
wind_grid = SpatialAnalysis.patches(wind_grid, 5);
// save the patches grid to the output directory and a user code given in the XML file
wind_grid.save( Globals.defaultDirectory('output') + Globals.setting('user.code')+ '_stormDamage_v' + v + '.asc' );
// save also a list of the extracted patch sizes
Globals.saveTextFile(Globals.defaultDirectory('output') + Globals.setting('user.code')+ '_stormPatches_v' + v + '.txt', SpatialAnalysis.patchsizes + "\n");
rumpleIndex
Double
Retrieve the rumple index for the full landscape (i.e., one value).
See also: saveRumpleGrid