在netlogo中从shapefile添加障碍和目标

时间:2019-02-22 19:36:16

标签: netlogo

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

a)通过将坡度shapefile用作障碍物来避免坡度> 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  

1 个答案:

答案 0 :(得分:0)

感谢塞思,我已经使用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相交的红色拼块着色,然后要求母牛避开红色补丁并四处移动。 再次感谢!