我有动物走动,然后一条线连接他们走到的所有位置。该线形成一个闭合的多边形。我还使用图形扩展来填充多边形以用于视觉目的。但我不知道如何让多边形内的所有斑块成为owner
(即形成多边形的动物)的领土。补丁可能由多个动物拥有。下面的代码说明了重叠的多边形。我真的很感激你的帮助。谢谢!
extensions [graphics]
breed [animals animal]
breed [homeranges homerange]
animals-own
[
Name
X
Y
]
patches-own
[
owner
]
homeranges-own
[
Name
]
to setup
clear-all
random-seed 4
ask patches
[
set owner nobody
set pcolor grey
]
let $colors [brown orange violet sky lime]
let $Name ["t6" "t7" "t8" "t9" "t10"]
ask n-of 5 patches with [(pycor < 10 and pycor > -10) and (pxcor < 10 and pxcor > -10)]
[
sprout-animals 1
[
set shape "circle"
set color item who $colors
set pcolor color
set X (list xcor)
set Y (list ycor)
set Name item who $Name
set owner self
]
]
graphics:initialize min-pxcor max-pycor patch-size
reset-ticks
end
to go
repeat 5
[
ask animals
[
rt 45
fd 2
set X lput pxcor X
set Y lput pycor Y
set pcolor [color] of self
]
]
ask animals
[
pen-up
let tempXY (map [list ?1 ?2] X Y)
graphics:fill-polygon tempXY
; create a turtle, which draws the homerange boundary
hatch-homeranges 1
[
hide-turtle
set Name [Name] of myself
set color [color] of myself
]
; draw the homerange boundary
foreach tempXY
[
ask homeranges with [Name = [Name] of myself]
[
move-to patch (item 0 ?) (item 1 ?)
pen-down
]
]
; connect the last point of the homerange with the first one, to close the polygon
ask homeranges with [Name = [Name] of myself]
[
let lastpoint first tempXY
move-to patch (item 0 lastpoint) (item 1 lastpoint)
]
]
end
答案 0 :(得分:1)
如果你看一下http://netlogo-users.18673.x6.nabble.com/Netlogo-Point-in-Polygon-td4980030.html,你会发现过去(2012)关于这个问题的解决方案的讨论。
在线程的最后,Jim Lyons发布了一个关于Modeling Commons模型的链接,但模型似乎不再存在于那里。如果你想问他这件事,他是here on Stack Overflow。
答案 1 :(得分:1)
这篇文章中提供了答案:NetLogo - misalignment with imported GIS shapefiles。多边形作为GIS shapefile导出,并使用GIS扩展导入。然后gis:intersecting
用于为那些落在GIS导入的多边形内的补丁提供变量。