[GRASSLIST:8463] Re: extracting the value of a raster cell
Shaun Walbridge
walbridge at nceas.ucsb.edu
Fri Sep 30 12:56:49 EDT 2005
Jason,
GRASS doesn't have much native support for geostatistical calculations
such as spatial mean, but it should be a fairly trivial task if you use
the R/GRASS interface. A few of my co-workers use R in this fashion,
with generally great success. A primer on the topic is available at:
http://grass.itc.it/statsgrass/grass_geostats.html.
- Shaun
Jason Horn wrote:
> Thank you Hamish, for the response.
>
> As usual, I don't think I was specific enough. What I'm looking for
> is a way to extract the value of a particular raster cell. r.what
> will do the trick, but only if you know the exact coordinates. I
> want to loop through in a script and extract the value of each cell
> in a raster coverage. For example, if a raster layer was a 10x10
> grid, I want the value of cell (1,1), then cell(2,1), then cell
> (3,1), etc.. If I were to use r.what, calculating the location of
> the next cell using resolution and the coordinates of the first cell,
> I might accidentally skip a cell due to rounding errors. r.mapcalc
> allows you to access the value of a cell directly, but the result is
> always another raster map - you can't output the cell value directly.
>
> The reason for all of this is that I am trying to write my own script
> for calculating the spatial mean of a given raster map. I am
> surprised that there is no facility for this in GRASS already - it
> seems like such a basic spatial statistic. My solution, so far, is
> to output the map as an ascii file, then load the ascii file into an
> array within a script. It works, but seems like a ridiculous
> workaround for something so simple.
>
> If anyone can think of another way, please post it. All suggestions
> welcome.
>
> I guess I should probably write my own module in C, but I've never
> had much luck getting GRASS to compile successfully in the first
> place, so I'll stick with the script route for now.
>
> - Jason
>
>
>
> On Sep 28, 2005, at 7:57 PM, Hamish wrote:
>
>
>>> Does anyone know how to extract the value of a cell at given
>>> coordinates from a raster layer?
>>>
>>>
>>
>> r.what
>>
>>
>>
>>> I am writing a script that will calculate the spatial mean for a given
>>> raster layer. Therefore, I need to be able to access the values of
>>> raster cells.
>>>
>>>
>>
>> r.univar?
>>
>> If you want the stats within a buffer around a point, I would suggest a
>> vector point map -> v.buffer -> v.to.rast -> MASK map -> r.univar in a
>> loop, or probably simpler with Markus's new v.rast.stats module in
>> 6.1-cvs.
>>
>>
>>
>> Hamish
>>
>>
>>
>>
>
>
More information about the grass-user
mailing list