[R-sig-Geo] rasterize func: polygon values to raster cells - error msg
Gustaf Granath
Gustaf.Granath at ebc.uu.se
Thu Dec 13 08:55:49 CET 2012
Hi,
I have used the rasterize function to get values from a
spatialPolyDataFrame variable (@data$variable) to raster:
rasterize(SPDFobj, rasterObj, field="variable")
For a specific case a get a, to me, strange error message .
"Error in writeValues(out, fun(n), tr$row[i]) :
error in evaluating the argument 'v' in selecting a method for
function 'writeValues': Error in fun(n) : unused argument(s) (n)"
It works with one SpatialPolyDataFrame that Im working with, but not
with another one and I cannot figure out why. Any ideas of what is going on?
Unfortunately, I have not been able to reproduce the error with
simulated data (and my data files are huge) but this is essentially what
I have done (but the code below works - actually the raster layer in
this code works with my SPDFobj):
p1 <- rbind(c(-180,-20), c(-140,55), c(10, 0), c(-140,-60), c(-180,-20))
p2 <- rbind(c(-10,0), c(140,60), c(160,0), c(140,-55), c(-10,0))
p3 <- rbind(c(-125,0), c(0,60), c(40,5), c(15,-45), c(-125,0))
pols <- SpatialPolygons( list( Polygons(list(Polygon(p1),
Polygon(hole)), 1),
Polygons(list(Polygon(p2)), 2),
Polygons(list(Polygon(p3)), 3)))
pols <-SpatialPolygonsDataFrame(pols, data.frame("W"=1:3))
r <- raster(ncol=80, nrow=90)
test<-rasterize(pols, r, field="W")
Here is an overview of the objects I am using.
> summary(SPDFobj)
Object of class SpatialPolygonsDataFrame
Coordinates:
min max
x -11.08333 31.91753
y 33.91667 71.91743
Is projected: FALSE
proj4string : [+proj=longlat +datum=WGS84]
Data attributes:
variable
...
...
> rasterObj_orig
class : RasterLayer
dimensions : 12768, 11050, 141086400 (nrow, ncol, ncell)
resolution : 250, 250 (x, y)
extent : 2782250, 5544750, 2220250, 5412250 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000
+ellps=GRS80 +units=m +no_defs
data source : C:\Users\veGustaf\Desktop\phd\Where is Ndep neg\bogs.grd
names : layer
values : 36, 36 (min, max)
> rasterObj #projection fixed etc through an extent object, raster -->
extent --> raster
class : RasterLayer
dimensions : 12768, 11050, 141086400 (nrow, ncol, ncell)
resolution : 250, 250 (x, y)
extent : 2782250, 5544750, 2220250, 5412250 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84
Cheers,
Gustaf
--
Gustaf Granath (PhD)
Dept of Plant Ecology and Evolution
Uppsala University
More information about the R-sig-Geo
mailing list