NetLogo - applying values to patches within polygons

本小妞迷上赌 提交于 2019-12-24 03:32:53

问题


I have animals walk around and a line then connects all the locations that they walked to. The line forms a closed polygon. I also used the graphics extension to fill the polygon for visual purposes. But I don't know how to have all of the patches that fall within the polygon become the territory of the owner (i.e., the animal that formed the polygon). It is possible for patches to be owned by multiple animals. The code below illustrates overlapping polygons. I'd really appreciate any help on this. Thanks!

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

回答1:


If you look at http://netlogo-users.18673.x6.nabble.com/Netlogo-Point-in-Polygon-td4980030.html you'll find a past (2012) discussion of solutions to this problem.

At the end of the thread, Jim Lyons posts a link to a model on the Modeling Commons, but the model doesn't seem to exist there anymore. He's here on Stack Overflow if you want to ask him about it.




回答2:


An answer was provided in this post: NetLogo - misalignment with imported GIS shapefiles. The polygons are exported as a GIS shapefile and imported back in using the GIS extension. Then the gis:intersecting was used to give a variable to those patches that fall within the GIS-imported polygons.



来源:https://stackoverflow.com/questions/22467703/netlogo-applying-values-to-patches-within-polygons

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!