Python 区域统计脚本:尝试安装 rioxarray 后出现问题
Python Zonal statistics script: Problem after trying to install rioxarray
我有一个用于计算区域统计数据(中位数)的脚本,但现在我得到了 AttributeError:'DatasetReader' 对象没有属性 'affine'。
这是我的代码:
with rasterio.open(f'{project_data}/ras.tif') as raster:
array = raster.read(1)
affine = raster.affine
stat = zonal_stats(f'{project_data}/Lila.shp', array, affine=affine,
stats=['median'], geojson_out=True)
result = {"type": "FeatureCollection", "features": stat}
outname = f'{project_data}/files/Lala_test.geojson'
with open(outname, 'w') as outfile:
json.dump(result, outfile)
我昨天尝试用 Anaconda 安装 rioxarray 但没有成功,我使用的是虚拟 conda - 环境 (Python 3.8 Interpreter),这可能是问题所在吗?如果是,我该如何解决?我在 windows 10...
affine
已弃用。 transform
现在接受 GDAL 和仿射样式转换。
从 迁移到 Rasterio 1.0
affine.Affine() 与 GDAL 风格的地理变换:
https://rasterio.readthedocs.io/en/latest/topics/migrating-to-v1.html
Since the above changes, several functions have been added to Rasterio
that accept a transform argument. Rather than add an affine argument
to each, the transform argument could be either an Affine() object or
a GDAL geotransform, the latter issuing the same deprecation warning.
The original plan was to remove the affine argument + property, and
assume that the object passed to transform is an Affine(). However,
after further discussion it was determined that since Affine() and
GDAL geotransforms are both 6 element tuples users may experience
unexplained errors and outputs, so an exception is raised instead to
better highlight the error.
我有一个用于计算区域统计数据(中位数)的脚本,但现在我得到了 AttributeError:'DatasetReader' 对象没有属性 'affine'。 这是我的代码:
with rasterio.open(f'{project_data}/ras.tif') as raster:
array = raster.read(1)
affine = raster.affine
stat = zonal_stats(f'{project_data}/Lila.shp', array, affine=affine,
stats=['median'], geojson_out=True)
result = {"type": "FeatureCollection", "features": stat}
outname = f'{project_data}/files/Lala_test.geojson'
with open(outname, 'w') as outfile:
json.dump(result, outfile)
我昨天尝试用 Anaconda 安装 rioxarray 但没有成功,我使用的是虚拟 conda - 环境 (Python 3.8 Interpreter),这可能是问题所在吗?如果是,我该如何解决?我在 windows 10...
affine
已弃用。 transform
现在接受 GDAL 和仿射样式转换。
从 迁移到 Rasterio 1.0 affine.Affine() 与 GDAL 风格的地理变换:
https://rasterio.readthedocs.io/en/latest/topics/migrating-to-v1.html
Since the above changes, several functions have been added to Rasterio that accept a transform argument. Rather than add an affine argument to each, the transform argument could be either an Affine() object or a GDAL geotransform, the latter issuing the same deprecation warning.
The original plan was to remove the affine argument + property, and assume that the object passed to transform is an Affine(). However, after further discussion it was determined that since Affine() and GDAL geotransforms are both 6 element tuples users may experience unexplained errors and outputs, so an exception is raised instead to better highlight the error.