[R-sig-Geo] raster: extract is empty with polygon
Agustin Lobo
alobolistas at gmail.com
Thu Mar 24 19:11:01 CET 2011
Hi!
I'm trying to calculate the mean values for a set of polygons.
This is what I do:
require(raster)
require(rgdal)
#SGRGBWBPS125F40
#"read" tif file
SGRGBF40 = brick("/media/TRANSCEND/MONTSENY2008/CALIBRACION2010/DigiPreprocess/TESTCASA/CALSEL/SGRGB/SGRGBWBPS125F40.tif")
> SGRGBF40
class : RasterBrick
filename : /media/TRANSCEND/MONTSENY2008/CALIBRACION2010/DigiPreprocess/TESTCASA/CALSEL/SGRGB/SGRGBWBPS125F40.tif
nlayers : 3
nrow : 1760
ncol : 2640
ncell : 4646400
projection : NA
min value : 0 0 0
max value : 65535 65535 65535
extent : 0, 2640, 0, 1760 (xmin, xmax, ymin, ymax)
resolution : 1, 1 (x, y)
> projection(SGRGBF40)
[1] "NA"
#read the shape file
calibf2 = readOGR(dsn="/media/TRANSCEND/MONTSENY2008/CALIBRACION2010/DigiPreprocess/TESTCASA/CALSEL",layer="calibf2",stringsAsFactors=F)
> projection(calibf2)
[1] "+proj=utm +zone=31 +ellps=intl +units=m +no_defs"
> projection(SGRGBF40) = projection(calibf2)
But they do not overlap as shown by
> plot(subset(SGRGBF40,1))
> plot(calibf2,add=T)
and the extracted object is empty
#Calculate mean values for each polygon:
> v <- extract(SGRGBF40, calibf2,fun=mean,nl=3)
> summary(v)
Length Class Mode
[1,] 0 -none- NULL
[2,] 0 -none- NULL
[3,] 0 -none- NULL
[4,] 0 -none- NULL
[5,] 0 -none- NULL
etc
> sessionInfo()
R version 2.12.2 (2011-02-25)
Platform: i486-pc-linux-gnu (32-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=C LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] rgdal_0.6-31 raster_1.7-8 sp_0.9-72
loaded via a namespace (and not attached):
[1] grid_2.12.2 lattice_0.19-17 tools_2.12.2
More information about the R-sig-Geo
mailing list