1

This example should be reproducible, the first part (with large polygons) works, the second fails:

library(raster)

USA.altitude <- getData('alt', country='USA')
lower48 <- USA.alt[[1]]

Srs1 = Polygons(list(Polygon(cbind(c(-96,-95,-95,-96),c(40,40,41,40)))), "s1")
Srs2 = Polygons(list(Polygon(cbind(c(-97,-96,-96,-97),c(40,40,41,40)))), "s2")

spdf.large <- SpatialPolygonsDataFrame( SpatialPolygons(list(Srs1,Srs2)), 
                              data.frame( z=1:2, row.names=c("s1","s2") ) )
plot(spdf.large)
usa.average.elev<-extract(lower48, spdf.large, fun=mean)

Yay! everything seems ok, yes? Now with small polys:

Srs3 = Polygons(list(Polygon(cbind(c(-95.01,-94.99,-94.99,-95.01),c(40,40,40.01,40)))), "s3")
Srs4 = Polygons(list(Polygon(cbind(c(-94.01,-93.99,-93.99,-94.01),c(40,40,40.01,40)))), "s4")


spdf.small <- SpatialPolygonsDataFrame( SpatialPolygons(list(Srs3,Srs4)), 
                              data.frame( z=1:2, row.names=c("s3","s4") ) )
plot(spdf.small)
usa.average.elev<-extract(lower48, spdf.small, fun=mean)

Fails with error:

Error in pmax(ceiling(10/dim(r)[1:2]), c(1, 1)) : object 'r' not found

maRtin
  • 6,336
  • 11
  • 43
  • 66
agavegoose
  • 11
  • 3
  • Would you please construct a reproducible example that does not require a data set that takes several minutes to download? Also, have you investigated the `small=` and `weights=` arguments to `extract()`, both documented in `?extract`? – Josh O'Brien Jan 04 '14 at 01:10
  • 2
    Isn't this duplicate of [extract() data from raster with small polygons - rounded weights too small](http://stackoverflow.com/q/17766989/684229)? – Tomas Jan 04 '14 at 01:13
  • @Tomas did Robert Hijmans' answer to that question turn out to be helpful to you? – Josh O'Brien Jan 04 '14 at 01:16
  • 1
    Sorry about the data size, it only took 2 seconds here, so sometimes I forget not all have cable internet. I will edit the datasource and repost soon. I have tried small = TRUE and messed with weights having seen Tomas's question. This seemed more severe though as it throws an error and prevents analysis outright. – agavegoose Jan 04 '14 at 01:55
  • 1
    This is a bug introduced in the last version (earlier this week); as a result of trying to improve the function to better deal with the issue Tomas brought up. It was not supposed to be in the CRAN version yet, but it got there anyway, prematurely. Should go away in the next version. – Robert Hijmans Jan 04 '14 at 04:50
  • @JoshO'Brien: I don't know, I haven't tried it yet. – Tomas Jan 05 '14 at 01:05

0 Answers0