Reputation: 147
This one is long so please bear with me. I have Two rasters in my world, one of a department and one of a very important lake (it was a shape file that I rasterized). I load both rasters and use them to set the variable lake (tota) and the elevation. Then Im trying to set the distance between non lake patches and lake patches but Im getting an error "DISTANCE expected input to be an agent but got NOBODY instead. error while patch 571 969 running DISTANCE"
This error doesn't make sense to my as the variable im checking is only for those who have tota (water) I know the code will be long and i tried my best to simplify but it is still a bit cluttered
extensions [ gis ]
globals [ world lake show-lake water]
patches-own[
distance-water
tota
]
to draw-tota
let min-elevation gis:minimum-of world
let max-elevation gis:maximum-of world
ask patches [
set elevation gis:raster-sample worldself
if (elevation <= 0) or (elevation >= 0) [
set pcolor scale-color green elevation 2900 max-elevation
]
]
end
to draw-lake
ask patches [
set water gis:raster-sample lake self
if (water >= 0) [
set pcolor blue
set tota 1
]
]
end
to setup-map
set world gis:load-dataset "D:/Geografico/DEM_Lago_Tota.asc"
gis:set-transformation [-72.994844704 -72.835891153 5.418413284 5.648012857666661] [0 1000 0 1000]
set lake gis:load-dataset "D:/Geografico/Lago_Tota_Raster.asc"
draw-tota
draw-lake
end
;;set up conditions
to set-houses
ask patches [
set dano_suelo (1 + random 5) ;;
set distance-lake distance min-one-of patches with [tota = 1] [distance myself]
]; This is the line that is giving me trouble!
set-default-shape turtles "person"
create-turtles 100
end
to setup
ca
resize-world 0 1000 0 1000
;set-lago
; set-predios
set-houses
reset-ticks
end
It is a lot, and unfortunately i dont know how to show you a picture. Any guidance will be appreciated as Im really lost. Thanks in advance.
Edit: Now the names are in English, Tota is the name of the lake in question. Thanks Matteo for the tip.
Upvotes: 0
Views: 44
Reputation: 2305
What I know about your problem indicates that there is not always a patch that fulfills the requirements of min-one-of patches with [tota = 1] [distance myself]
. You could try running the code with an added if
statement to check for that.
ifelse any? patches with [tota = 1] [
set distancia_agua distance min-one-of patches with [tota = 1] [distance myself]
] [
set distancia_agua "na"
]
As an edit based on your comment:
In order to reduce the number of operations I introduced let tota-edge <...>
. This means that you check only once which patches qualify as tota rather than doing it 1002001 times (since every single patch would do this same operation). So 1002001 times instead of 1.004006e+12.
I don't know how big tota itself is but if it is a sizable portion of the world, ask patches with [tota != 1]
will speed up your program some more. Finally, I only used the edges of tota since the middle of the lake is never the closest part of the lake to a non-lake patch.
ifelse any? patches with [tota = 1] [
let tota-edge patches with [tota = 1 and any? neighbors with [tota != 1]]
ask patches with [tota != 1] [ set distancia_agua distance min-one-of tota-edge [distance myself] ]
ask patches with [tota = 1] [ set distancia_agua 0 ]
] [
ask patches [ set distancia_agua "na" ]
]
Upvotes: 2