简体   繁体   中英

How to create certain number of turtles on the road shapefile and specific area?

I have imported the road shapefile and polygon shapefile and already intersected with patches. I want to create a certain number of turtles in a specific polygon and turtles allow moving only on the road shapefile. For example, In polygon A have turtles 20, polygon B have turtles 30 and I want to let the number of these to show up on its own polygon.

What I have done is I have intersected the road and the polygon by using (I mean 2 foreach for road and polygon)

foreach gis:feature-list-of x
  [ vector-feature ->
    ask patches gis:intersecting vector-feature
      [blah blah blah...]
  ]

Then, I created turtles using this code

to setup
  create-walkers Population
  ask walkers
  [
    set wlocation one-of patches with [pcolor = red]
    ;I have assigned the road shapefile to red color.
    move-to wlocation
end

With only patches is RED, it's work, BUT when I tried to set wlocation one-of patches with [pcolor = red and pcolor = ;another color which is the color of polygon] Netlogo got an error that

move-to expected input to be an agent but got nobody instead

How could I solve this problem?

Thank you in advance.

You appear to have a basic misunderstanding about patches . In NetLogo, a patch is an area of the world and is a single unit. What that means is that the patch can ONLY have one colour. Try running this code (as a new model)

to testme
  ask patches
  [ set pcolor random 256
  ]
end

You can see the patches, each with a randomly allocated colour. Now type inspect one-of patches in the command centre and an inspect window will open for a randomly selected patch. You will see that one of the listed variables is pcolor .

Short answer - a patch can only have one colour, so your request for patches with colour A and colour B is meaningless.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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