Skip to content

Iteratively subsample a rater and reassemble

6 messages · Gordon Holtgrieve, Jonathan Greenberg, Forrest Stevens

#
Gordon:

To clarify, you are trying to determine a relative population density
per country, correct?  I think you should look at the ?subs function,
which will make it a lot easier to swap the country ID with the
population value -- you just need a data.frame of ID and population.
Then it seems if you create a new raster that has the population of
the country for each cell, you can simply divide the per-location
population by that raster.

--j
On Mon, Mar 31, 2014 at 12:12 AM, Gordon Holtgrieve <gholt at uw.edu> wrote:

  
    
#
Ok, so I think the way I described may work for what you are doing --
basically, make a raster where each pixel is the per-country
population value via ?subs linking the country code with the
population.  From that, you will have, for each pixel, an estimate for
the full country population, and a corresponding ACTUAL population for
each pixel, with which you can now do band math.

Given a raster of two countries A and B:

A A A B B B
A A A A B B
A A B B B B

And data.frame:
ID Population
A  100
B  200

A ?subs will return a raster:

100 100 100 200 200 200
100 100 100 100 200 200
100 100 200 200 200 200

A more brute-force (assuming you have enough memory) is to ?getValues
the entire raster, and convert it into a data.frame.  For small
rasters this is fine, for bigger rasters this is a more serious issue.

--j
On Mon, Mar 31, 2014 at 12:12 PM, Gordon Holtgrieve <gholt at uw.edu> wrote: