GIS extension demo
Model was written in NetLogo 5.0.3
•
Viewed 2133 times
•
Downloaded 150 times
•
Run 0 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
Info tab cannot be displayed because of an encoding error
Comments and Questions
Click to Run Model
extensions [ gis table ] globals [ projection countries-dataset patch-area-sqkm desired-people patches-to-go people-to-go ] breed [ persons person ] patches-own [ population country-name area population-density ] persons-own [ agent-country-name ] ; setup code -- modified from GIS General Examples by Uri Wilensky ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; to setup ca set projection "WGS_84_Geographic" ; Note that setting the coordinate system here is optional gis:load-coordinate-system (word "data/" projection ".prj") ; Load the dataset set countries-dataset gis:load-dataset "data/countries.shp" ; Set the world envelope. DS = different x and y scales ; (fits to actual world dimensions -- world does not actually have a perfect 2:1 aspect ratio) gis:set-world-envelope-ds [-180 180 -90 90] ; Drawing country boundaries from a shapefile -- as per Uri Wilensky gis:set-drawing-color white gis:draw countries-dataset 1 ; New code set patch-area-sqkm (510000000 / count patches) setup-gis reset-ticks end ; Using gis:apply-coverage to copy values from the country dataset to the patches ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; to setup-gis show "Loading patches..." gis:apply-coverage countries-dataset "POP_CNTRY" population gis:apply-coverage countries-dataset "SQKM" area gis:apply-coverage countries-dataset "CNTRY_NAME" country-name ask patches [ ifelse (area > 0 and population > 0) [ ; Colour patch according to population density set population-density (population / area) set pcolor (scale-color red population-density 400 0) ] [ ; Colour patch with no population blue set population-density 0 set pcolor blue ] ] end ; Create turtles based on patch population density ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; to create-random ; Delete old population ask persons [ die ] ask patches [ if (population-density > 0) [ ; How many people to create? (N.B. this is an overestimate, since country does not occupy entire patch) let num-people (population-density * patch-area-sqkm / 10000000) ; Create whole numbers directly sprout-persons (floor num-people) [ agent-setup country-name ] ; Create fractions probabilistically let fractional-part (num-people - (floor num-people)) if (fractional-part > random-float 1) [ sprout-persons 1 [ agent-setup country-name ] ] ] ] show (word "Randomly created " (count persons) " people") tick end ; Alternate turtle creation using tables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; to create-deterministic ; Reset tables (1) set patches-to-go table:make set people-to-go table:make set desired-people 0 ; Delete old population (2) ask persons [ die ] ; Calculate number of people desired (3) ; N.B. Countries with no patches will be ignored, even if population > 0 foreach gis:feature-list-of countries-dataset [ let ctry gis:property-value ? "CNTRY_NAME" let pop gis:property-value ? "POP_CNTRY" let desired (round (pop / 10000000)) table:put people-to-go ctry desired ] ; Count patches for each country, efficiently, using a single loop (4) ask patches [ if (population-density > 0) [ ; Have we seen this country before? ifelse (table:has-key? patches-to-go country-name) [ ; YES -- record one extra patch for this country let n (table:get patches-to-go country-name) table:put patches-to-go country-name (n + 1) ] [ ; NO -- record first patch, and add population of country to desired total table:put patches-to-go country-name 1 let desired (table:get people-to-go country-name) set desired-people (desired-people + desired) ] ] ] ; Create desired number of people (5) ask patches [ if (population-density > 0) [ let n (table:get patches-to-go country-name) let people-needed (table:get people-to-go country-name) if (people-needed > 0) [ ; More people needed for this country table:put patches-to-go country-name (n - 1) let num-people (round (people-needed / n)) if (num-people > 0) [ ; People needed on this patch table:put people-to-go country-name (people-needed - num-people) sprout-persons num-people [ agent-setup country-name ] ] ] ] ] ; Report number of agents created (6) show (word "Created " (count persons) " people / desired " desired-people) tick end ; Agent setup ;;;;;;;;;;;;; to agent-setup [ ctry ] set shape "person" set size 3 set color black set agent-country-name ctry end
There are 2 versions of this model.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
CountryMedianAge.txt | data | Country median age file (for extending the model) | over 10 years ago, by Anthony Dekker | Download |
GIS extension demo.png | preview | Preview for 'GIS extension demo' | over 10 years ago, by Anthony Dekker | Download |
GISDemoInterface1.png | png | Preview before creating agents | over 10 years ago, by Anthony Dekker | Download |
This model does not have any ancestors.
This model does not have any descendants.
Anthony Dekker
Explanation
This model is associated with a tutorial at http://scientificgems.wordpress.com/2014/05/12/the-netlogo-gis-extension-a-tutorial/
Posted over 10 years ago