使用 apply-raster 将 ascii 应用于 netlogo 时出错

error in applying an ascii to netlogo with apply-raster

我正在尝试使用以下代码将 ascii(241 行,463 列)应用于 netlogo:

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

在 resize-world 命令中,我添加了 -1 因为 netlogo 从 0 开始,而 gis:width-of 从 1.The 开始结果是一个带有 [=59= 的 netlogo 世界] 0 max-pycor 240 和 min-pxcor 0 max-pxcor 462(一个 241x463 的世界),这与我的 ascii 的大小完全匹配。 gis-world envelop 命令确保 Netlogo 世界中 ascii 的范围相似。我检查了一下,再次完美匹配。

我面临的问题是,虽然netlogo 的行和列与ascii 的行和列相匹配,但应用的ascii 在y 方向上位移了1。 netlogo 世界的第一行填充了零,而我的 ascii 的第一行填充了高值。

图:顶行为红色,显示 0 个值,它们不应为 0。

感谢您的帮助

更多信息:

ascii header

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

netlogo 信封:

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

my-file信封:

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

请注意,存在细微的舍入差异,无论我如何编码 world-envelope,我都无法删除它。无论如何,考虑到这是如此微小的差异,我认为这不是问题所在。

我进一步调查了一下,我认为错误源于 apply-raster 背后的代码 similar to the problem here.

分析了apply raster的java代码on github,在gis extent上做点什么的时候好像引用了worlds min-pxcor和min-pycor。由于实际边缘坐标与补丁中心坐标不相似,这可能是导致问题的原因?不过,我不是 java 专家,这可能需要进一步调查(我可能错了..)。

无论如何,为了让我的 ascii 很好地应用于我的世界(设置为 ascii 的大小),我现在 运行 以下代码:

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 ] ] )