spsample:.local(x, n, type, ...) 中的错误:迭代未收敛;尝试扩大参数 iter
spsample: Error in .local(x, n, type, ...) : iteration did not converge; try enlarging argument iter
当 运行 通过循环生成随机点时,我 运行 遇到了这个错误。如果我只生成一次点,spsample 工作正常,但如果我反复尝试这个,我最终(迟早)会遇到这个错误。关于如何正确解决它的任何想法(我的意思是理论上我可以跳过错误的迭代,但这不是很好的编码,对吧?)。这个问题似乎只发生在 "random" 选项上。
data(meuse.riv)
meuse.sr = SpatialPolygons(list(Polygons(list(Polygon(meuse.riv)), "x")))
#works fine if run just once
n<-10
points<-spsample(meuse.sr, n, "random")
for (i in 1:5000){
print(i)
points<-spsample(meuse.sr, n, "random")
}
我想你应该遵循错误信息的建议:
for (i in 1:5000){
print(i)
points<-spsample(meuse.sr, n, "random", iter=10)
}
运行 通过所有 5000 次迭代,没有错误消息。 ?spsample
说
iter(default = 4) number of times to try to place sample points in a polygon before giving up and returning NULL - this may occur when trying to hit a small and awkwardly shaped polygon in a large bounding box with a small number of points.
所以多给它机会可以解决问题
当 运行 通过循环生成随机点时,我 运行 遇到了这个错误。如果我只生成一次点,spsample 工作正常,但如果我反复尝试这个,我最终(迟早)会遇到这个错误。关于如何正确解决它的任何想法(我的意思是理论上我可以跳过错误的迭代,但这不是很好的编码,对吧?)。这个问题似乎只发生在 "random" 选项上。
data(meuse.riv)
meuse.sr = SpatialPolygons(list(Polygons(list(Polygon(meuse.riv)), "x")))
#works fine if run just once
n<-10
points<-spsample(meuse.sr, n, "random")
for (i in 1:5000){
print(i)
points<-spsample(meuse.sr, n, "random")
}
我想你应该遵循错误信息的建议:
for (i in 1:5000){
print(i)
points<-spsample(meuse.sr, n, "random", iter=10)
}
运行 通过所有 5000 次迭代,没有错误消息。 ?spsample
说
iter(default = 4) number of times to try to place sample points in a polygon before giving up and returning NULL - this may occur when trying to hit a small and awkwardly shaped polygon in a large bounding box with a small number of points.
所以多给它机会可以解决问题