[R-sig-Geo] overlay polygon with raster

Simone Ruzza simone.ruzza12 at gmail.com
Fri Dec 5 00:54:06 CET 2014


Thank you for your prompt and kind replies! I think that maybe what
Jose Hidasi was suggesting is what I want. I will give it a go! Just
to clarify, what I would like to extract is the only the area (or
proportion) of a particular cell covered by the polygon and the
corresponding raster category. I am not sure whether this makes it
clearer but I have drawn a rough sketch of the information I am
interested in, highlighted in different colours...
<https://dl.dropboxusercontent.com/u/33966347/query1.JPG>Ideally, I
would like to extract the area or the proportion of each the sections
in different colours and the corresponding category number for the
raster below it...

thanks in advance!

Simone



On Thu, Dec 4, 2014 at 9:32 PM, Nahm Lee <nlee at valleywater.org> wrote:
> Yes, there is a round issues when you use "extract or mask", http://gis.stackexchange.com/questions/112274/is-this-a-known-issue-in-gaps-between-masked-raster-and-spatial-polygon-in-r-wit.
>
> I use "disaggregate" to improve(?) raster resolution.
> This is an example
>
> yourraster.dis <- disaggregate("yourraster" , fact = 2)
>
> Nahm Lee
> nlee at valleywater.org
> Santa Clara Valley Water District
>
> -----Original Message-----
> From: R-sig-Geo [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of Frede Aakmann Tøgersen
> Sent: Wednesday, December 03, 2014 10:37 PM
> To: Simone Ruzza; r-sig-geo at r-project.org
> Subject: Re: [R-sig-Geo] overlay polygon with raster
>
> Hi Simone
>
> If I understand you correctly, then have a look at the man page of raster(). Here is the relevant sections:
>
>      ## S4 method for signature 'Raster,SpatialPolygons'
>      extract(x, y, fun=NULL, na.rm=FALSE, weights=FALSE, cellnumbers=FALSE,
>           small=FALSE, df=FALSE, layer, nl, factors=FALSE, sp=FALSE, ...)
>
> Where
>        x: Raster* object
>
>        y: points represented by a two-column matrix or data.frame, or
>           'SpatialPoints*'; 'SpatialPolygons*'; 'SpatialLines';
>           'Extent'; or a numeric vector representing cell numbers
>
> and
>
> weights: logical. If 'TRUE', the function returns, for each polygon, a
>           matrix with the cell values and the approximate fraction of
>           each cell that is covered by the polygon(rounded to 1/100).
>           The weights can be used for averaging; see examples. This
>           option can be useful (but slow) if the polygons are small
>           relative to the cells size of the Raster* object.
>
> I just googled for ' R area of raster cells within polygon' and got this hit with a reproducible small example:
>
> http://stackoverflow.com/questions/17766989/extract-data-from-raster-with-small-polygons-rounded-weights-too-small
>
> See that page for a solution to some rounding errors in the case of the polygon being very small compared to raster cell size.
>
> Yours sincerely / Med venlig hilsen
>
>
> Frede Aakmann Tøgersen
> Specialist, M.Sc., Ph.D.
> Plant Performance & Modeling
>
> Technology & Service Solutions
> T +45 9730 5135
> M +45 2547 6050
> frtog at vestas.com
> http://www.vestas.com
>
> Company reg. name: Vestas Wind Systems A/S This e-mail is subject to our e-mail disclaimer statement.
> Please refer to www.vestas.com/legal/notice If you have received this e-mail in error please contact the sender.
>
>> -----Original Message-----
>> From: R-sig-Geo [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of
>> Simone Ruzza
>> Sent: 4. december 2014 01:15
>> To: r-sig-geo at r-project.org
>> Subject: [R-sig-Geo] overlay polygon with raster
>>
>> 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
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list