Land use change

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Land use change

roos_de_boer


 I'm using netlogo for a school project. This is the first time that I'm using netlogo and I'm running into some problems.
 For example I want to caculate a patch "willingness to change" based on is they are with enough fellow patches according to a senario. I now wrote this:
 Ask patches [ if count patches with [pcolor = 64] > Senario1 [ set willingtochangeN True ]
 if count patches with [pcolor = 14] > Senario2 [ set willingtochangeL True ]
 if count patches with [pcolor = 45] > Senario3 [ set willingtochangeA True ]
 if count patches with [pcolor = 35] > Senario4 [ set willingtochangeB True ]
 if count patches with [pcolor = 135] > Senario5 [ set willingtochangeI True ]
 But i would like to do it according to an iteration, So that I can put Willingness to change to [patches own] And than do something like:
 list [ (land-use 1) (land-use 2) (land-use 3)] foreach ask [ if count patches > senarioX set willingnesstochange true ] But then for senario it has to take senario1 for land-use 1 and senario2 for land-use 2 etc.
 Anyone that can help?
 This is my code untill now:
 extensions [ gis ] Patches-own [ Land-use ;; Wat kind og landusetype a patch has Willingstochange ;; If true a patch would like to change atractivenesstochangein ;; if a patch type is attractive to change in <1 = yess ] globals [ Senario1N ;; the count of patches senario 1 describes Senario1L Senario1A Senario1B Senario1I land-use-map ;; The land use map ] to setup ;; The setup is divided into four procedures clear-all setup-constants setup-patches update-display load-gis reset-ticks end to load-gis ;;load the maps clear-all set land-use-map gis:load-dataset "a_LANDUSE_cellsize5.asc" ;;loads the land use map gis:set-world-envelope-ds gis:envelope-of land-use-map ;;sets the envelope of the world to match that of the GIS dataset end to setup-constants set Senario1N 2350 ;; the count of patches senario 1 describes set Senario1L 847 set Senario1A 27330 set Senario1B 1625 set Senario1I 264 end to setup-patches gis:apply-raster land-use-map land-use ;;patches in the land-use-map have a specific land-use now list of patches [ (land-use 1) (land-use 2) (land-use 3) (land-use 4) (land-use 6) ] foreach [ count patches > senarioN set WillingtoChange True ] set atractivenesstochangein foreach [ count patches / senarioN ] end to update-display ask patches [ if land-use = 1 [ set pcolor Green ] ; Green = Nature ;; patches have a certain color now if land-use = 2 [ set pcolor red ] ; Dark red = Leisure if land-use = 3 [ set pcolor yellow ] ; Yellow = Agriculture if land-use = 4 [ set pcolor brown ] ; brouwn = Buildup if land-use = 5 [ set pcolor grey ] ; grey = roads if land-use = 6 [ set pcolor pink ] ; pink = industry if land-use = 7 [ set pcolor blue ] ; Blue = water ] end

Reply | Threaded
Open this post in threaded view
|

RE: [Non-DoD Source] [netlogo-users] Land use change

tswan73
When you say " do it according to an iteration" what do you mean? There's probably a simple solution for your problem, but it's kind of confusing as to what you're actually trying to do.

Best,
Todd

-----Original Message-----
From: [hidden email] [mailto:[hidden email]]
Sent: Friday, June 08, 2018 8:46 AM
To: [hidden email]
Subject: [Non-DoD Source] [netlogo-users] Land use change

 




I'm using netlogo for a school project. This is the first time that I'm using netlogo and I'm running into some problems.

For example I want to caculate a patch "willingness to change" based on is they are with enough fellow patches according to a senario. I now wrote this:

Ask  patches [

    if count patches with [pcolor = 64] > Senario1 [ set willingtochangeN True ]
    if count patches with [pcolor = 14] > Senario2 [ set willingtochangeL True ]
    if count patches with [pcolor = 45] > Senario3 [ set willingtochangeA True ]
    if count patches with [pcolor = 35] > Senario4 [ set willingtochangeB True ]
    if count patches with [pcolor = 135] > Senario5 [ set willingtochangeI True ]


But i would like to do it according to an iteration, So that I can put Willingness to change to [patches own] And than do something like:

list [
(land-use 1) (land-use 2) (land-use 3)]
foreach
ask [
if count patches > senarioX set willingnesstochange true ]


But then for senario it has to take senario1 for land-use 1 and senario2 for land-use 2 etc.

Anyone that can help?

This is my code untill now:

extensions [ gis ]


Patches-own
  [ Land-use                ;; Wat kind og landusetype a patch has
    Willingstochange        ;; If true a patch would like to change
    atractivenesstochangein ;; if a patch type is attractive to change in <1 = yess
    ]


globals
  [
      Senario1N             ;; the count of patches senario 1 describes
      Senario1L
      Senario1A
      Senario1B
      Senario1I
      land-use-map          ;; The land use map
      ]


to setup                    ;; The setup is divided into four procedures
  clear-all
  setup-constants
  setup-patches
  update-display
  load-gis
  reset-ticks
end

 to load-gis               ;;load the maps
  clear-all
  set land-use-map gis:load-dataset "a_LANDUSE_cellsize5.asc"     ;;loads the land use map
  gis:set-world-envelope-ds gis:envelope-of land-use-map          ;;sets the envelope of the world to match that of the GIS dataset
end


to setup-constants
  set Senario1N 2350 ;; the count of patches senario 1 describes
  set Senario1L 847
  set Senario1A 27330
  set Senario1B 1625
  set Senario1I 264
end


to setup-patches
  gis:apply-raster land-use-map land-use                         ;;patches in the land-use-map have a specific land-use now

  list of patches [ (land-use 1) (land-use 2) (land-use 3) (land-use 4) (land-use 6)  ]
    foreach
    [ count patches > senarioN set WillingtoChange True
    ]                                    
    set atractivenesstochangein foreach
    [ count patches / senarioN  
    ]
end



to update-display
  ask patches
  [
    if land-use = 1 [ set pcolor Green ]   ; Green = Nature           ;; patches have a certain color now
    if land-use = 2 [ set pcolor red ]     ; Dark red = Leisure
    if land-use = 3 [ set pcolor yellow ]  ; Yellow = Agriculture
    if land-use = 4 [ set pcolor brown ]   ; brouwn = Buildup
    if land-use = 5 [ set pcolor grey ]    ; grey = roads
    if land-use = 6 [ set pcolor pink ]    ; pink = industry
    if land-use = 7 [ set pcolor blue ]    ; Blue = water
    ]
end






Reply | Threaded
Open this post in threaded view
|

Re: Land use change [1 Attachment]

guerrin
In reply to this post by roos_de_boer
Hi Roos,

you should read and train yourself with the NetLogo documentation to
improve your knowldege of the NetLogo syntax and primitives.

Every time you want to use a command or reporter, lookup in the
dictionnary, check the syntax (using the check button) and test it
beforehand to make sure it works the way you want.

Namely, review carefully the features about lists and how to write
"anonymous procedures" (foreach etc.).

This being said, here below is how you could write your program:

;;;; LAND USE CHANGE
; I want to caculate a patch "willingness to change" based on is they
are with enough fellow patches according to a senario.

patches-own
[Land-use
   Willingstochange
]

to setup
   clear-all
   assign-land-uses
   set-colors
   set-willingness
end

to assign-land-uses
   let land-use-list (range 1 8)
   foreach land-use-list
   [x -> ask patches [set land-use one-of land-use-list]]
end

to set-colors
   let land-use-list (range 1 8)
   let color-to-display [green red yellow brown grey pink blue]
   foreach land-use-list
  [x -> ask patches with [land-use = x] [set pcolor item (x - 1)
color-to-display]] ; the rank of a first item of a list is 0, hence use
x - 1
end

to set-willingness
   let land-use-list (range 1 8) ; both lists should be the same length
to match
   let scenario-count-list [2350 847 27330 1625 264 1 1] ; therefore I
added two fake values at the end of this one
   (foreach  land-use-list scenario-count-list
     [[x y] ->
       let patches-to-set patches with [land-use = x]
       ask patches-to-set
       [ifelse count patches-to-set > y
         [set Willingstochange true]
         [set Willingstochange false]
       ]
     ]
   )
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



Le 08/06/2018 à 15:45, roos_de_boer@hotmail...com [netlogo-users] a écrit :

>
>
> I'm using netlogo for a school project. This is the first time that
> I'm using netlogo and I'm running into some problems.
>
> For example I want to caculate a patch "willingness to change" based
> on is they are with enough fellow patches according to a senario. I
> now wrote this:
>
> |Ask patches [ if count patches with [pcolor = 64] > Senario1 [ set
> willingtochangeN True ] if count patches with [pcolor = 14] > Senario2
> [ set willingtochangeL True ] if count patches with [pcolor = 45] >
> Senario3 [ set willingtochangeA True ] if count patches with [pcolor =
> 35] > Senario4 [ set willingtochangeB True ] if count patches with
> [pcolor = 135] > Senario5 [ set willingtochangeI True ] |
>
> But i would like to do it according to an iteration, So that I can put
> Willingness to change to [patches own] And than do something like:
>
> |list [ (land-use 1) (land-use 2) (land-use 3)] foreach ask [ if count
> patches > senarioX set willingnesstochange true ] |
>
> But then for senario it has to take senario1 for land-use 1 and
> senario2 for land-use 2 etc.
>
> Anyone that can help?
>
> This is my code untill now:
>
> |extensions [ gis ] Patches-own [ Land-use ;; Wat kind og landusetype a
> patch has Willingstochange ;; If true a patch would like to change
> atractivenesstochangein ;; if a patch type is attractive to change in
> <1 = yess ] globals [ Senario1N ;; the count of patches senario 1
> describes Senario1L Senario1A Senario1B Senario1I land-use-map ;; The
> land use map ] to setup ;; The setup is divided into four procedures
> clear-all setup-constants setup-patches update-display load-gis
> reset-ticks end to load-gis ;;load the maps clear-all set land-use-map
> gis:load-dataset "a_LANDUSE_cellsize5.asc" ;;loads the land use map
> gis:set-world-envelope-ds gis:envelope-of land-use-map ;;sets the
> envelope of the world to match that of the GIS dataset end to
> setup-constants set Senario1N 2350 ;; the count of patches senario 1
> describes set Senario1L 847 set Senario1A 27330 set Senario1B 1625 set
> Senario1I 264 end to setup-patches gis:apply-raster land-use-map
> land-use ;;patches in the land-use-map have a specific land-use now
> list of patches [ (land-use 1) (land-use 2) (land-use 3) (land-use 4)
> (land-use 6) ] foreach [ count patches > senarioN set WillingtoChange
> True ] set atractivenesstochangein foreach [ count patches / senarioN
> ] end to update-display ask patches [ if land-use = 1 [ set pcolor
> Green ] ; Green = Nature ;; patches have a certain color now if
> land-use = 2 [ set pcolor red ] ; Dark red = Leisure if land-use = 3 [
> set pcolor yellow ] ; Yellow = Agriculture if land-use = 4 [ set
> pcolor brown ] ; brouwn = Buildup if land-use = 5 [ set pcolor grey ]
> ; grey = roads if land-use = 6 [ set pcolor pink ] ; pink = industry
> if land-use = 7 [ set pcolor blue ] ; Blue = water ] end |
>
>
>

--

SignatureMail-FG.png (33K) Download Attachment