简体   繁体   English

如何在道路形状文件和特定区域上创建一定数量的海龟?

[英]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.我已经导入了道路 shapefile 和多边形 shapefile 并且已经与补丁相交。 I want to create a certain number of turtles in a specific polygon and turtles allow moving only on the road shapefile.我想在特定多边形中创建一定数量的海龟,海龟只允许在道路 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.例如,在多边形 A 中有 20 只海龟,多边形 B 有 30 只海龟,我想让这些海龟的数量显示在它自己的多边形上。

What I have done is I have intersected the road and the polygon by using (I mean 2 foreach for road and polygon)我所做的是我通过使用将道路和多边形相交(我的意思是道路和多边形的 2 个foreach

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只有补丁是红色的,它可以工作,但是当我尝试set wlocation one-of patches with [pcolor = red and pcolor = ;another color which is the color of polygon] Netlogo 出现错误

move-to expected input to be an agent but got nobody instead move-to预期输入是代理但没有人代替

How could I solve this problem?我怎么能解决这个问题?

Thank you in advance.先感谢您。

You appear to have a basic misunderstanding about patches .您似乎对patches有一个基本的误解。 In NetLogo, a patch is an area of the world and is a single unit.在 NetLogo 中,补丁是世界的一个区域,是一个单独的单元。 What that means is that the patch can ONLY have one colour.这意味着patch只能有一种颜色。 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.现在在命令中心输入inspect one-of patches ,一个inspect窗口将打开一个随机选择的补丁。 You will see that one of the listed variables is pcolor .您将看到列出的变量之一是pcolor

Short answer - a patch can only have one colour, so your request for patches with colour A and colour B is meaningless.简短的回答 - 一个补丁只能有一种颜色,所以你对颜色 A 和颜色 B 的补丁的要求是没有意义的。

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

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