[Rspatial-devel] [R-spatial-devel] sp change in handling gridded data

Roger Bivand Roger.Bivand at nhh.no
Wed May 25 07:33:09 CEST 2011


On Tue, 24 May 2011, Edzer Pebesma wrote:

> selection [ on SpatialPixels has now as default drop=FALSE (was: drop=TRUE)

I've checked on the book code, and nothing broke. This doesn't check that 
nothing changed, though - I probably ought to diff the output too, but 
never did that.

Roger

>
> On 05/24/2011 12:04 PM, Edzer Pebesma wrote:
>> [r-spatial-devel included, but please continue any discussion about sp
>> on the r-forge list]
>>
>> I'm proposing a change in the way sp handles gridded data. Right now, a
>> data set with coordinates
>>
>> x y
>> 1 1
>> 1 2
>> 1 3
>>
>> cannot be coerced to SpatialPixels (gridded(x) = TRUE) because from the
>> x coordinate we cannot figure out the grid cell size.
>>
>> My proposal is to change this, and when another coordinate (y) can give
>> the grid cell size, to take that one as grid cell size. This would then
>> generate the following warning:
>>
>> Warning message:
>> In points2grid(points, tolerance, round) :
>>   cell size from constant coordinate 2 possibly taken from other coordinate
>>
>> library(sp)
>> data(meuse.grid)
>> gridded(meuse.grid) = ~x+y
>> meuse.grid[2:3,]
>>
>> used to generated an error, but would now pass with this warning.
>>
>> As the major nuissance with this is when selecting few or single pixels,
>> I modified the behaviour of [ on SpatialPixels[DataFrame]s. The default
>> is drop=FALSE, which will keep the original @grid GridTopology, so that
>>
>> meuse.grid[1,]
>>
>> will result in a single-pixel grid, with grid topology from meuse.grid,
>> whereas
>>
>> meuse.grid[1,drop=TRUE]
>>
>> will result in an error (cannnot derive grid from single point), and
>>
>> meuse.grid[2:3, drop=TRUE]
>>
>> will result in the warning message above. SpatialPixels() and
>> SpatialPixelsDataFrame() now have a grid=NULL argument, that, when
>> specified, will take these grid topologies instead of those derived from
>> the points.
>>
>> I committed this to r-forge, and hope you like it. Reactions more than
>> welcome. An appropriate message to r-sig-geo at (or before?) next
>> release of sp is useful, i suppose.
>
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the Rspatial-devel mailing list