[GRASS-stats] How to make histogram in R from raster of grass

Rainer M Krug Rainer at krugs.de
Mon Oct 7 01:55:32 PDT 2013


pvanbosgeo <p.vanbreugel at gmail.com>
writes:

> If you import a GRASS raster, you'll get a SpatialGridDataFrame object.
> Suppose your spatialgriddataframe is called 'myrast'. You can find out the
> structure of that object using str(myrast). You'll find that the raster
> values are in myrast at data. You can extract the data as data frame 
>
> myrast.data <- myrast at data
>
> Now you can create histograms as you would normally do. 
>
> Especially when you are dealing with very large raster layers, a good
> alternative is to use the 'raster' package to import the raster layer. You
> can then use the hist function to create a histogram of the values of a
> RasterLayer directly. For large datasets the hist function in the raster
> package automatically uses a sample.

Or you can use the GRASS function r.stats via the package spgrass6 as
follow:

,----
|  cats <- c("*", 1:7)
|  his <- spgrass6::execGRASS(
|         "r.stats",
|         input = layer,
|         flags = c("c","i"),
|         intern = TRUE
|         )
`----

from the GRASS help:

,----
| r.stats calculates the area present in each of the categories of
| user-selected raster map layer(s). Area statistics are given in units of
| square meters and/or cell counts. This analysis uses the current
| geographic region and mask settings. Output can be sent to a file in the
| user's current working directory. If a single map layer is specified on
| the command line, a list of areas in square meters (assuming the map's
| coordinate system is in meters) for each category in the raster map
| layer will be printed. (If the -c option is chosen, areas will be stated
| in number of cells.) If multiple raster map layers are specified on the
| command line, a cross-tabulation table of areas for each combination of
| categories in the map layers will be printed.
`----

Hope this helps,

Rainer

>
>
>
>
>
> -----
> ---
> http://pvanb.wordpress.com/
> --
> View this message in context: http://osgeo-org.1560.x6.nabble.com/How-to-make-histogram-in-R-from-raster-of-grass-tp5049699p5082132.html
> Sent from the Grass - Stats mailing list archive at Nabble.com.
<#secure method=pgpmime mode=sign>

-- 
Rainer M. Krug

email: RMKrug<at>gmail<dot>com



More information about the grass-stats mailing list