1

I am trying to apply an ascii (241 rows, 463 columns) to netlogo using the following code:

set my-dataset "data/my-folder/my-file.asc"
resize-world 0 gis:width-of (gis:load-dataset my-dataset) - 1 0 gis:height-of (gis:load-dataset my-dataset) - 1
gis:set-world-envelope-ds (gis:envelope-of (gis:load-dataset my-dataset))
gis:apply-raster (gis:load-dataset my-dataset) my-variable

In the resize-world command, I added the -1 since netlogo starts at 0, while gis:width-of starts at 1.The result is a netlogo world with min-pycor 0 max-pycor 240 and min-pxcor 0 max-pxcor 462 (a 241x463 world), which matches the size of my ascii perfectly. The gis-world envelop command makes sure that the extent is similar for the ascii en the Netlogo world. I checked this, and again it matches perfectly.

The problem I am facing is that although the netlogo rows and columns match the ascii rows and columns, the applied ascii is displaced by 1 in the y direction. The top row of the netlogo world is filled with zero's, while the top row of my ascii is filled with high values.

FIGURE: top row is red, showing 0 values, where they should not be 0.

  • Does anybody know what the problem is? Or how to correctly apply the ascii to the netlogo world so that one ascii value fills the corresponding netlogo patch?

  • Maybe additional to this: can I stop netlogo from automatically resampling, so that I know for sure that the values in netlogo are the same as those in my ascii.

Thank you for your help

More info:

ascii header

NCOLS 463
NROWS 241
XLLCORNER 2.54710299910375
YLLCORNER 49.4941766658013
CELLSIZE 0.00833333333339921
NODATA_value -9999

netlogo envelope:

 show gis:world-envelope
 observer: [2.5471029991037497 6.405436332467584 49.49417666580129 51.502509999150504]

my-file envelope:

 show gis:envelope-of gis:load-dataset my-dataset
 observer: [2.54710299910375 6.405436332467584 49.4941766658013 51.502509999150504]

Note that there is a slight rounding difference, which I just cannot erase no matter how I code the world-envelope. In any case, considering that it is such a tiny difference I don't think this is the problem.

  • edit: I checked what actually happened by exporting the netlogo values to a raster, and comparing them in ArcGIS. It is not a simple problem of resampling. Actually, the top row just has missing values, without shifting values. Furthermore, the middle column and row duplicate, causing everything to shift outwards from the middle towards the bottom and right. I added a simple illustration, hoping that this would clarify the problem.

enter image description here

Toon
  • 75
  • 5

1 Answers1

2

I investigated it further, and I think the error originates in the code behind apply-raster similar to the problem here.

I analyzed the java code of the apply raster on github, and it seems to refer to the worlds min-pxcor and min-pycor while doing something with the gis extent. As the real edge coordinates are not similar to the patch center coordinates, this might be causing the problem? I am not a java expert though, it might be something to investigate further (and I might be wrong..).

Anyway, to get my ascii to apply nicely to my world (which was set to the size of the ascii), I now run the following code:

file-open "data/my-folder/my-file.asc"
let temp []
while [file-at-end? = false][repeat 6 [let header file-read-line] ; skip header
                             set temp lput file-read temp 
                              ]
file-close
(foreach sort patches temp
     [ ask ?1 [ set my-variable ?2 ] ] )
Community
  • 1
  • 1
Toon
  • 75
  • 5