Dear Edzer, In raster the default approach for extracting raster values with polygons is that a polygon has to cover the center of a cell, for the cell to be included. However, you can use argument "weights=TRUE" in which case you get, apart from the cell values, the percentage of each cell that is covered by the polygon, so that you can apply, e.g., a 50% area covered threshold, or compute an area-weighted average.
In the case of lines, any cell that is crossed by a line is included. For lines and points, a cell that is only 'touched' is included when it is below or to the right (or both) of the line segment/point (except for the bottom row and right most column). I agree that this is very elegant ( I do not find it very intuitive, but that might change when I get used to it! ) For its elegance I have added it to raster (v 1.6-9) ( also in the spirit of, where possible, trying to have similar approaches in spatial packages that Jeremy recently called for http://www.mail-archive.com/r-sig-geo@stat.math.ethz.ch/msg09015.html ). I have also added raster[polygons] <- value , a wrapper around polygonsToRaster(raster, value, update=TRUE) ) Robert On Sat, Oct 30, 2010 at 3:24 AM, Edzer Pebesma <edzer.pebe...@uni-muenster.de> wrote: > I like that solution; it seems intuitive, and as this seems to be a FAQ, > I would like to copy this behaviour to sp classes, such that > > obj[geom,] # in case there are attribute data in obj, or > > obj[geom] # in case obj has only geometry > > return the items in obj that are within the geometry of geom. This would > liberate us from selecting the non-NA indexes returned from overlay (or > in case of a grid, assign NA to everything outside). > > A problem occurs when obj is pixels or a grid (or raster or im), and > geom lines or polygons, I can see two difficult cases: > > - the grid cell centre does not, but part of the grid cell does overlap > with geom or cross geom, > - the grid cell touches geom, but does not overlap / cross. > > Robert, how does raster deal with these two cases? Does it have fixed > behaviour, or can the user choose? > > Rolf, how does spatstat deal with these two cases? > > On 10/30/2010 12:23 AM, Turner Rolf wrote: >> >> ________________________________________ >> From: r-sig-geo-boun...@stat.math.ethz.ch >> [r-sig-geo-boun...@stat.math.ethz.ch] On Behalf Of Peter Larson >> [pslars...@gmail.com] >> Sent: Saturday, 30 October 2010 8:28 a.m. >> To: r-sig-geo@stat.math.ethz.ch >> Subject: [R-sig-Geo] convert from spatstat to sp >> >> Hello all, >> >> Is there any way to convert from spatstat to sp? >> >> Specifically, I am looking to clip a density plot produced in spatstat >> to include only points within a polygon boundary in a shapefile. if >> there is a way to clip in spatstat, this would also be acceptable. >> >> Clipping in spatstat is done simply using [] --- let X be your density plot >> (image; object of class "im") >> and let W be an object of class owin determined by the polygonal boundary >> that you have in mind. >> >> Just do >> >> Y <- X[W] >> >> to get X clipped to the window W. To find out how to make ``a polygon >> boundary in a shapefile'' into >> a window, see the vignette on handling shapefiles in spatstat: >> >> vignette("shapefiles") >> >> cheers, >> >> Rolf Turner >> _______________________________________________ >> R-sig-Geo mailing list >> R-sig-Geo@stat.math.ethz.ch >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo > > -- > Edzer Pebesma > Institute for Geoinformatics (ifgi), University of Münster > Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251 > 8333081, Fax: +49 251 8339763 http://ifgi.uni-muenster.de > http://www.52north.org/geostatistics e.pebe...@wwu.de > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo@stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > _______________________________________________ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo