[prev in list] [next in list] [prev in thread] [next in thread] 

List:       grass-stats
Subject:    Re: [GRASS-stats] How to make histogram in R from raster of grass
From:       Rainer M Krug <Rainer () krugs ! de>
Date:       2013-10-07 8:55:32
Message-ID: m2mwmlihob.fsf () krugs ! de
[Download RAW message or body]

pvanbosgeo <p.vanbreugel@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@data. You can extract the data as data frame 
> 
> myrast.data <- myrast@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

_______________________________________________
grass-stats mailing list
grass-stats@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-stats


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic