I can't moving the turtle - gis

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

Related

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

How do you make patches in netlogo take on the colors of an imported shapefile?

'
fúè G¾‹ðÑRÀ#ÑOïC#-ºü*½RÀÆOÙ§D# H 1!Š´âÉRÀwš(yD#”Š¾6ìÈRÀIÊ;ŠãD# F 2©Ì®~ÉRÀ6ÓœÄD#›rǘsÉRÀ;=ºx·D#´µÉFbÉRÀü(I¿£D#}!YLKÉRÀ¬%”‰D#T-Bi#ÉRÀIë-}D#6j6ÉRÀ HQËqD#+f°’ÉRÀ²®‚9D#”Š¾6ìÈRÀí–[PD#ÁÀ–tîÈRÀ·cùB
D#X­#3ñÈRÀPYÈóíD#©³Î¶óÈRÀ| ¡_×D#}"ùÈRÀ¾…¥D#ܤG´þÈRÀ5µsD#oAÔÉRÀ ‚ŠWD#f¥Œ
ÉRÀaí&BD#®\¨ ÉRÀZ5šD#&Ùwo
ÉRÀMdÓ—ðD#à$_ÉRÀ:Ši©ÜD#ûÑPeÉRÀ9oæWÐD#ˆV2yÉRÀ€—ªÄªD##‚üÉRÀwš(yD#Ñ‹;°0ÉRÀÛ`õê~D#!°¾4ÉRÀab÷D#¦dµÒAÉRÀWÃ>ƒD#扺¾NÉRÀg+Ñš†D#ùl¼VÉRÀù½ˆD#á€%¸[ÉRÀøÁñ‰D#ù+‘hÉRÀl&7D#«x’U‚ÉRÀ꺔D#·÷›ÉRÀ$i„hšD#¸»ùp¬ÉRÀz8—KœD#^鮶ÉRÀê<`‡D#ùŸ/¸ÉRÀ›°D#ךÊÉRÀk–iËŸD#¨’ÒÖÈÉRÀ0¡8æÃD#·zÈÈÉRÀŒ2ÎÉD#&°Á(ÇÉRÀW4O9îD#Ë ‡EÆÉRÀî*æÑD#–"&ÄÉRÀÉÉŸ\7D#ÜæÏÔÂÉRÀ&1Ó•]D#€eX!ÃÉRÀÔ¨ÈíaD#¢â¤ÙÃÉRÀ»tøÀoD#ê)L±ÄÉRÀÑáü+zD#ÄÅÀÅÉRÀQB~D#¦½ÆÉRÀEöl.€D#ñ?J×ÉRÀÀÜ™±D#1!Š´âÉRÀá#h/ÔD#Þ$EÜÉRÀVŸSÙD#áÉ2ÕÉRÀ”ŸÀÛÞD#|98ÏÉRÀ$+Æ{ãD#´J¨ÇÉRÀX7zéD#ð˜¨ÖÀÉRÀ¼1šÎîD#£®ÃN¶ÉRÀ'á!÷D#Hnªk¸ÉRÀXð;ýD#¿RÏþ¶ÉRÀõLjíýD#µçдÉRÀ2eMÔýD#)€G¶³ÉRÀeÒãüD#p>Í°ÉRÀHúsD#…ÔÁ׬ÉRÀøÁÅ;D#/ 0éªÉRÀͶ`MD#½"U©ÉRÀ/Ïá^]D#Ê0W§ÉRÀñNnD#=Ö=o¥ÉRÀFÆp D#Á¬£ÉRÀAÿ!D#Ìñ6ç¡ÉRÀ§Þ D#WùŸÉRÀ–Fuì°D#¦çá?žÉRÀÊ\"ìÀD#x2ÐbÉRÀP·NQÉD#{ÈKšÉRÀIÊ;ŠãD#2©Ì®~ÉRÀ6ÓœÄD# È ï Ÿ±ìÀRÀ¢ö«D#CU‚Fc¿RÀb|ßlD# V Gp‰[ÀRÀü¬C*WD#1êwð¿RÀ’¬ô.AD#Æ$¼ë¿RÀ…¡³J<D#I]"(¦¿RÀLÈ!íD#T)C¢¿RÀ)XAÄèD#q¼ñœ¿RÀï̹ãD#ˆ´m¤–¿RÀôM#LßD#<¬dè¿RÀnÞ}"ÜD#Ã
KŠ¿RÀþÛ„ ÚD#š~lvƒ¿RÀƒ
ñ×D#î¬%|¿RÀxÓ«ÔD#¼pâ1x¿RÀØRðHÒD#„v¨t¿RÀbc<OÏD#U&‹q¿RÀ‹ŠM¯ÌD#›ÝU:n¿RÀ‘BÎcÉD#!õ4j¿RÀµsÿÃD#‹­3¶f¿RÀÅ&̾D#}Ȉd¿RÀr™£¶¼D#CU‚Fc¿RÀÎBc\»D#¬èȤg¿RÀÖàðµD#¿š+k¿RÀÃ2TÓ±D#÷2D½p¿RÀI™Ï·¬D#OÁØv¿RÀÀYãƨD#M2ñ…}¿RÀ†š¸ò£D#ÎxýE¿RÀówœD#û»£ãž¿RÀïêwÛ’D#«1Ö¼¸¿RÀI+¯˜…D#UZ}οRÀXþê€zD#­1iƒã¿RÀ Ê·yoD#›Â¿ö¿RÀ1ÿ]îdD#"
°;þ¿RÀë0È`D#KÀÞÀRÀ%é UD#NÍpcÀRÀÁŒ°SD#¢EØù0ÀRÀM¾´6+D#æÉЙNÀRÀŽY7ED#álÖñdÀRÀ?èO_àD#‚­ˆ#ÀRÀ~õ¹´D#ƒLL‰‚ÀRÀ)ö“²D#'}ÒƆÀRÀ¢ö«D#bä¤"‰ÀRÀ˜q^¹D#ʸ)§ˆÀRÀbmž¼D#RGa·ÀRÀ–®¿D#ÇYœ_‹ÀRÀ[þ]ÖD#(’À‹ÀRÀÛ^£ÚD#úSáÀRÀIÁäMÞD#K#¥ú–ÀRÀÆŠJ¾éD#ŒC¾6¦ÀRÀþµ{­ýD#BÉÔªÐÀRÀX’ý4D#út÷6ÒÀRÀFÆþ’8D#¬O×ÀRÀ×…‡æ?D#
QÛÀRÀ"¸4ÐBD#o$z+èÀRÀ·iÒÖSD#ï Ÿ±ìÀRÀH·:ÿYD##ÌJ#èÀRÀÆ°9BbD#KŒâÀRÀ ‚hælD#÷‡ÙwßÀRÀ`WviD#ßËîÚÀRÀ×Ƭ¯dD#* ÜñÖÀRÀñQåjaD#×ÎJÒÀRÀ=ñŽ{_D#&‘IÍÀRÀ;2‹^D#Sƃ—ÈÀRÀ?|C‚^D#T:ÑÄÀRÀeõ}_D#C,ÁÀRÀëú/Ü`D# ’Tn¾ÀRÀ­ùybD#ŠD~”¼ÀRÀ]yê0dD#dn¨³ÀRÀi¢PblD#—Ru§ÀRÀ•Ò»
xD#'I £ÀRÀû­-ÚzD#È—ÐÞÀRÀ½ôþ]}D#àÒä™ÀRÀ·ÅokD#‘Wn‘ÀRÀšLn‚D#
ö•ÀRÀ-Ly¨D#öŽ“æÀRÀ®Ñ,‹ªD#Ÿ‰ü¬ÀRÀ‰Âå|¬D#NBÒŠÀRÀ|ê®D#Õý,ˆÀRÀÂd+²D#¿ñ¶Ö„ÀRÀ¯>!®·D#ŽÙ ŸiÀRÀ>Ô" âD#zFÜ—\ÀRÀX/˜öD#dBÖÀOÀRÀ
0‹
Boundary of Philadlephia shp file I am successfully able to import a shapefile into Netlogo. Someone told me that my foreach loop that applies my shp GIS layer is only creating lines in the drawing layer of NetLogo, not actually changing the patches themselves. How do I assign some component of the shapefile to the patches themselves for turtles to be able to assess them?
My code is
to setup
clear-all
create-turtles 10
set-default-shape turtles "butterfly"
ask turtles [set size 25]
;if pxcor = min-pxcor [die]]
reset-ticks
let view gis:load-dataset "City_Plan_Boundary.shp"
gis:set-world-envelope gis:envelope-of view
foreach gis:feature-list-of view
[
gis:set-drawing-color green
gis:draw ? 1.0
]
end
thank you, ny help is appreciated. I am very new to netlogo.

How to Make a turtle Move within Polygons?

I am creating model in netlogo using GIS extension to read shapefiles. I have polygons representing a National Park and points representing lions. The points and park's polygon display without any problem. However, I want to create turtles from the points, that is where I get a problem. When I do that turtles change position. They are arranged in the same pattern but they spread and occupy the whole netlogo's world, as opposed to being a small cluster within the park.
extensions [gis]
globals [lion-dataset park-dataset]
to setup
ca
reset-ticks
;; import national park shapefile
set park-dataset gis:load-dataset "H:/college/reserve_lion.shp
gis:set-drawing-color green gis:fill park-dataset 2.0
;; read in turtle dataset and draw
set lion-dataset gis:load-dataset "H:/college/lion.shp
gis:set-drawing-color red gis:fill park-dataset 2.0
breed [lions lion]
;; creating the turtle from lion-dataset
foreach gis:feature-list-of lion-dataset
[ let location gis:location-of gis:centroid-of ?
if not empty? location
[ create-lions 1
[ set shape "person"
set size 1
set color red
set xcor gis:property-value ? " x_park"
set xcor gis:property-value ? " y_park"
show "world loaded"
end
to go
ask lions
[move]
tick
end
to move
fd 3
rt 3
end

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

NetLogo, how to hatch a turtle at a certain distance on Gis layers

My patches contain attributes such as elevation :
set mnt gis:load-dataset "F:/StageM2/Modelisation/Modele/mnt.asc"
gis:apply-raster mnt alt
gis:set-transformation (list 567887.504252 573503.504252 6183200.86463 6187628.86463) (list min-pxcor max-pxcor min-pycor max-pycor)
gis:set-world-envelope gis:envelope-of mnt
and turtles are created from raster of forest :
to import-foret93
set foret-93 gis:load-dataset "F:/StageM2/Modelisation/Modele/foret76_93.asc"
gis:apply-raster foret-93 f93
ask patches with [f93 = 1]
[
set pcolor black
set foret93? true
;ask n-of 2813 patches with [foret93? = true] [ hatch 2813 ]
sprout-arbres 1 [set color pink
set size 4]
]
end
The layers have the same spatial reference : RGF1993, so it is in meters.
Now, I want to create new turtles from existing turtles and randomly in a radius of 150m from the turtle (the new turtle can be hatch at 1m or at 130m). For instance, I ask just one turtle to hatch a turtle at a distance giving by an input box in the interface named dispersal-dist.
to disp-graines
ask turtle 2918
[
hatch-arbres 1
[
let seedX xcor
let seedY ycor
let ran-bear random 360
lt ran-bear
move-to one-of patches in-radius dispersal-dist
set color magenta
set size 15
]
]
end
But the created turtle go further then the dispersal distance giving in meters.
Did I forget something to transforme the netlogo scale in meters ? Or it is another problem?
Thank you in advance for your help !
While your raster dataset is expressed in meters in your case, your patches don't have a real world scale. Assuming your raster has square pixels, you can calculate a patch scale with something like:
let patch-scale (item 1 gis:world-envelope - item 0 gis:world-envelope ) / world-width
You could then use it in your existing code:
move-to one-of patches in-radius dispersal-dist / patch-scale
If your pixels in your raster have different real world height and width, you will have to do the patch-scale for the horizontal and vertical dimension separately.