coordinatesnetlogopatchgridworld

Netlogo - make patches smaller to display clearly all agents ' locations clustered in a small area


I am modelling delivery system of a city. the delivery branch agent's location is based on the real world coordinates. How can I make a smaller netlogo world that can clearly display all the agents in a defined area (min-x: 113.783131, max-x: 114.42618; min-y: 22.476584, max-y: 22.809712)? The current netlogo world is simply too big to make each agents visible (they all clustered in a small point)


Solution

  • All you need to do is write a function that rescales your x and y coordinates into the NetLogo range. Then simply call that function whenever you refer to real world coordinates. See below for functions that are independent of the number of patches in your world. You may want to fiddle with the maximums and minimums in the functions if you want to get closer to or further away from the edge. Also, I would add an error check (so the function prints a meaningful message if you accidentally try to ask for coordinates outside your predefined max and min).

    Run the testme to see what it does.

    to testme
      clear-all
      create-turtles 1
      [ setxy fix-x 113.8 fix-y 22.6 ]
      create-turtles 1
      [ setxy fix-x 114.49 fix-y 22.8 ]
    end
    
    to-report fix-x [#x]
      let minx 113.5
      let maxx 114.5
      report ((#x - minx) / (maxx - minx)) * (max-pxcor - min-pxcor) + min-pxcor
    end
    
    to-report fix-y [#y]
      let miny 22.45
      let maxy 22.82
      report ((#y - miny) / (maxy - miny)) * (max-pycor - min-pycor) + min-pycor
    end
    

    UPDATE from comments: If you actually have a GIS dataset, simply load that into NetLogo using the GIS extension and set the envelope. The world will adjust.