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

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.

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

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

NetLogo - applying values to patches within polygons

I have animals walk around and a line then connects all the locations that they walked to. The line forms a closed polygon. I also used the graphics extension to fill the polygon for visual purposes. But I don't know how to have all of the patches that fall within the polygon become the territory of the owner (i.e., the animal that formed the polygon). It is possible for patches to be owned by multiple animals. The code below illustrates overlapping polygons. I'd really appreciate any help on this. Thanks!
extensions [graphics]
breed [animals animal]
breed [homeranges homerange]
animals-own
[
Name
X
Y
]
patches-own
[
owner
]
homeranges-own
[
Name
]
to setup
clear-all
random-seed 4
ask patches
[
set owner nobody
set pcolor grey
]
let $colors [brown orange violet sky lime]
let $Name ["t6" "t7" "t8" "t9" "t10"]
ask n-of 5 patches with [(pycor < 10 and pycor > -10) and (pxcor < 10 and pxcor > -10)]
[
sprout-animals 1
[
set shape "circle"
set color item who $colors
set pcolor color
set X (list xcor)
set Y (list ycor)
set Name item who $Name
set owner self
]
]
graphics:initialize min-pxcor max-pycor patch-size
reset-ticks
end
to go
repeat 5
[
ask animals
[
rt 45
fd 2
set X lput pxcor X
set Y lput pycor Y
set pcolor [color] of self
]
]
ask animals
[
pen-up
let tempXY (map [list ?1 ?2] X Y)
graphics:fill-polygon tempXY
; create a turtle, which draws the homerange boundary
hatch-homeranges 1
[
hide-turtle
set Name [Name] of myself
set color [color] of myself
]
; draw the homerange boundary
foreach tempXY
[
ask homeranges with [Name = [Name] of myself]
[
move-to patch (item 0 ?) (item 1 ?)
pen-down
]
]
; connect the last point of the homerange with the first one, to close the polygon
ask homeranges with [Name = [Name] of myself]
[
let lastpoint first tempXY
move-to patch (item 0 lastpoint) (item 1 lastpoint)
]
]
end
If you look at http://netlogo-users.18673.x6.nabble.com/Netlogo-Point-in-Polygon-td4980030.html you'll find a past (2012) discussion of solutions to this problem.
At the end of the thread, Jim Lyons posts a link to a model on the Modeling Commons, but the model doesn't seem to exist there anymore. He's here on Stack Overflow if you want to ask him about it.
An answer was provided in this post: NetLogo - misalignment with imported GIS shapefiles. The polygons are exported as a GIS shapefile and imported back in using the GIS extension. Then the gis:intersecting was used to give a variable to those patches that fall within the GIS-imported polygons.