Interesting -- this issue didn't arise in my application.

Note that 'extract' includes an argument called 'weight', which will 
apparently return the cell value & the fraction of each cell which is 
inside the polygon. This should be enough to compute the weighted 
average in a case like yours. I haven't tried it out, so can't comment 
on efficiency -- although the help page suggests it can be slow.

Another possibility might be to sample the polygons with regular points 
using 'spsample' -- and then use the raster values at these point 
locations (from 'extract') to approximate the weighted average.

Cheers,
G.


On 05/09/13 02:37, Michael Treglia wrote:
> Thanks for the suggestion! I ended up using the centroids of my 
> polygons, and doing the overlay in SAGA GIS. The whole process ran 
> quickly.
>
> GD- Ill keep your suggestion in mind for the future. A quick question 
> though - your method doesn't directly allow computation of weighted 
> average of pixel values within a polygon, does it? For my situation, 
> for example, with large raster cells with respect to the polygons, 
> imperfect alignment means that sometimes a polygon is 1/3 of 1 pixel 
> value and 2/3 another, so I would want the weighted average of the 
> pixel values.  (I've got what I needed to work for now, but curious 
> for the future).
>
> Thanks again, and best regards,
> Mike
>
>
> On Fri, Aug 30, 2013 at 11:42 PM, GD <grothe...@gmail.com 
> <mailto:grothe...@gmail.com>> wrote:
>
>     I had related situation with 85000 non-overlapping polygons, and a
>     raster
>     dataset with dimensions ~ 10000x10000. In that case I wanted the full
>     distribution of pixel values inside each polygon, rather than just
>     the mean.
>
>     An efficient approach (much faster than extract) was:
>
>     1) Rasterize the polygons (to a single raster with the same
>     dimensions as
>     the input raster dataset). My polygons had a unique ID value that
>     was burned
>     into the raster. I did this with 'gdal_rasterize'
>
>     2) Use the 'crosstab' function in the 'raster' package to
>     cross-tabulate the
>     values from the ID raster with the values on the input raster
>     dataset. This
>     gives the full range of pixel values associated with each polygon ID.
>
>     3) From there, it is straightforward to apply whichever function
>     to the
>     pixel values for each ID.
>
>
>
>
>     --
>     View this message in context:
>     
> http://r-sig-geo.2731867.n2.nabble.com/Extract-function-too-much-data-for-R-tp7584509p7584521.html
>     Sent from the R-sig-geo mailing list archive at Nabble.com.
>
>     _______________________________________________
>     R-sig-Geo mailing list
>     R-sig-Geo@r-project.org <mailto:R-sig-Geo@r-project.org>
>     https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>


        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to