Question

Using GIS extension of NetLogo, how to give a value to a turtle attribute, according to the value of the polygon on which the turtle is placed?

I need to create agents of breed “house” that are located on a polygon.

Each polygon has an attribute :

CODE,

which is a unique value, and that value must be assigned to each house-agent in its house-attribute

breed [ houses house ]

...

houses-own [ ...
             c_commune
             ...
             ]

I am using this procedure:

to draw-houses

  foreach gis:feature-list-of comuna-dataset [

    this-comuna ->
    let prop_houses gis:property-value this-comuna "Prop_v"
    let code        gis:property-value this-comuna "CODIGO"

    let houses-in-comuna round ( prop_houses * number_houses )

    gis:create-turtles-inside-polygon this-comuna houses houses-in-comuna [
      set shape   "square 2"
      set size     0.5
      set color    blue
      set c_comuna code  ; it is displaying the last value
      set label    c_comuna
    ]
  ]

end

The problem is the double loop made by foreach

gis:feature-list-of 

and

gis:create-turtles-inside-polygon 

blocks, which are overwriting the last value for all house-agents, and they end up with the same value.

 2  20  2
1 Jan 1970

Solution

 1

procedure should rather read :

to draw-houses

  foreach gis:feature-list-of
                           comuna-dataset [
                      this-comuna ->

    let prop_houses gis:property-value this-comuna "Prop_v"
    let code        gis:property-value this-comuna "CODIGO"

    let houses-in-comuna round ( prop_houses * number_houses )

    gis:create-turtles-inside-polygon           ;; proc
                              this-comuna       ;; where
                              houses            ;; what
                              houses-in-comuna  ;; how many
                              [                 ;; to-do [ cmd ... ]
      set shape    "square 2"
      set size      0.5
      set color     blue
  ;;  set c_comuna  code  ; it is displaying the last value
      set c_commune code 
  ;;  set label     c_comuna
      set label     code
      ]
  ]

end
2024-07-23
user3666197