[R-sig-Geo] overlay polygon with raster

José Hidasi hidasineto at gmail.com
Thu Dec 4 09:11:44 CET 2014


Hello Simone,

You can also intersect the raster with the polygon and then calculate the
area covered by each raster cell. If that's what you want, you might need
to:

1) use "rasterToPolygons()" function to transform the raster into a polygon.

2) apply an equal area projection (e.g. lambert azimuthal) to both polygons
using "spTransform()" (raster/polygon and the other polygon).

3) create a new attribute in your "raster polygon" to identify each cell
(i.e. give a number to each cell). After creating the attribute, you can
use something like:
rasterpolygon$new.attribute <- c(1:length(rasterpolygon$new.attribute))

4) intersect both polygons using "intersect()".

5) use "gArea()" function to calculate the area of each "intersected cell",
but remember to use the "byid=T" argument. It should look like "area.cells
<- gArea(IntersectedPolygon, byid=T)". It will return a vector with the
area sizes in the units of the projection you used in step 2.

6) finally, get the area for each cell while identifying its number before
the intersection. To do that, you can bring up together "area.cells" (from
step 5) and the attribute you created in step 3 (which was maintained after
the intersection). For example:
info <- cbind(intersected.raster$new.attribute, area.cells)


Just an idea.


All the best,
Jose


On Wed, Dec 3, 2014 at 10:15 PM, Simone Ruzza <simone.ruzza12 at gmail.com>
wrote:

> Dear R-sig-geo users,
>
> apologies for the simplicity of my question, but I have been
> struggling with this for a bit I have not managed to find a solution.
> Basically, I would like to overlay a polygon onto raster grid and
> extract some statistics for the polygon in question i.e. the area of
> every raster cell covered by the polygon. Here is a figure that might
> make it clearer
> <https://dl.dropboxusercontent.com/u/33966347/example.JPG> . I have
> been fiddling around with the extract function from the raster
> package, which works to some extent, as I am able to retrieve
> information on the categories of each of the raster cells covered by
> the polygon. However, as I said, I am interested in the area covered
> by the polygon within each raster cell. I know that perhaps I should
> try and convert my polygon into another raster and then overlay the
> two rasters, but this perhaps would mean that the polygon should be
> converted into a raster at a high resolution? If this was case, it is
> not computationally feasible for me as some polygons I have cover a
> huge area and it would take forever to overlay all those rasters. Any
> help, suggestions would be highly appreciated!
>
> thanks in advance!
>
> Simone
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



-- 
José Hidasi Neto
Ph.D. Candidate in Ecology and Evolution - Community Ecology and
Functioning Lab - UFG
Lattes:
http://buscatextual.cnpq.br/buscatextual/visualizacv.do?id=K4293841A0
Community Ecology and Functioning Lab: http://cianciaruso.wix.com/home
My blog about R: http://rfunctions.blogspot.com.br/

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list