简体   繁体   English

NetLogo GIS扩展:如何根据shapefile中的位置信息创建海龟

[英]NetLogo GIS extension: How to create turtles according to location information in shapefile

In the process of making a NetLogo model with the gis extension, I am getting stuck at wanting to create turtles according to the shapefile location information. 在使用gis扩展名创建NetLogo模型的过程中,我陷入了想要根据shapefile位置信息创建乌龟的困境。 How do I create turtles on the location contained in the shapefile and make sure that they have properties also contained in the shapefile? 如何在shapefile中包含的位置上创建乌龟,并确保它们具有也在shapefile中包含的属性?

So far I managed to make a dataset in R and convert it into a shapefile and import it into NetLogo. 到目前为止,我设法在R中制作了一个数据集并将其转换为shapefile并将其导入到NetLogo中。 With the code provided I am able to draw points on a map. 使用提供的代码,我可以在地图上绘制点。

But I want to create agents on every location that is contained in the shapefile dataset. 但是我想在shapefile数据集中包含的每个位置上创建代理。 I have searched on the internet, but I cannot find it. 我已经在互联网上搜索了,但是找不到。 Also when I look at the Netlogo user manual, I am not able to do it. 另外,当我查看Netlogo用户手册时,也无法做到。

And in the shapefile dataset an extra characteristic is present which must be assigned to every agent because I want to create an household (agent) per location and according to the characteristic assign a color to it. 并且在shapefile数据集中,存在一个额外的特征,必须将其分配给每个座席,因为我想在每个位置创建一个住所(座席),并根据该特征为其分配颜色。

The shapefile contains an ID no., a boolean variable and coordinates shapefile包含一个ID号,一个布尔变量和坐标

1 16823 0 c(1.7474251, 4.9600897)
2 16873 0 c(1.3272039, 5.1185999) 
3 16874 1 c(1.327054, 5.1162204)
4 16875 0 c(1.3270068, 5.115111)
5 16876 1 c(1.3268986, 5.1130956)

Based on this code I can implement the following code: 基于此代码,我可以实现以下代码:

set-patch-size 6.5
set dataset gis:load-dataset "PlotLocations_HARV.shp"
gis:set-world-envelope gis:envelope-of dataset
gis:set-drawing-color white
gis:draw dataset 1

Which draws points on a map, but I want to sprout agents on the points, keeping the ID no. 这会在地图上绘制点,但我想在这些点上萌生特工,并保留ID号。 and the boolean variable for every agent. 以及每个代理的布尔变量。

In the meantime with the help of you guys and other sources, I've managed to get what I wanted with the following code: 同时,在大家和其他资源的帮助下,我设法通过以下代码获得了想要的东西:

to setup
      ca
      resize-world 0 120 0 120
      set-patch-size 6.5
      set dataset gis:load-dataset "PlotLocations_HARV3.shp"
      gis:set-world-envelope gis:envelope-of dataset
      gis:set-drawing-color white
      gis:draw dataset 1
      displayhh
end

to displayhh
  foreach gis:feature-list-of dataset [
    vector-feature ->
    let coord-tuple gis:location-of (first (first (gis:vertex-lists-of vector-feature)))
    let pv gis:property-value vector-feature "CC_PV_A"

   let long-coord item 0 coord-tuple
    let lat-coord item 1 coord-tuple

    create-turtles 1 [ set pv1 pv setxy long-coord lat-coord ]
  ]

end

Where the shapefile is the database to be imported. 其中shapefile是要导入的数据库。 And CC_PV_A is the boolean variable that is stated in the shapefile and assigned to turtles in the form of pv1 (with pv as an intermediary variable). CC_PV_A是在shapefile中声明并以pv1形式(以pv作为中间变量)分配给乌龟的布尔变量。

I hope this can help somebody! 我希望这可以帮助某人!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM