Jan Veen
Jan Veen

Reputation: 31

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. How do I create turtles on the location contained in the shapefile and make sure that they have properties also contained in the shapefile?

So far I managed to make a dataset in R and convert it into a shapefile and import it into 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. 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.

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.

The shapefile contains an ID no., a boolean variable and coordinates

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. and the boolean variable for every agent.

Upvotes: 2

Views: 1123

Answers (1)

Jan Veen
Jan Veen

Reputation: 31

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. 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).

I hope this can help somebody!

Upvotes: 1

Related Questions