[prev in list] [next in list] [prev in thread] [next in thread] 

List:       r-sig-geo
Subject:    Re: [R-sig-Geo] =?windows-1252?q?=22rasterize=22_changes_the_data_val?=
From:       "Robert J. Hijmans" <r.hijmans () gmail ! com>
Date:       2012-05-31 16:21:44
Message-ID: CANtt_hwcJW2HeHVw6GK231+mAgTvNhkMueFOFBOCipsX8KdgRA () mail ! gmail ! com
[Download RAW message or body]

Malcolm,

That is a bug in the current version. A new version should be on CRAN in a
week or so. The work-around is to use

raster:::.polygonsToRaster(    )

(same arguments as in rasterize)

Robert

On Thu, May 31, 2012 at 5:42 AM, Malcolm Fairbrother <
m.fairbrother@bristol.ac.uk> wrote:

> 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
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

	[[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic