NetLogo / GIS-Extension

the GIS (Geographic Information Systems) extension bundled with NetLogo
Other
27 stars 20 forks source link

Add create-turtles-from-points primitive #31

Closed JamesHovet closed 3 years ago

JamesHovet commented 3 years ago

Add a primitive that automatically creates a set of turtles for each point in a points GIS points dataset. Each turtle created takes on variable values from their respective origin points automatically.

In addition to the above create-turtles-from-points primitive, there is a create-turtles-from-points-manual primitive that allows the user to manually specify how GIS property/field names are mapped to NetLogo variables.

An example: say you wanted to create a turtle of breed "cities/city" for each city in a dataset of cities like the one included in the "GIS General Examples" model from the models library. The cities dataset has four properties, "NAME", "COUNTRY", "POPULATION", and "CAPITAL". To map them all to NetLogo turtle variables and set their shapes to circles, you could do this:

JamesHovet commented 3 years ago

Thank you for all your work on this! It looks like you got all the features we talked about implemented, which is great. This mostly looks good. I left some small style comments in the code.

One issue I found in testing, I loaded the GIS General Examples code example model from the library. I added this code above the existing setup procedure:


breed [ ciudades ciudad ]
;ciudades-own [ name ]

to setup-ciudades 
  clear-all
  gis:load-coordinate-system (word "data/" projection ".prj")
  set cities-dataset gis:load-dataset "data/cities.shp"
  gis:set-world-envelope gis:envelope-of cities-dataset
  gis:create-turtles-from-points cities-dataset "ciudades" [
    set size 1.5
    set shape "circle" 
  ]
end

What I noticed is that when I did not define any breeds-own variables (commented out the ciudades-own [ name ]), the turtles were loaded but they didn't get the position set, they were all at (0, 0). When I uncommented the ciudades-own [ name ] they got the position set by the dataset and also the name values were populated. That looks like a bug to me, I'd expect all the built-in variables to be loaded and set (including position) even if the breed doesn't define any variables.

Good catch. I had the change-the-turtle-position code inside of the for-each-matching-variable-pair for loop for some reason. Fixed and added this situation as a test case.

cdwren commented 3 years ago

Hey there, this looks super useful and covers a very needed addition. Any chance you know which future release this will be brought into?

LaCuneta commented 3 years ago

@cdwren I think there is a little more work left to do on improvements, but you can expect a release of the GIS Extension through the extensions manager sometime in the next month. The updates will also be included in the next release of NetLogo desktop, but there is no timeline for that.