r.neighborhoodmatrix identifies all adjacency relations between objects (aka segments or clumps) in a raster map and exports these as a 2xn matrix where n is the number of neighborhood relations with each relation listed in both directions (i.e. if a is neighbor of b, the list will contain a,b and b,a). If a path to an output file is specified, the matrix will be written to that file, otherwise it will be sent to standard output.
Neighborhood relations are determined pixel by pixel, and by default only pixels that share a common pixel boundary are considered neighbors. When the -d flag is set pixels sharing a common corner (i.e. diagonal neighbors) are also taken into account.
When the -l flag is set, the module additionally indicates the length of the common border between two neighbors in number of pixels. As this length is not clearly defined for diagonal neighbors, the -l flag cannot be used in combination with the -d flag.
In order to speed up calculations, the user can set the parameter processes to the number of desired processes to run in parallel. As the module parallelizes per direction, the maximum number of processes is 4 without and 8 with the -d flag.
The module (without the -d flag) should give the same result as the equivalent call to v.neighborhoodmatrix with the -b flag. Currently it actually seems faster for some maps to transform the raster to vector and then run the latter. More tests are needed, though, to confirm this.
As neighborhood length is measured in pixels, this length is not in proportion to length in map units if the location is a lat-long location, or if the resolution is not the same in East-West and in North-South direction (rectangular pixels).
r.neighborhoodmatrix in=boundary_county_500m sep=comma
r.neighborhoodmatrix -l n=boundary_county_500m sep=comma \ output=county_neighbors.csv processes=4
r.to.vect -tbv in=boundary_county_500m out=boundary_county_500m type=area v.neighborhoodmatrix in=boundary_county_500m sep=comma
Last changed: $Date: 2017-11-20 12:49:09 +0100 (Mon, 20 Nov 2017) $
Available at: r.neighborhoodmatrix source code (history)
Main index | Raster index | Topics index | Keywords index | Graphical index | Full index
© 2003-2018 GRASS Development Team, GRASS GIS 7.4.1svn Reference Manual