[R-sig-Geo] bug in rasterize (package raster)?

Robert J. Hijmans r.hijmans at gmail.com
Tue Nov 16 05:51:34 CET 2010


Hi Julian,

Yes that is bug. It is a corner-case, literally, with a line leaving a
row exactly where four cells meet. Fixed in version 1.6-20 such that
the below (your example) works.

Robert

library(raster)

cds <- matrix(c(-22.02833, 63.40222, -22.00111, 63.40500, -21.98444,
63.40722, -21.95722, 63.40861, -21.93944, 63.40861, -21.91306,
63.40583, -21.88556, 63.40194, -21.86833, 63.39750, -21.84139,
63.39222, -21.82556, 63.38722, -21.79972, 63.39306, -21.80583,
63.39083, -21.84028, 63.39556, -21.86222, 63.40194, -21.88694,
63.40528, -21.92389, 63.40500, -21.94972, 63.40417, -21.97500,
63.40389, -21.99444, 63.40194, -22.01750, 63.40444), ncol=2,
byrow=TRUE)

my.line <- SpatialLines(list(Lines(list(Line(cds)), "1")))
my.raster <- raster(nrow=10, ncol=52, xmn=-22.04, xmx=-21.785,
ymn=63.375, ymx=63.42)

x <- rasterize(my.line, my.raster)



On Mon, Nov 15, 2010 at 4:01 PM, Julian Burgos <jmburgos at uw.edu> wrote:
> Dear list,
>
> I´m getting the following error when trying to convert a spatial lines
> object into a raster using the rasterize function (package raster):
>
>> my.line
> An object of class "SpatialLines"
> Slot "lines":
> [[1]]
> An object of class "Lines"
> Slot "Lines":
> [[1]]
> An object of class "Line"
> Slot "coords":
>            lon      lat
>  [1,] -22.02833 63.40222
>  [2,] -22.00111 63.40500
>  [3,] -21.98444 63.40722
>  [4,] -21.95722 63.40861
>  [5,] -21.93944 63.40861
>  [6,] -21.91306 63.40583
>  [7,] -21.88556 63.40194
>  [8,] -21.86833 63.39750
>  [9,] -21.84139 63.39222
> [10,] -21.82556 63.38722
> [11,] -21.79972 63.39306
> [12,] -21.80583 63.39083
> [13,] -21.84028 63.39556
> [14,] -21.86222 63.40194
> [15,] -21.88694 63.40528
> [16,] -21.92389 63.40500
> [17,] -21.94972 63.40417
> [18,] -21.97500 63.40389
> [19,] -21.99444 63.40194
> [20,] -22.01750 63.40444
>
> Slot "ID":
> [1] "a"
>
> Slot "bbox":
>        min       max
> x -22.02833 -21.79972
> y  63.38722  63.40861
>
> Slot "proj4string":
> CRS arguments: +proj=longlat +ellps=WGS84
>
>> my.raster
> class       : RasterLayer
> filename    :
> nrow        : 10
> ncol        : 52
> ncell       : 520
> min value   : NA
> max value   : NA
> projection  : +proj=longlat +ellps=WGS84
> extent      : -22.04, -21.785, 63.375, 63.42  (xmin, xmax, ymin, ymax)
> resolution  : 0.004903846, 0.0045  (x, y)
>
>> rasterize(my.line,my.raster)
> Error in if (outcol < 1) next : missing value where TRUE/FALSE needed
>
>
> Is this a bug in the raster function?  Or I am missing something?
> Many thanks,
>
> Julián
>
> Julián Mariano Burgos
> Hafrannsóknastofnunin/Marine Research Institute
> Skúlagata 4, 121 Reykjavík, Iceland
> Sími/Telephone : +354-5752037
> Bréfsími/Telefax:  +354-5752001
> Netfang/Email: julian at hafro.is, jmburgos at uw.edu
>
>        [[alternative HTML version deleted]]
>
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>



More information about the R-sig-Geo mailing list