[R-sig-Geo] problem with extract() raster package using weight=TRUE

Ariel Ortiz-Bobea aortizbobea at arec.umd.edu
Fri Sep 20 02:53:40 CEST 2013

Hello Umberto and Robert,

I'm actually encountering the same problem.

- when I set weights=F, the extract function works
- when I set weights=T, I get the "Error: identicalCRS(x, y) is not TRUE"
- I've used this code before with the same shapefile and raster file (with
an older version of raster) and everything worked fine. I presume the newer
versions of extract() are more sensitive
- Following the solution by Umberto, I tried several US shape files
(including the latest one from the census
http://www.census.gov/geo/maps-data/data/tiger-line.html, which should be of
good quality)... without success. I get the same error.

Any suggestions?



My code looks like:

# Import shape file
poly <- readOGR("tl_2013_us_county.shp", "tl_2013_us_county")
projection(poly) # I get: "+proj=longlat +datum=NAD83 +no_defs +ellps=GRS80

# Import raster file
r   <- raster("2012010100.NOAH.grb", nl=1)
projection(r) # I get: "+proj=longlat +a=6371200 +b=6371200 +no_defs"

# change projection of polygon
poly2 <- spTransform(poly, CRS(proj4string( r )) )
projection(poly2) # As espected, I get: ""+proj=longlat +a=6371200
+b=6371200 +no_defs"

# Extract without weights (works)
 v1 <- extract( r, poly2, cellnumbers=TRUE, progress="text")

# Extract with weights (does not work)
 v2 <- extract( r, poly2, cellnumbers=TRUE, weights=T, progress="text") 
# I get: the bar advances to 1-6% depending on the shape file and then I get
"Error: identicalCRS(x, y) is not TRUE"

Ariel Ortiz-Bobea
Fellow at Resources for the Future
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/problem-with-extract-raster-package-using-weight-TRUE-tp7584665p7584678.html
Sent from the R-sig-geo mailing list archive at Nabble.com.

More information about the R-sig-Geo mailing list