[R-sig-Geo] problem with extract() raster package using weight=TRUE
Robert J. Hijmans
r.hijmans at gmail.com
Sat Sep 21 21:58:04 CEST 2013
The error occurs if "over" is called; whether this happens depends on
the polygons and the raster used. In earlier versions overlay was used
and there was less checking of CRS in that case. This problem has been
fixed in the next version of raster (2.1-56). For now, I think the
work around -- unlike what I said before -- is to set the CRS of both
datasets to NA.
On Thu, Sep 19, 2013 at 5:53 PM, Ariel Ortiz-Bobea
<aortizbobea at arec.umd.edu> wrote:
> 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.
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
More information about the R-sig-Geo