我想计算一个多边形和一个多边形之间的边到边距离,多边形位于一个乌龟之间,每个多边形位于围绕多边形的半径2公里处。多边形由不同的ID表示,每个多边形由几个补丁组成。我获得了一条错误消息,其中包含以下代码“FOREACH预计此输入为列表,但代之以获得代理”。我不明白为什么“[plabel = ID-polygon])的补丁”不是列表?实际上,我想选择标签等于多边形标签的所有贴片。 谢谢你的帮助。
to-report create-edge-turtles [ID-polygon]
let edge-turtles nobody
ask ID-polygon [
foreach (patches with [plabel = ID-polygon]) [
foreach sort neighbors [
sprout 1 [
if [plabel] of neighbors != ID-polygon [
face ?
fd distance ? / 2
set edge-turtles (turtle-set edge-turtles self)] ] ] ] ]
report edge-turtles
end code here
to-report edge-distance-between-polygons-in-buffer [indvidual]
ask individual [
set list-ID-polygon-in-buffer ([plabel] of patch-here in-radius 2)
set list-ID-polygon-in-buffer remove ([plabel] of patch-here) list-ID-polygon-in-buffer
foreach list-ID-polygon-in-buffer [
let ID-polygon-with-individual ([plabel] of patch-here)
let ID-polygon-in-buffer ?
let edges-polygon-with-individual create-edge-turtles ID-polygon-with-individual
let edges-polygon-in-buffer create-edge-turtles ID-polygon-in_buffer
set distance-patches min [ min [ distance myself ] of edges-polygon-in-buffer ] of edges-polygon-with-individual
ask edges-polygon-with-individual [ die ]
ask edges-polygon-in-buffer [ die ] ] ]
report distance-patches
end
答案 0 :(得分:1)
命令
patches with [plabel = ID-polygon]
返回代理集,而不是列表。要将代理集转换为列表,只需使用sort
关键字,就这样
sort patches with [plabel = ID-polygon]