Netlogo 使用.shp文件中的开始和结束节点创建和命名链接

Netlogo 使用.shp文件中的开始和结束节点创建和命名链接,netlogo,Netlogo,.shp文件的属性表具有以下格式: street_name start_node end_node street_1 A B street_1 B C street_2 B D 如何使用开始节点和结束节点创建链接,然后为每个链接指定与其开始节点和结束节点关联的街道名称。例如,具有起始节点A和结束节点B的链接应获得名称“street_1”,而具有起始节点B和结束节点D的街道应获得名称“street_2” 我

.shp文件的属性表具有以下格式:

street_name  start_node  end_node

street_1     A           B
street_1     B           C
street_2     B           D
如何使用开始节点和结束节点创建链接,然后为每个链接指定与其开始节点和结束节点关联的街道名称。例如,具有起始节点A和结束节点B的链接应获得名称“street_1”,而具有起始节点B和结束节点D的街道应获得名称“street_2”

我使用foreach
gis:feature list of
链接数据集的节点,但这种方式我无法根据它们的开始和结束节点命名链接,因为一些节点在街道段之间共享

非常感谢

编辑:

我感兴趣的属性表的列是name1、startNode和endNode。我已经使用下面的代码连接了节点,现在我有了一个完全连接的道路网络。我不确定如何集成您的代码,以便节点之间的链接将获得与构成该链接的节点组合相关联的名称

foreach gis:feature-list-of roads-dataset [ vector-feature ->
    foreach  gis:vertex-lists-of vector-feature [ vertex ->
      let previous-turtle nobody
      foreach vertex [point ->
        let location gis:location-of point
        if not empty? location
        [
          let x item 0 location
          let y item 1 location
          let current-node one-of (turtles-on patch x y) with [ xcor = x and ycor = y ]
          if current-node = nobody [
            create-nodes 1 [
              setxy x y
              set size 0.2
              set shape "circle"
              set color black
              set hidden? true
              set name gis:property-value vector-feature "name1"
              set current-node self
            ]
          ]
          ask current-node [
            if is-turtle? previous-turtle [
              create-link-with previous-turtle
            ]
            set previous-turtle self
          ]
        ]
      ]
    ]
  ]

你是说你的节点现在在你的模型中被正确命名了吗?如果是这样的话,这里有一个简化版的方法,可能对你有用。我会注意到,这不是一种非常有效的方法,因为它会在链接和属性表之间循环,所以如果有很多链接,则需要一段时间。首先,由于我没有您的shapefile,我制作了一个版本的链接示例:

extensions [csv]

globals [ whole-file ]
turtles-own [ node ]
links-own [ name ]

to setup
  ca
  reset-ticks
  let names [ "A" "B" "C" "D" ]
  let n 0
  crt 4 [
   setxy random 30 - 15 random 30 - 15
   set node item n names
   set n n + 1
  ] 

  ask turtles with [ node = "A" ] [
    create-links-to turtles with [node = "B" ]
  ]
  ask turtles with [ node = "B" ] [
    create-links-to turtles with [ node = "C" or node = "D" ]
  ]
end
这只构建了四个Turtle,其链接如示例shapefile属性表所示。我使用的文件名为“node_example.csv”,如下所示:

  street_name start_node end_node
1    street_1          A        B
2    street_1          B        C
3    street_2          B        D
共有四列,其中第一列为观察编号

基本上,这种方法是迭代列表,从
end1
end2
提取节点的名称,反之亦然(因为
两端将以随机顺序提取它们),并将它们与表中的每个
开始节点
结束节点
组合进行比较。如果匹配,则将该行的
街道名称
指定给匹配的链接:

to link-name 

  set whole-file csv:from-file "node_example.csv"

  foreach sort links [
    [ i ] ->
    show i
    let way-1 list ( [node] of [end1] of i ) ( [node] of [end2] of i )
    let way-2 list ( [node] of [end2] of i ) ( [node] of [end1] of i )
    foreach whole-file [
      [j] ->
      if sublist j 2 4 = way-1 or sublist j 2 4 = way-2 [
        ask i [
          set name item 1 j
        ]
      ]
    ]
  ]

  ask links [
    print name
    print (word [node] of end1 [node] of end2 )
  ]

end
显然,这是基于在模型中命名的节点(在本例中,使用的变量是
node
)-如果不是这种情况,这将不起作用

编辑1

好的,我用你的形状文件玩了一会儿。这还不完美,我暂时不能再做了,但也许它会让你开始。使用此设置:

extensions [gis]

breed [ nodes node ]
globals [ roads-dataset ]
turtles-own [ name line-start line-end]
links-own [ lname ]
我的想法是将起点和终点节点名称指定给线要素沿线的每个点,以便链接可以对照要素列表进行检查。注释中有更具体的注释,但我基本上修改了gis要素节点代码来实现这一点。玩一玩(运行需要一段时间),你会发现有一些差距我还没有完全弄清楚-也许你可以取得进展

to gis-feature-node
  set roads-dataset gis:load-dataset  "road_links.shp"
  foreach gis:feature-list-of roads-dataset [ vector-feature ->

    ; First, grab the names of the starting and ending node for the current 
    ; vector feature in order to assign common names to all nodes within
    ; the feature

    let first-vertex gis:property-value vector-feature "startNode"
    let last-vertex gis:property-value vector-feature "endNode"

    foreach  gis:vertex-lists-of vector-feature [ vertex ->
      let previous-turtle nobody

      foreach vertex [ point ->
        let location gis:location-of point
        if not empty? location
        [
          let x item 0 location
          let y item 1 location
          let current-node one-of (turtles-on patch x y) with [ xcor = x and ycor = y ]
          if current-node = nobody [
            create-nodes 1 [
              setxy x y
              set size 0.05
              set shape "circle"
              set color white
              set hidden? false
              set name gis:property-value vector-feature "name1"

              ; Here you assign the first-vertex and last-vertex of the entire line
              ; to each node
              set line-start first-vertex 
              set line-end last-vertex
              set current-node self 
            ]
          ]
          ask current-node [
            if is-turtle? previous-turtle [
              create-link-with previous-turtle
            ]
            set previous-turtle self
          ]
        ]
      ]
    ]
  ]

  ask links [ 
    ;; Here is a major slowdown- reiterate through the entire roads-dataset
    ;  and, if the names in "startNode" and "endNode" match, assign the
    ;  value from "name1" to the link currently being created.
    let way-1 list [line-start] of end1 [line-end] of end2 
    let way-2 list [line-end] of end1 [line-start] of end2  
    foreach gis:feature-list-of roads-dataset [ vector-feature-sub ->
      let vector-start gis:property-value vector-feature-sub "startNode"
      let vector-end gis:property-value vector-feature-sub "endNode"
      let start-end list vector-start vector-end

      if way-1 = start-end or way-2 = start-end [
        set lname gis:property-value vector-feature-sub "name1"
      ]
    ]
  ] 

  ask links with [ lname = "Hamilton Place" ] [
    set color red 
    set thickness 0.2
  ]
  ask links with [ lname = "Whitcomb Street" ] [
    set color yellow
    set thickness 0.2
  ]

end
编辑2

下面的代码已经过测试,可以解决问题了

    ask links [
    set is-road? true
    ;; Here is a major slowdown- reiterate through the entire roads-dataset
    ;  and, if the names in "startNode" and "endNode" match, assign the
    ;  value from "name1" to the link currently being created.
    let way-1 list [line-start] of end1 [line-end] of end2
    let way-2 list [line-end] of end1 [line-start] of end2
    let way-3 list [ line-start ] of end1 [ line-end ] of end1
    let way-4 list [ line-start ] of end2 [ line-end ] of end2
    foreach gis:feature-list-of roads-dataset [ vector-feature-sub ->
      let vector-start gis:property-value vector-feature-sub "startNode"
      let vector-end gis:property-value vector-feature-sub "endNode"
      let start-end list vector-start vector-end
      let end-start list vector-end vector-start

      if way-1 = start-end or way-2 = start-end or way-3 = start-end or way-4 = start-end [
        set lname gis:property-value vector-feature-sub "name1"
      ]
    ]
  ]

我编辑了我的帖子,还上传了.shp和其他相关文件,这些文件可以从这个共享的Ok第二轮中访问!看一看,看看这是否有助于你打赌!我肯定地发现它跳过了一些片段,而我现在还没有时间去弄清楚原因——但肯定地是(至少对我来说)它在~6000个链接中丢失了大约1800个链接。也许通过一些调整它会完全工作。。。祝你好运我来看看。我刚刚检查了一下,确实有2358个链接
lname=0
。但是谢谢你的开始。这是一种展示我想要的结果的方式。你可以打赌,如果你最终完全弄明白了,我很想听听你是如何做到的。干杯