subsetting
Tomislav Hengl wrote:
In GIS terms, getting a raster from one grid topology to (any) other grid topology (also subgrids) is referred to 'resampling' (I do not think that this is yet implemented in any R package; a combination of akima and spTransform will do the trick but it is not really compact).
I do think so: overlay in sp is your friend: library(sp) data(meuse.grid) gridded(meuse.grid) = ~x+y grd = spsample(meuse.grid, n = 100, type = "regular") image(meuse.grid["dist"]) points(grd, pch = 3) gridded(grd)= TRUE overlay(meuse.grid, grd) grddf = SpatialPixelsDataFrame(grd, as(meuse.grid, "data.frame")[overlay(meuse.grid, grd),]) image(grddf["dist"]) points(as(grd, "SpatialPoints"), pch = 3) Note that there is only a single code line that does the resample. If anyone has suggestions for a cleaner or simpler interface, or a function or method resample, please let me know. This of course does not do any interpolation; I consider that a different chapter (and package). I cannot see how spTransform could help here.When warping grids, you'd have to revert them first into polygons and spTransform them, to conserve the non-square grid cells resulting. -- Edzer
A generic function to combine R+ILWIS to put a map to a different grid (e.g. to LatLon coordinates) would be: # write to ILWIS:
writeGDAL(dem25m[1], "dem25m.mpr", "ILWIS")
# create a new grid: ...
gridparameters(geoarc)
# resample the map (Bilinear) to the new geographic grid:
shell(cmd=paste(ILWIS, " crgrf geoarc.grf ",geoarc at grid@cells.dim[[2]],"
",geoarc at grid@cells.dim[[1]]," -crdsys=LatlonWGS84
-lowleft=(",geoarc at grid@cellcentre.offset[[1]],",",geoarc at grid@cellcentre.offset[[2]],")
-pixsize=",geoarc at grid@cellsize[[1]],sep=""), wait=F)
shell(cmd=paste(ILWIS, "dem25m_ll_c.mpr = MapResample(dem25m_c.mpr, geoarc, BiLinear)"), wait=F)
shell(cmd=paste(ILWIS, "open dem25m_ll_c.mpr -noask"), wait=F)
see http://geomorphometry.org/R.asp hth, Tom Hengl http://spatial-analyst.net -----Original Message----- From: r-sig-geo-bounces at stat.math.ethz.ch [mailto:r-sig-geo-bounces at stat.math.ethz.ch] On Behalf Of Pieter Beck Sent: Thursday, October 23, 2008 9:15 PM To: r-sig-geo at stat.math.ethz.ch Subject: [R-sig-Geo] subsetting Dear all, I am a new user to the world of spatial applications of R and am wondering about this trivial question: What is the easiest way to subset a SpatialGridDataFrame, based on 4 corner coordinates? The reason I ask is that I want to do an overlay of a polygon file on a large raster dataset, to extract summary statistics from it. Both files are extremely large, however, and just applying overlay causes memory trouble. I was hoping to loop through the polygons, subset the SpatialGridDataFrame using the bounding box surrounding a polygon and then create the summary statistics one polygon at-a-time. To do this, I'd need to subset the SpatialGridDataFrame based on the bounding box corner coordinates. Thanks in advance for the help, Kind Regards, Pieter Beck [[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo _______________________________________________ R-sig-Geo mailing list R-sig-Geo at 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.springer.com/978-0-387-78170-9 e.pebesma at wwu.de