【问题标题】:Exporting a list of patches to a shapefile in NetLogo将补丁列表导出到 NetLogo 中的 shapefile
【发布时间】:2022-10-17 05:19:44
【问题描述】:

我在 NetLogo 中构建了一个基于代理的模型,代理走到目标。我正在使用 NetLogo 6.3 的 GIS 扩展。在每个滴答声中,他们都会将他们当前所在的补丁记录在名为“路径”的列表中。

我想包含一个按钮来将此列表导出到 shapefile,但我不知道该怎么做。我相信我需要使用“gis:store-dataset”功能。我这样使用它:

to export-path  
let file (word "path_output.shp")
  if file-exists? file [file-delete file]
  file-open file
  
  let exported-path path
  gis:store-dataset exported-path file
end

在界面页面上,我设置了一个按钮,使用 ask turtles [] 调用该过程。但是我收到错误消息说这不是数据集。任何人都可以帮助我吗? 谢谢。

【问题讨论】:

    标签: netlogo agent-based-modeling


    【解决方案1】:

    对于计算和精度(取决于你的补丁代表的区域有多大),我建议不要将补丁存储在它们的列表中,海龟只需记录它们的坐标(使用类似 envelope-of 的东西),这样你就可以使用你的 GIS将它们的坐标转换为具有更精细控制的 shapefile:

    extensions [ gis csv ]
    
    turtles-own [ path ]
    
    to setup
      ca
      reset-ticks
      let shp_path "C:/gis_example/british_columbia_administrative.shp"
      let prj_path "C:/gis_example/british_columbia_administrative.prj"
    
      gis:load-coordinate-system prj_path
      let shp gis:load-dataset shp_path
      let base_envelope gis:envelope-of shp
      gis:set-world-envelope-ds base_envelope
      gis:set-drawing-color white
      gis:draw shp 1
      
      ask n-of 3 patches [
        sprout 1 [
          set path ( list self-ticks-coords )
          show path
        ]
      ]
      
    end
    
    to-report self-ticks-coords 
      ; Report the current ticks and then middle two 'envelope' values of the turtle
      report  sentence ticks (reduce sentence sublist gis:envelope-of self 1 3) 
    end
    
    to go
      ask turtles [
        rt random 60 - 30
        fd 1
        set path lput self-ticks-coords path
      ]
      tick
    end
    
    to go-10-then-export
      repeat 10 [
        go 
      ] 
      let out-list reduce sentence [self-who-tick-coords] of turtles
      set out-list fput [ "who" "tick" "x" "y" ] out-list
      csv:to-file "C:/gis_example/example_coords.csv" out-list
    end
    
    to-report self-who-tick-coords
      ; Report a formatted list of who, tick, and coordinate vlaues
      let who-tick-coord-list map [ i -> ( sentence who i ) ] path
      report who-tick-coord-list
    end
    

    这会导出一个 csv,其中存储海龟标识符、时间步长和坐标(并且可以灵活地存储您需要的任何信息),我觉得这更有用。我的两分钱!

    MapCruzin.com下载的数据集

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多