2

I want to import some polygons from shapefile and create turtles with specific coordinates (a set of points that will be put in specific polygons). I successfully imported the polygons, set the envelope of the world... However, when I tried to add turtles and put them on a specific place (setxy), it added them at the same point (like those two points have the same coordinates, and they have not). And I chose coordinates of the points for which I know they belong spatially to the different imported polygons. I changed the pixel size (though that may be the problem), but nothing. I realized that NetLogo interpreters those coordinates as its' local coordinates, instead of GIS. But shouldn't Netlogo recognize the GIS coordinates in the defined envelope of the world?
Can someone help me with this and tell me what I am doing wrong.

My setup procedure:

to setup
  set paldrino gis:load-dataset "paldrino.shp"                
  let world ( gis:envelope-of paldrino )
  gis:set-world-envelope (world)

  ;; Make them visible
  foreach gis:feature-list-of paldrino  [ ;for each polygon
  polygon ->
   ask patches gis:intersecting polygon [
   set pcolor pink 
   ]]

  create-turtles 1[
  set color blue
  set size 15
  setxy 34.6255826 48.2408635  ;; here's the problem, netlogo treats this as the network coordinates of the world, not as GIS coordinates
  ]

 create-turtles 1[
 set color green
 set size 15
 setxy 34.8056851 48.1885275  ;; here's the problem, netlogo treats this as the network coordinates of the world, not as GIS coordinates

end
Naturaleza
  • 99
  • 8

1 Answers1

1

I have found the alternative solution. Certainly is not the best one, but for now is the only I have. I created an additional procedure that rescale GIS coordinates to the NetLogo coordinates.

to-report nl-x [#x]
    let world gis:envelope-of paldrino  
    let minx item 0 world  
    let maxx item 1 world
  report ((#x - minx) / (maxx - minx)) * (max-pxcor - min-pxcor) + min-pxcor
end

to-report nl-y [#y]
   let world gis:envelope-of paldrino  
   let miny item 2 world  
   let maxy item 3 world
report ((#y - miny) / (maxy - miny)) * (max-pycor - min-pycor) + min-pycor
end

And when I want to set a turtle's coordinates I call the procedure in the following way:

 setxy nl-x(34.6255826) nl-y(48.2408635)

If someone has the better computational solution and can me explain why my code in the question is no working, please do. I will accept that answer instead of this.

Naturaleza
  • 99
  • 8
  • This looks like a good solution to me. `setxy` is a NetLogo command, it refers to NetLogo coordinates. The GIS information is not active within NetLogo, think of it as a drawing layer only. That's why there's a bunch of commands to transfer the information held in the GIS file into patches or turtles - because patches and turtles are the entities of the NetLogo model. The envelope command is about telling NetLogo how big to make the drawing layer, but doesn't make it active within the NetLogo model. – JenB Aug 03 '20 at 07:51
  • But it's not good in my case. The thing is that when I added and visualized paldrino polygons, points/cities were not perfectly aligned with polygons. They were slightly misaligned. I don't know how to fix this. I tried with this solution, but didn't help: https://stackoverflow.com/questions/22485341/netlogo-misalignment-with-imported-gis-shapefiles – Naturaleza Aug 11 '20 at 14:06
  • If you want NetLogo to work with GIS coordinates, you have to stay with the gis extension. Does `gis:location-of` do what you are trying to do? – JenB Aug 11 '20 at 20:41
  • No. The things is that my cities are in graphml format,which has x and y attribute. The principle is still the same. I have breed cities which have attributes x and y inherited from the file. The line of the code that is referring to their position is this: `ask cities [setxy nl-x(read-from-string x) nl-y(read-from-string y)]` So if I understood well from the doc, you use `gis:location-of` primitive when you want to extract x and y from the shapefile. And this is the opposite and I am stuck. Thank you very much for responding me and the others (I bumped into your answers which helped me). – Naturaleza Aug 12 '20 at 13:19
  • And if try with `set xcor read-from-string x set ycor read-from-string y` then every city is located in one point. – Naturaleza Aug 12 '20 at 13:37