Good day,
We are attempting to simulate camera-trap sampling within a national park. We'd like to simulate different trap layouts.
I created a cluster of traps as a traps object using make.grid and subset:
#
tenX500 = make.grid(nx = 21, ny = 21, spacex = 500, spacey = 500, detector = "proximity")
#
cross12 = subset(tenX500, subset = c("A11","I11","J11","K 1","K 9",'K10',"K12","K13","K21","L11","M11","U11"))
#
This gives a 10 km X 10 km box or cross shape defined by 4 traps, with a smaller 2 km X 2 km "X" or cross shape in the center.
We have the park boundary as a SpatialPolygonsDataFrame (knpb.spdf). I used it (with gBuffer and make.mask) to define a finite sampling frame for trap.builder:
#
knp.interior = gBuffer(knpb.spdf, width = -4000)
df = data.frame(1)
knp.int = SpatialPolygonsDataFrame(knp.interior, df, match.ID = F)#
fr.mask = make.mask(spacing = 1000, type = c("polygon"), poly = knp.int)#
fr = as.data.frame(fr.mask)#
This gives me a finite sampling frame with points 1000 m apart, all of which are at least 4000 m inside the park boundary.
However, when I try to use trap.builder with edgemethod = c("allinside"), I get error messages
#
> l1 = trap.builder(n = 4, cluster = cross12, region = knpb.spdf, frame = fr,
+ method = c("GRTS"),edgemethod = c("allinside"),detector = "proximity",
+ samplefactor = 10, plt = TRUE)
Stratum: None
Current number of levels: 3
Current number of levels: 5
Final number of levels: 5
Error in trap.builder(n = 4, cluster = cross12, region = knpb.spdf, frame = fr, :
not enough clusters inside polygon
> l1 = trap.builder(n = 4, cluster = cross12, region = knpb.spdf, frame = fr,
+ method = c("GRTS"),edgemethod = c("allinside"),detector = "proximity",
+ samplefactor = 100, plt = TRUE)
Stratum: None
Current number of levels: 5
Current number of levels: 7
Current number of levels: 8
Current number of levels: 9
Final number of levels: 9
Error in origins[i, ] : subscript out of bounds
In addition: There were 50 or more warnings (use warnings() to see the first 50)
#
I tried setting edgemethod = "clip" to see if that was the only problem, and got a different error message.
#
> l1 = trap.builder(n = 4, cluster = cross12, region = knpb.spdf, frame = fr,
+ method = c("GRTS"),edgemethod = c("clip"),detector = "proximity",
+ samplefactor = 10, plt = TRUE)
Stratum: None
Current number of levels: 3
Current number of levels: 5
Final number of levels: 5
Error in `row.names<-.data.frame`(`*tmp*`, value = c("1.A11", "1.I11", :
duplicate 'row.names' are not allowed
In addition: Warning message:
non-unique value when setting 'row.names': ‘NA.NA’
Not sure what I'm doing wrong here, but any advice would be welcome.
Thanks,
Eric