如何在Netlogo中从shapefile中创建移动的海龟 [英] how to create moving turtles out of a shapefile in Netlogo

查看:507
本文介绍了如何在Netlogo中从shapefile中创建移动的海龟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是从使用Netlogo创建基于代理的模型开始.我有两个要使用的shapefile:一个城市的网络地图(线形文件)和一个城市中踏板车的点形文件.想法是让他们在网络shapefile的线上穿越城市.由于我是Netlogo的新手,所以我仅设法在模型中加载了这些shapefile.有人可以帮助我从踏板车注册点(点)中创建海龟,并让它们在网络上移动,从而给我一个领先的机会.到目前为止,我在互联网上几乎找不到任何帮助,并且反复试验也无法正常工作.到目前为止,我的代码就是这样:

I'm just starting with using Netlogo to create an Agent Based Model. I have two shapefiles I want to use: a network map of a city (line-shapefile) and a point-shapefile of scooters in the city. The idea is to have them drive through the city on the lines of the network shapefile. Since I am new to Netlogo, I only managed to load these shapefiles in my model. Could someone give me a headstart by helping me to create turtles from the scooter registrations (points) and let them move over the network lines. I have found little help so far on the internet and it won't work with trial and error. So far, my code is just this:

extensions [ gis ]

to load
  ca
  let network gis:load-dataset "Roads_Asmterdam.shp"

  foreach gis:feature-list-of network
  [ gis:set-drawing-color white
    gis:draw ? 0.3

  ]

  let people gis:load-dataset "scooters_Amsterdam.shp"
   foreach gis:feature-list-of people
  [ gis:set-drawing-color blue
    gis:draw people 3

  ]

end

据我所知,我需要一个可以移动海龟的go功能.而且我需要一个函数来从点shapefile中创建可能移动的海龟,但是我还需要让它们知道只使用线条而不是整个区域.

So, as far as I know, I need a to go function where I want to move the turtles. And I need a function to create possible moving turtles out of the point-shapefile, but also I need to let them know to only use the lines instead of the whole area.

非常感谢!

推荐答案

在加载线形文件后,您需要将其转换为代理/海龟网络并进行链接. NetLogo不会为您做到这一点,您需要遍历所有功能,线段并自己进行协调.然后,您需要将踏板车放置在线网络上的坐标上,然后可以询问"它们来回移动.

After loading the lines shape file you need to convert these into a network of agents/turtles and link them. NetLogo doesn't do that for you, you need to iterate over all the features, line segments and coordinates yourself. Then you need to place the scooters onto the coordinates from the line network, and then you can "ask" them to move around.

这是我想出的:

extensions [ gis ]
globals [ roads-dataset scooter-dataset ]
breed [ nodes node ]
breed [ scooters scooter ]
breed [ walkers walker ]
walkers-own [ wlocation ]
scooters-own [slocation]

to setup
  ; reset
  clear-all
  reset-ticks

  ; load data set
  gis:load-coordinate-system (word "C:/Program Files/NetLogo 5.3.1/app/models/Code Examples/GIS/data/WGS_84_Geographic.prj")
  set roads-dataset gis:load-dataset "C:/shape/roads.shp"
  set scooter-dataset gis:load-dataset "C:/shape/scooter.shp"
  gis:set-world-envelope (gis:envelope-of roads-dataset)

  ; draw data set
  gis:set-drawing-color blue
  gis:draw roads-dataset 1

  make-road-network
end

to make-road-network
  clear-links
  let first-node nobody
  let previous-node nobody
  foreach gis:feature-list-of roads-dataset [ ; each polyline
    foreach gis:vertex-lists-of ? [ ; each polyline segment / coordinate pair
      foreach ? [ ; each coordinate
        let location gis:location-of ?
        if not empty? location [ ; some coordinates are empty []
          create-nodes 1 [
            set color green
            set size 1
            set xcor item 0 location
            set ycor item 1 location
            set hidden? true
            if first-node = nobody [
              set first-node self
            ]
            if previous-node != nobody [
              create-link-with previous-node
            ]
            set previous-node self
          ]
        ]
      ]
      set previous-node nobody
    ]
  ]
  ; connect adjacent polylines/roads
  ask nodes [ create-links-with other nodes in-radius 0.001 ]
end

to add-agents
  create-walkers 5 [
    set color red
    set wlocation one-of nodes
    move-to wlocation
  ]
end

to add-scooters
  foreach gis:feature-list-of scooter-dataset [ 
    foreach gis:vertex-lists-of ? [
      let location gis:location-of (first ?)

      create-scooters 1 [
        set color yellow
        set size 1
        set xcor item 0 location 
        set ycor item 1 location

        let nearest-node min-one-of (nodes in-radius 10)[distance myself]
        set slocation nearest-node
        move-to slocation
      ]
    ]
  ]
end

to go
  ask walkers [
    let new-location one-of [link-neighbors] of wlocation
    move-to new-location
    set wlocation new-location
  ]
  ask scooters [
    let new-location one-of [link-neighbors] of slocation
    move-to new-location
    set slocation new-location
  ]
end

我发现一些资源和示例代码特别有帮助:

Some resources and example code I found particularly helpful:

  • NetLogo Programming Guide & example models about "walking" and "networks" that come with NetLogo
  • NetLogo Bag of Tricks - Venice Example Code
  • Duncan Golicher: Importing points into Netlogo and forming a network

这篇关于如何在Netlogo中从shapefile中创建移动的海龟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆