【问题标题】:how to create moving turtles out of a shapefile in Netlogo如何在 Netlogo 中从 shapefile 中创建移动海龟
【发布时间】:2014-11-14 11:56:38
【问题描述】:

我刚刚开始使用 Netlogo 创建基于代理的模型。我有两个要使用的 shapefile:一个城市的网络地图(line-shapefile)和一个城市中踏板车的 point-shapefile。这个想法是让他们沿着网络 shapefile 的路线开车穿过城市。由于我是 Netlogo 的新手,我只设法将这些 shapefile 加载到我的模型中。有人可以通过帮助我从滑板车注册(点)创建海龟并让它们在网络线上移动来给我一个先机。到目前为止,我在互联网上几乎没有找到任何帮助,而且它无法通过反复试验来工作。到目前为止,我的代码是这样的:

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

所以,据我所知,我需要一个 to go 函数来移动海龟。而且我需要一个函数来从点形状文件中创建可能的移动海龟,但我还需要让他们知道只使用线条而不是整个区域。

非常感谢!

【问题讨论】:

    标签: gis netlogo


    【解决方案1】:

    加载线条形状文件后,您需要将它们转换为代理/海龟网络并链接它们。 NetLogo 不会为您这样做,您需要自己迭代所有特征、线段和坐标。然后你需要把滑板车放在线路网络的坐标上,然后你可以“要求”他们四处走动。

    这是我想出的:

    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
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-11
      • 1970-01-01
      • 1970-01-01
      • 2019-05-30
      • 1970-01-01
      • 2015-04-16
      • 2021-09-18
      • 1970-01-01
      相关资源
      最近更新 更多