'Trying to sprout turtles from a point shapefile

I have a point shapefile indicating the name of the village, households and total population of each village. I've had success uploading it on Netlogo but I'm having trouble working out a solution to relate the # of households and population of each village to different turtle groups. I want to be able to sprout turtles using the population value within each village. The following code is what I'm using currently but would love some help with understanding how to relate the attribute value in the shapefile to create my model.

To display the shapefile I'm using the following:

to display-villages
   gis:create-turtles-from-points villages houses [
    set size 4
    set color red
    set shape "house"
     ]
end

The shapefile villages has attributes relating to population, and number of households. But at the moment I'm only able to sprout one village at the point location of the shapefile.

The gis:property-value code doesn't work for me for some reason. I've tried removing the Z value from the shapefile and other suggestions posted by members but it gives me an error. So I'd appreciate some workaround with my current code.

Thank you!



Solution 1:[1]

If you read the documentation for gis:create-turtles-from-points you will see that it creates one turtle per point, so it will not solve your problem.

Instead, you need to:

  • Read in the GIS point coverage using gis:load-dataset
  • Get a list of all the points, using gis:feature-list-of
  • For each of those points, create the number of turtles you want, reading that number from the point via gis:property-value
  • When you create each turtle, move it to the location of the point. That location is obtained via gis:location-of, which returns a list with the X and Y coordinates of the point.

The GIS code example in the Models Library is very helpful. You will probably end up with code like this (which I have not tested), assuming "population" is your GIS property containing the number of turtles at a point:

; Read in the shapefile of cell polygons
set points-dataset gis:load-dataset GIS-file-name

(some code to re-size the world, copied from Models Library.)

foreach (gis:feature-list-of points-dataset) [next-point ->
  let num-turtles-here gis:property-value next-point "population"
  let point-location gis:location-of next-point
  create-turtles num-turtles-here
  [
    ; code to put the new turtles at the point's location
    setxy item 0 point-location item 1 point-location
  ]
] ; end of foreach

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Steve Railsback