1

I, once again have a question. My previous solution to my problem didn't work as I expected. To remind you, I imported some polygons and had a problem setting some turtles (cities) in the NetLogo world appropriately (to read GIS coordinates from non-gis file and set their position in the world, more on Netlogo doesen't recognize the GIS coordinates in the defined envelope of the world, it treats them as netologo world coordinates). So, in the end, I came up with a solution to transform the GIS coordinates in NetLogo coordinates (nl-x and nl-y procedures). The cities are actually in graphml format with x and y attributes. So, my code is this:

extensions [nw gis]
directed-link-breed [highways highway]
breed [cities city]
highways-own [ name ]
cities-own [ x y ]
globals [ paldrino ]

to setup
  ca
  ;; set the world envelope
  gis:load-coordinate-system "wgs84.prj"
  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 ->
   let temp-color one-of base-colors
      ask patches gis:intersecting polygon [
      set pcolor  temp-color
   ]]

  ;; load network
  nw:set-context cities highways
  nw:load-graphml "highway-network.graphml"
  ask cities[
    set xcor nl-x(read-from-string x)  ;; if I put set xcor read-from-string  x, then it will put all the nodes in one point in Netlogo world, same for setxy fix-x(read-from-string x) fix-y (read-from-string y)
    set ycor nl-y (read-from-string y)
  ]

end

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  

In the end, the problem is that NetLogo doesn't perfectly align those two files: polygons (paldrino) and network (cities). Approximately it put them ok, but I need them to be perfectly set in the world. For example, some cities should have been in one polygon, but they are in the adjacent polygon. So, for example, this is how NetLogo puts them:

enter image description here

And this is how they should be (read in QGIS):

enter image description here

If anyone please can help me or point me in another direction. I start losing my mind.

Thank you!

Naturaleza
  • 99
  • 8
  • I assume your shp file is real GIS coordinates, but you state that your cities file is graphml with x and y coordinates. I don't understand this at all - x and y coordinates with respect to what origin and scale? Also a city is a point, but graphml is lines. From your code I think you mean that the graphml is for roads that join cities, so there are four coordinates - x and y for each of two cities. Roads presumably don't change over time in your model, and you have qGIS working with the data. Why don't you use qGIS to convert your graphml into shp format? – JenB Aug 21 '20 at 07:49
  • Thank you for replay! Yes, the actually its roads network between the cities (I wrote cities in the previous question, to simplified and focus more on the exact problem). Cities are nodes which have x and y coordinates (real one - when I load them in qgis, or with the python - their position is perfect). I need a network in NetLogo - this graph is directed and have some properties that I need for my model, such time travel and so on). And because my network is really large (the whole country) I think its too computational demand to load them as shp and them to convert them into network. – Naturaleza Aug 21 '20 at 13:00

0 Answers0