[R-sig-Geo] "rasterize" changes the data values… why?
Malcolm Fairbrother
m.fairbrother at bristol.ac.uk
Thu May 31 14:42:03 CEST 2012
Dear list,
I'm trying to use "rasterize" to create a raster out of a SpatialPolygonsDataFrame. The problem I'm having is that, for reasons I don't understand, the data values in the resulting raster ("faosoil") do not correspond to those of the original variable in the SpatialPolygonsDataFrame ("dsmw").
In the code below, you'll see that values for dsmw$FAOSOIL range from 1 to 186. However, when I convert dsmw into a raster, its data values range from 390 to 587, and I can't tell whether these new values correspond in some way to the original ones. I've tried both "field=1" and "field="FAOSOIL"", and they return the same result.
Can anyone tell me how to get the original-scale data into the raster, or what I'm misunderstanding?
Many thanks,
Malcolm
> summary(dsmw)
Object of class SpatialPolygonsDataFrame
Coordinates:
min max
x 68.11093 97.39555
y 6.74004 33.17195
Is projected: FALSE
proj4string :
[+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0]
Data attributes:
FAOSOIL DOMSOI
Min. : 1.00 Min. : 1.00
1st Qu.: 56.00 1st Qu.:17.00
Median : 79.50 Median :20.00
Mean : 91.47 Mean :21.53
3rd Qu.:138.00 3rd Qu.:28.00
Max. :186.00 Max. :43.00
> faosoil <- rasterize(dsmw, bio, field=1)
Found 634 region(s) and 736 polygon(s)
> summary(faosoil)
Cells: 447692
NAs : 34484
Min. 390.0
1st Qu. 441.0
Median 495.0
Mean 481.4
3rd Qu. 508.0
Max. 587.0
NA's 34484.0
More information about the R-sig-Geo
mailing list