DvB09
DvB09

Reputation: 41

Netlogo - Importing a Shapefile and counting the number of entries on each patch

I have a shapefile containing the location of several thousands of people. I want to import this and for each patch, I'd like to count the amount of people on this exact patch (each person is an entry in the shape file, but multiple people can be located on the exact patch depending on my world size).

I have managed to do so using the following code:

set population-here 0
let population-dataset gis:load-dataset "population_file.shp"
foreach gis:feature-list-of population-dataset [a ->
    ask patches gis:intersecting a [
      set population-here population-here + 1]

However, it takes several hours to load the dataset in a world of -300 to 300 pixels. Is there a faster way of counting the number of individual entries for each patch?

The population should be placed on an underlying shapefile of an area. This area is imported as following:

let area-dataset gis:load-dataset "area.shp"
  ask patches [set world? false]
  gis:set-world-envelope gis:envelope-of area-dataset
  ask patches gis:intersecting area-dataset
  [ set pcolor grey
    set world? true
  ]

Upvotes: 0

Views: 734

Answers (1)

JenB
JenB

Reputation: 17678

Okay, I can't test this and I'm not entirely confident in this answer as I use GIS very rarely. But I suggest you adapt the code in the GIS general examples in the NetLogo model library (see File menu). What you appear to want to do is create a turtle breed for your people, and create a person at each location where there is a person in your population dataset.

breed [people person]

patches-own [population]

to setup
  < all the other stuff you have >
  let population-dataset gis:load-dataset "population_file.shp"
  foreach gis:feature-list-of population-dataset
  [ thisFeature ->
    [ let location gis:centroid-of (first (first (gis:vertex-lists-of thisFeature )))
      create-people 1
      [ set xcor item 0 location
        set ycor item 1 location
      ]
    ]
  ]
  ask patches [ set population count people-here ]
end

You can also import other variables from the population set (eg gender or age group) and have those variables transfer to appropriate attributes of your NetLogo people.

If you haven't found it yet, I recommend this tutorial https://simulatingcomplexity.wordpress.com/2014/08/20/turtles-in-space-integrating-gis-and-netlogo/.

Note that this assumes there is a reason why you want the people in the correct (as defined by the GIS dataset) position for your model rather than simply having some sort of population count (or density) in your GIS file and then create the people in NetLogo on the correct patch.

Upvotes: 1

Related Questions