使用apply-raster将ascii应用于netlogo时出错 [英] error in applying an ascii to netlogo with apply-raster

查看:84
本文介绍了使用apply-raster将ascii应用于netlogo时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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.

我面临的问题是,尽管netlogo行和列与ascii行和列匹配,但所应用的ascii在y方向上却偏移了1. netlogo世界的第一行充满零,而我的ascii的第一行充满高值.

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.

图:第一行为红色,显示0个值,其中不应为0.

  • 有人知道问题出在哪里吗?或者如何正确地将ascii应用于netlogo世界,以便一个ascii值填充相应的netlogo补丁?

  • 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?

也许对此有所补充:我可以阻止netlogo自动重新采样,以确保我确定netlogo中的值与我的ascii中的值相同.

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.

谢谢您的帮助

更多信息:

ascii标头

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

netlogo信封:

netlogo envelope:

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

我的文件信封:

 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:通过将netlogo值导出到栅格并在ArcGIS中进行比较,我检查了实际发生的情况.这不是一个简单的重采样问题.实际上,第一行只是缺少值,而没有移位值.此外,中间的列和行重复,导致所有内容从中间向底部和右侧向外移动.我添加了一个简单的例子,希望这可以解决问题.

推荐答案

我对此进行了进一步调查,并且我认为该错误起源于apply-raster

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

我分析了应用栅格的Java代码在github 上,它在处理gis范围时似乎引用了世界上的min-pxcor和min-pycor.由于实际边缘坐标与面片中心坐标不相似,这可能是造成问题的原因吗?我不是Java专家,但可能需要进一步研究(我可能错了..).

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

无论如何,要使我的ascii很好地适用于我的世界(已将其设置为ascii的大小),我现在运行以下代码:

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

这篇关于使用apply-raster将ascii应用于netlogo时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆