10

When I use this code to import a raster layer into NetLogo and resize the world, all patch variables of the last column is zero when it should contain data. This happens only for a few rasters from the same landscape.

set rasterLayer gis:load-dataset "x.asc"
resize-world 0 (gis:width-of rasterLayer) -1 0 (gis:height-of rasterLayer) -1
gis:set-world-envelope gis:envelope-of rasterLayer
gis: apply-raster rasterLayer 

Without the '-1' when resizing the world, I get a column of NaN values (Importing raster data into NetLogo results in a row/column of NaN values).

The dimensions of this raster are correct; the column of 0 values is not an extra one, meaning that some data is lost.

  • A few more notes to follow up on this question: the dimensions of the NetLogo world (166 rows, 202 columns) after I resize it, match those of the raster. Does this not mean that no resampling should take place and that all the patches in the NetLogo world after the `gis: apply-raster` command should fully mirror the raster? How do I find out if the boundaries of the NetLogo world and the raster do not align? – Anisha Jayadevan Jul 23 '18 at 06:40
  • 1
    Did you already check this answer and solution? https://stackoverflow.com/questions/37703137/error-in-applying-an-ascii-to-netlogo-with-apply-raster?rq=1 But keep in mind, that the proposed solution code example uses NetLogo 5 syntax. For NetLogo 6 you have to adjust the foreach part (see multiple lists example on https://ccl.northwestern.edu/netlogo/docs/dictionary.html#foreach) – nldoc Jul 24 '18 at 07:42
  • @Tyr thank you so much! Despite repeated searches, I had not come across that question and answer before. The answer posted in the link you shared does solve the problem. The only thing is that it takes a little longer to apply the ascii file to the NetLogo world this way, especially since I have ~15 rasters that are applied and ~500 such tiles (I had split a large landscape into more manageable 'tiles' which will be merged later to form the landscape) for which I have to repeat the operation. – Anisha Jayadevan Jul 25 '18 at 08:47

1 Answers1

1

Thanks to @Tyr : a workaround to this possible bug was posted here. This is the code I used, for NetLogo 6, to make sure that the raster was applied properly to the NetLogo world :

 file-open "data/my-folder/my-file.asc"
 let temp []
 repeat 6 [let header file-read-line] ; skip first 6 lines of header
 while [file-not-at-end?][
       set temp lput file-read temp 
]
 file-close
(foreach sort patches temp [
       [a b] -> ask a [ set my-variable b] 
 ] )