【问题标题】:Adding obstacles and targets from shapefile in netlogo在 netlogo 中从 shapefile 添加障碍物和目标
【发布时间】:2019-02-22 19:36:16
【问题描述】:

我是 NetLogo 的新手,所以如果这个问题非常愚蠢,我提前道歉。我想创建一个基于代理的模型,让动物在复杂的地形中四处寻找水源。运动应该是下坡,受陡坡(>25°)的限制,目标应该是湖泊。为此,我正在使用来自 GIS 数据的真实示例,并且我已经设法设置了一个包含 ASCII 高程网格的世界、一个包含表示陡峭 25 度斜坡的线的 shapefile 和一个包含表示湖泊的区域的 shapefile。我创建了动物(奶牛)并找到了一条代码行,告诉它们下坡。现在,我想告诉他们

a) 通过使用坡度形状文件作为障碍物来避免 >25° 的坡度和

b) 以湖泊 shapfiles 为目标前往湖泊

有人可以帮我编写代码吗? 提前谢谢了! 这是我到目前为止整理的代码

breed [ cows cow ]

extensions [ gis ]
patches-own [ elevation ]

globals [ 
  slope-dataset
  lake-dataset
elevation-dataset
]

to setup-terrain

  clear-all

  reset-ticks

set slope-dataset gis:load-dataset "FILENAME.shp" ;;extent of GIS datasets is N42.3-43.4 and W120.0-121.1

set lake-dataset gis:load-dataset "FILENAME.shp"

set elevation-dataset gis:load-dataset "FILENAME.asc"

gis:set-world-envelope gis:envelope-of slope-dataset

gis:set-world-envelope gis:envelope-of lake-dataset

gis:set-world-envelope gis:envelope-of elevation-dataset

end

to display-slopes


gis:set-drawing-color red

gis:draw slope-dataset 0.5

end


to display-lakes

gis:set-drawing-color blue

gis:draw lake-dataset 2

end


to display-elevation-in-patches

gis:apply-raster elevation-dataset elevation

let min-elevation gis:minimum-of elevation-dataset

let max-elevation gis:maximum-of elevation-dataset

ask patches

[ ; note the use of the "<= 0 or >= 0" technique to filter out

; "not a number" values, as discussed in the documentation.

if (elevation <= 0) or (elevation >= 0)

[ set pcolor scale-color black elevation min-elevation max-elevation ] ]

end


to setup-cows

set-default-shape cows "cow"

create-cows 100 [

setxy random-pxcor random-pycor

set size 1

set color white
  ]

end


to move

move-to patch-here ;; go to patch center

let p min-one-of neighbors [elevation]

if [elevation] of p < elevation [

face p

move-to p ;; makes cows move to the next lower elevation patch, if no lower 
elevetion is present, cow doesn't move
  ]

end


to go

ask cows [

move
  ]
end  

【问题讨论】:

  • 你到底在坚持什么? “有人可以帮助我”不是一个真正的问题......
  • 感谢您的回复,很抱歉在我的第一篇文章中过于含糊。我一直在寻找一种方法让奶牛将我的输入 shapefile 分别识别为障碍物或目标。我找到了一些例子,其中某种颜色的补丁(或者如果使用高程模型作为输入文件的高程)可以用作障碍物或目标,但我也没有设法为此使用 shapefile。这甚至可能吗?
  • 我自己没有使用过 GIS 扩展,但看了一眼 ccl.northwestern.edu/netlogo/docs/gis.htmlgis:intersects?gis:contains? 等原语似乎相关?

标签: netlogo


【解决方案1】:

感谢 Seth,我找到了使用 gis:intersects 的解决方案?你建议的原语:

to display-slopes
ask patches gis:intersecting slope-dataset
[ set pcolor red ]
end 

to go
ask cows
[fd 1
avoid-ostacles]
tick
end

to avoid-obstacles 
ask cows [
if [pcolor] of patch-ahead 1 = red 
[rt 90 fd 1]] 
end 

这样,我可以将与包含坡度矢量数据集的 shapefile 相交的斑块涂成红色,然后让奶牛避开并在红色斑块周围移动。 再次感谢!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-12
    • 1970-01-01
    • 2011-08-25
    • 2022-07-22
    • 2016-05-12
    相关资源
    最近更新 更多