可能有很多方法可以解决这个问题,但这里有两种选择。首先,我在 Esri Open 数据中找到的一些示例数据 - 2015 population data for Haiti。我将 shapefile 和相关文件提取到一个名为“gis”的文件夹中。我们将使用在 `gis:property-name': "POPULATION" 中找到的人口值。使用此设置:
extensions [ gis ]
globals [
state-layer
]
to setup
ca
resize-world 0 110 0 80
set-patch-size 6.5
set state-layer gis:load-dataset "gis/Population_2015.shp"
gis:set-world-envelope gis:envelope-of state-layer
gis:set-drawing-color white
gis:draw state-layer 1
reset-ticks
end
第一种选择是在每个特征的质心处仅生成整个种群(在本例中,除以 1000 以不生成太多海龟)。
to sprout-at-centroid
foreach gis:feature-list-of state-layer [
state ->
; Get the population for this state, divided by 1000
; to get a reasonable number
let pop ( gis:property-value state "POPULATION" ) / 1000
; get the 'gis:location-of', an x-y list, for the
; centroid of the current state / district
let center gis:location-of gis:centroid-of state
; get the patch with the center xy values to sprout pop
ask patch first center last center [
sprout pop
]
]
end
输出如下所示:
看起来不错!所有海龟都在每个要素的地理中心发芽。但是,根据您的数据集,您可能会遇到问题。请注意,中心的岛屿实际上是多部分要素的一部分,因此该多部分要素的人口已经在边界之外产生。这可能不会对您造成问题,具体取决于您所在地区的形状。
选项 2 有点复杂,您可能会引入一些舍入误差。它也慢得多,并且根据您的世界和人口的大小可能需要很长时间/您可能会耗尽内存。首先,获取您的人口数量和您所在地区的补丁数量。然后,将人口除以该地区的斑块,得到每个斑块的平均人口。然后,让每个包含的补丁发芽那个数量的海龟:
to apply-evenly
foreach gis:feature-list-of state-layer [
state ->
; Get the population for this state, divided by 10000
; to get a reasonable number
let pop ( gis:property-value state "POPULATION" ) / 1000
; Get the patches contained by the state. This is slow!
; Using 'gis:intersecting' alone is much faster, but results
; in overlaps as geographic boundaries don't align with patch boundaries
let target-patches ( patches gis:intersecting state ) with [ gis:contained-by? self state ]
if any? target-patches [
; Get the number of turtles that should be in each target-patch:
let avg-turtles round ( pop / count target-patches )
; Get the contained patches to sprout the appropriate number of turtles
ask target-patches [
sprout avg-turtles
]
]
]
end
这个的输出看起来像:
但请注意,与我在此处作为示例使用的相比,更大的人口确实需要更长的时间,特别是因为我除以 1000。另外请注意,如果您的补丁太大而无法包含在某个地区,你的地区不会有任何海龟产卵(例如,南海岸附近的小岛)。
希望这能让你指出正确的方向!