NetLogo - Errors during the setup with GIS extension - gis

I'm trying to load some shapefiles in Netlogo with the extension gis but it don't work. When I click on the button "initialisation" I have this error :
Extension exception: unsupported shape type 15
error while observer running GIS:LOAD-DATASET
called by procedure INITIALISATION
called by Button 'Initialisation'
This button change the color of patches to white for the world. So even if I have this error, it can load a white background...
Then, I'm trying to load some shapefiles : font (municipality of Genevois a natural region of Haute-Savoie/Upper Savoy,France), hydrology (lakes and rivers), urban areas and mountain (above 1250 meters).
The button for loading the font and urban areas works, that's not the case of the others shapefiles, I have this error :
Extension exception: not a VectorFeature, Agent, AgentSet, or List: 0.0
error while observer running GIS:INTERSECTING
called by procedure IMPORT.MOUNTAIN
called by Button 'Montagne'
That's the same error for hydrology.
Do you know how can I solve these errors ?
Here is my code :
;; Ajout de l'extension gis pour integrer des zones géographiques
extensions [ gis ]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Creation des variables globales
globals
[
font-dataset
urban-dataset
hydrology-dataset
mountain-dataset
]
patches-own
[
font? ;; indicates if the cell is sea
urban? ;; indicates if the cell is urban
hydrology?
mountain?
]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; initialisation
to total.initialisation
ca
end
to initialisation
ask patches[
set pcolor white
set font? false
set urban? false
set hydrology? false
set mountain? false
]
set font-dataset gis:load-dataset "font.shp"
set urban-dataset gis:load-dataset "urban.shp"
set hydrology-dataset gis:load-dataset "hydrology.shp"
set mountain-dataset gis:load-dataset "mountain.shp"
reset-ticks
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;import data
to import.all
import.font
import.urban
import.hydrology
import.mountain
end
to import.font
ask patches gis:intersecting font-dataset
[
set font? true
set urban? false
set hydrology? false
set mountain? false
set pcolor 58
]
end
to import.urban
ask patches gis:intersecting urban-dataset
[
set urban? true
set font? false
set hydrology? false
set mountain? false
set pcolor 16
]
end
to import.hydrology
ask patches gis:intersecting hydrology-dataset
[
set hydrology? true
set font? false
set urban? false
set mountain? false
set pcolor 96
]
end
to import.mountain
ask patches gis:intersecting mountain-dataset
[
set mountain? true
set font? false
set urban? false
set hydrology? false
set pcolor 34
]
end ```

Related

I can't moving the turtle

I'm just starting in netlogo to create an agent-based model. I've got 2 shapefiles, and I want to make my turtle move on my network map. For now I have only can managed to load the shapefiles in my model. Could someone give me an idea how to move the turtle on my network map?
Here is my code so far:
extensions [gis]
breed [cars car]
turtles-own [destination]
globals [
states-dataset
car-blue]
to custom-clear
reset-ticks
clear-turtles
clear-patches
clear-drawing
clear-all-plots
end
to setup
clear-all
custom-clear
ask patches [set pcolor green - 3]
set states-dataset gis:load-dataset "C:/Users/ADMIN/Documents/QGIS/Export Netlogo/Format .shp/state.shp"
gis:set-world-envelope gis:envelope-of states-dataset
gis:set-drawing-color yellow
gis:draw states-dataset 1
set route-car-blue gis:load-dataset "C:/Users/ADMIN/Desktop/routefiles/Shapefile/car/route-car-blue.shp"
gis:set-drawing-color blue
gis:draw angkot-permatabiru 1.5
foreach gis:feature-list-of route-car-blue
[car-pb -> let location gis:location-of gis:centroid-of car-pb
create-turtles 5 [
set xcor item 0 location
set ycor item 1 location
set shape "car"
set size 1
]]
end
to go
ask turtles [
let new-location one-of [link-neighbors] of destination
move-to new-location
set destination new-location]
tick
end
Does anybody know to fix my code? I want to make my turtle move based on my network map.
The problem is probably in the circularity of your destination and new-location. You define new-location as being a link-neighbor of your destination, but since you don't have a destination yet, this new-location is set to nobody. You then set your destination to be your new-location, which also sets destination to nobody, ending up in a circle where no movement is happening.
The fix for this would be to define a destination for each turtle during setup

Netlogo GIS: How can I create agents random location inside the specific region?

I have loaded shapfile and then I want to create turtles inside the map for simulating.
However, I use "gis:create-turtles-inside-polygon" then the agents just appear in same point. How can I put them in random places but inside the map?
with the following code
to setup-maps
gis:load-coordinate-system "dem.prj"
set Bangladesh gis:load-dataset "dem.shp"
set elevation gis:load-dataset "dem.asc"
gis:set-world-envelope gis:envelope-of elevation
gis:set-drawing-color red + 2
gis:draw Bangladesh 1
end
to setup-turtles
foreach gis:feature-list-of Bangladesh [ this-vector-feature ->
gis:create-turtles-inside-polygon this-vector-feature turtles 10 [
set shape "person"
set size 2.5
set color white
]
]
end
Are your shapefiles color coordinated? In which case you could make use of their color to determine where the turtles are placed.
A quick example of how I do this below. I save my map as an image first (PNG), and then use the import-pcolors function in NetLogo. That skips the need for the GIS extension.
to define-airplane-regions
ask patches with [pcolor = 14.9] [set namibia true] ask patches with [pcolor = 45.3] [set botswana true] end
to appear-aircrafts
if any? patches with [namibia = true][ ask one-of patches with [namibia = true] [sprout-aircrafts 3]] end
I have a tutorial on YouTube showing how to do this in more detail. All code in the video description.
https://youtu.be/VzvgBzO7ls0

Hide Road shapefile after create it's network in NetLogo

I would like to clear shape file in NetLogo world but i can not do this.
network line (on road shape file) is created and match with road shape file. Now i should clear road shape file and keep just road network.
can u help me to do this?
with respect regard
enter image description here
extensions [ gis ]
globals [ roads-dataset scooter-dataset ]
breed [ nodes node ]
breed [ scooters scooter ]
breed [ walkers walker ]
walkers-own [ wlocation ]
scooters-own [slocation]
to setup
; reset
clear-all
reset-ticks
; load data set
; gis:load-coordinate-system ("WGS 1984.prj")
set roads-dataset gis:load-dataset "layer/road.shp"
;set scooter-dataset gis:load-dataset "layer/lands.shp"
gis:set-world-envelope (gis:envelope-of roads-dataset)
; draw data set
gis:set-drawing-color blue
gis:draw roads-dataset 1
make-road-network
end
to make-road-network
clear-links
let first-node nobody
let previous-node nobody
foreach gis:feature-list-of roads-dataset [ ; each polyline
foreach gis:vertex-lists-of ? [ ; each polyline segment / coordinate pair
foreach ? [ ; each coordinate
let location gis:location-of ?
if not empty? location [ ; some coordinates are empty []
create-nodes 1 [
set color green
set size 1
set xcor item 0 location
set ycor item 1 location
set hidden? true
if first-node = nobody [
set first-node self
]
if previous-node != nobody [
create-link-with previous-node
]
set previous-node self
]
]
]
set previous-node nobody
]
]
; connect adjacent polylines/roads
ask nodes [ create-links-with other nodes in-radius 0.001 ]
end
just remove the line gis:set-drawing-color blue
Best,
A

Using 2 maps in netlogo

Is it possible to use two maps in a netlogo model? If yes, how to combine or to import it to netlogo?
The first map has land use value and the second map has the land price value. So, I need these two attribute to support my model.
Below code is for importing the first map;
to-report read-map[m]
let raster-map gis:load-dataset m
gis:load-dataset m
gis:set-world-envelope gis:envelope-of raster-map
report raster-map
end
to read-input-maps[m]
let data-source word"data/input/maps/" m
let input-map read-map data-source
gis:apply-raster input-map map-value
ask patches
[set map-value ifelse-value (map-value <= 0 or map-value >= 0)
[map-value]
[-9999]]
end
to read-map-attributes[m]
let data-source word "data/input/maps/"m
file-open data-source
set n-cols read-from-string remove "NCOLS"file-read-line
set n-rows read-from-string remove "NROWS" file-read-line
set xll read-from-string remove "XLLCORNER" file-read-line
set yll read-from-string remove "YLLCORNER" file-read-line
set cell-size read-from-string remove "CELLSIZE"file-read-line
file-close
resize-map
end
to resize-map
resize-world 0 n-cols 0 n-rows
set-patch-size 50 / cell-size
end
to display-map
ifelse input-file = "turi3400m2.asc"[
ask patches with[map-value = 1] [ set pcolor orange];Hutan sekunder orange
ask patches with[map-value = 2] [ set pcolor orange];Semak/belukar orange
ask patches with[map-value = 3] [ set pcolor yellow];Permukiman yellow
ask patches with[map-value = 4] [ set pcolor green];Kebun campuran green
ask patches with[map-value = 5] [ set pcolor green];Sawah green
ask patches with[map-value = 6] [ set pcolor orange];Tanah terbuka orange
ask patches with[map-value = 7] [ set pcolor green];Tegalan/ladang green
]
end
to setup-function [m]
read-map-attributes m
read-input-maps m
display-map
end
to setup
ca
setup-function
Input-File
Please help to solve this problem.
How about replacing:
patches-own [map-value]
gis:apply-raster input-map map-value
with:
patches-own [map-value-1 map-value-2]
ifelse m = "..."
[ gis:apply-raster input-map map-value-1 ]
[ gis:apply-raster input-map map-value-2 ]
This is the simplest possible fix I can think of. Is it adequate for your use case?

how to create moving turtles out of a shapefile in Netlogo

I'm just starting with using Netlogo to create an Agent Based Model. I have two shapefiles I want to use: a network map of a city (line-shapefile) and a point-shapefile of scooters in the city. The idea is to have them drive through the city on the lines of the network shapefile. Since I am new to Netlogo, I only managed to load these shapefiles in my model. Could someone give me a headstart by helping me to create turtles from the scooter registrations (points) and let them move over the network lines. I have found little help so far on the internet and it won't work with trial and error. So far, my code is just this:
extensions [ gis ]
to load
ca
let network gis:load-dataset "Roads_Asmterdam.shp"
foreach gis:feature-list-of network
[ gis:set-drawing-color white
gis:draw ? 0.3
]
let people gis:load-dataset "scooters_Amsterdam.shp"
foreach gis:feature-list-of people
[ gis:set-drawing-color blue
gis:draw people 3
]
end
So, as far as I know, I need a to go function where I want to move the turtles. And I need a function to create possible moving turtles out of the point-shapefile, but also I need to let them know to only use the lines instead of the whole area.
Many thanks in advance!
After loading the lines shape file you need to convert these into a network of agents/turtles and link them. NetLogo doesn't do that for you, you need to iterate over all the features, line segments and coordinates yourself. Then you need to place the scooters onto the coordinates from the line network, and then you can "ask" them to move around.
Here's what I came up with:
extensions [ gis ]
globals [ roads-dataset scooter-dataset ]
breed [ nodes node ]
breed [ scooters scooter ]
breed [ walkers walker ]
walkers-own [ wlocation ]
scooters-own [slocation]
to setup
; reset
clear-all
reset-ticks
; load data set
gis:load-coordinate-system (word "C:/Program Files/NetLogo 5.3.1/app/models/Code Examples/GIS/data/WGS_84_Geographic.prj")
set roads-dataset gis:load-dataset "C:/shape/roads.shp"
set scooter-dataset gis:load-dataset "C:/shape/scooter.shp"
gis:set-world-envelope (gis:envelope-of roads-dataset)
; draw data set
gis:set-drawing-color blue
gis:draw roads-dataset 1
make-road-network
end
to make-road-network
clear-links
let first-node nobody
let previous-node nobody
foreach gis:feature-list-of roads-dataset [ ; each polyline
foreach gis:vertex-lists-of ? [ ; each polyline segment / coordinate pair
foreach ? [ ; each coordinate
let location gis:location-of ?
if not empty? location [ ; some coordinates are empty []
create-nodes 1 [
set color green
set size 1
set xcor item 0 location
set ycor item 1 location
set hidden? true
if first-node = nobody [
set first-node self
]
if previous-node != nobody [
create-link-with previous-node
]
set previous-node self
]
]
]
set previous-node nobody
]
]
; connect adjacent polylines/roads
ask nodes [ create-links-with other nodes in-radius 0.001 ]
end
to add-agents
create-walkers 5 [
set color red
set wlocation one-of nodes
move-to wlocation
]
end
to add-scooters
foreach gis:feature-list-of scooter-dataset [
foreach gis:vertex-lists-of ? [
let location gis:location-of (first ?)
create-scooters 1 [
set color yellow
set size 1
set xcor item 0 location
set ycor item 1 location
let nearest-node min-one-of (nodes in-radius 10)[distance myself]
set slocation nearest-node
move-to slocation
]
]
]
end
to go
ask walkers [
let new-location one-of [link-neighbors] of wlocation
move-to new-location
set wlocation new-location
]
ask scooters [
let new-location one-of [link-neighbors] of slocation
move-to new-location
set slocation new-location
]
end
Some resources and example code I found particularly helpful:
NetLogo Programming Guide & example models about "walking" and "networks" that come with NetLogo
NetLogo Bag of Tricks - Venice Example Code
Duncan Golicher: Importing points into Netlogo and forming a network