edzer / sp

Classes and methods for spatial data

Home Page:http://edzer.github.io/sp/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

spsample specify only cellsize

behinger opened this issue · comments

Hi!
I found a bug when specifying cellsize in the spsample method without specifying n.

Minimal example:

xmin = 0
xmax = 1
ymin = 0
ymax = 1
coord = c(xmin,ymin,xmin,ymax,xmax,ymax,xmax,ymin)%>%
  matrix(ncol=2,byrow=TRUE)%>%
  sp::Polygon()
sp::spsample(coord,cellsize=0.1,type="hexagonal")

This leads to:

Error in while (is.null(res) && its < iter && n_is > 0 && ifelse(type == :
missing value where TRUE/FALSE needed

Because n (and therefore n_is) is set to NA if n is missing. Therefore the check "n_is >0" is a "NA > 0" check which leads to an error.

If I additionally specify 'n = 1' it works. I.e.

sp::spsample(coord,cellsize=0.1,type="hexagonal",n=1)

I was following this tutorial:
http://strimas.com/spatial/hexagonal-grids/
which calls the function without n=1. I see now, that it is a required parameter, but it shouldn't be if you can specify the cellsize, should it?

Package Info:
[1] sp_1.2-4
downloaded today from CRAN.