简体   繁体   English

Python:GDAL错误-RasterIO()中的访问窗口超出范围

[英]Python: GDAL ERROR - Access window out of range in RasterIO()

i have this error problem with GDAL/ 我在GDAL /中遇到此错误问题

INPUT_raster = "E:\myraster.asc"
ds = gdal.Open(INPUT_raster, gdal.GA_ReadOnly)
band = ds.GetRasterBand(1)
data = band.ReadAsArray(9658, 11599, 1, 1)
ERROR 5: E:\myraster.asc, band 1: Access window out of range in RasterIO().  Requested
(9658,11599) of size 1x1 on raster of 9658x16934.

is it possible to use try: and expect: to avoid this error? 是否可以使用try:和Expect:避免此错误?

I would appreciate your comments/suggestions. 非常感谢您的意见/建议。

Regards, Gianni 问候,詹妮

Try/expect dont avoid errors, they handle them. 尝试/期待不要避免错误,他们会处理错误。

You are trying to read data from a position which doesnt exist in your raster. 您正在尝试从栅格中不存在的位置读取数据。 The x dimension is 9658 elements large, if you want the outer most element you should use 9657 because the indexing starts at zero. x尺寸为9658个元素大,如果希望最外面的元素,则应使用9657,因为索引从零开始。

So use: 因此使用:

data = band.ReadAsArray(9657, 11599, 1, 1)

or for the last x position: 或最后一个x位置:

data = band.ReadAsArray(ds.RasterXSize-1, 11599, 1, 1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM