Skip to main content
1 of 2
Spacedman
  • 66.5k
  • 6
  • 83
  • 121

This looks like a bug in rasterize when working on small features on large grids.

Here's a reproducible example taken from one feature from your shape: These coordinates are part of one feature in your data:

xy = structure(c(417476.8675, 417468.8832, 417473.037, 417458.7495, 
417352.3868, 417328.5742, 417318.52, 417303.7033, 417293.8735, 
5887737.1296, 5887834.9375, 5887938.579, 5888021.6583, 5888042.825, 
5888022.7166, 5887966.6249, 5887940.1665, 5887907.6158), .Dim = c(9L, 
2L), .Dimnames = list(NULL, c("x", "y")))

and we make a SpatialLines object out of it:

ltest = SpatialLines(list(Lines(list(Line(xy)),ID=1)))

we'll use a raster with a much larger extent:

e = extent(c(xmin=414500,xmax=424500,ymin=5882000,ymax=5890000))

Now try and rasterize over a fine grid on that raster:

r5 <- raster(ncol=4000, nrow=4000, extent(e))
rtest = rasterize(ltest,r5)
plot(ltest)
plot(rtest,add=TRUE)

enter image description here

Its clear how bad this is. However if you restrict the raster to the extent of that one feature and rasterize at the same equivalent approximate resolution it works fine. Obviously this isn't practical but it shows there's nothing wrong with the feature to prevent it being rasterized at that cell size.

This is giving me deja-vu, but I can't find a related bug on the issue tracker so its possible I saw it discussed elsewhere.

Have now submitted as https://github.com/rspatial/raster/issues/125

> packageVersion("raster")
[1] ‘3.0.12’
> 
Spacedman
  • 66.5k
  • 6
  • 83
  • 121