使用geojson文件时剪辑栅格时出错
我正在尝试用Geojson文件夹住栅格文件。两个文件都有相同的坐标系统和重叠。这是我的代码,我会收到错误(TypeError:不能乘以“仿射”类型的非元素乘以序列)
shape_geojson=path of jeojson
input_file= path of geotiff filesenter code here
with open(shape_geojson) as data_file:
geoms= json.load(data_file)
geoms = [{'type': 'Polygon', 'coordinates': [[[372187.1496072686, 5068258.904150674, 0.0],
[373626.0661280414, 5068286.477440579, 0.0], [373548.73687596567, 5069922.161341429, 0.0],
[372152.12599016255, 5069847.257662993, 0.0], [372187.1496072686, 5068258.904150674, 0.0]]]}]
for file in os.listdir(input_file):
with rio.open(os.path.join(input_file, file)) as src:
out_image, out_transform = rio.mask.mask(src, geoms, crop=True)
out_meta = src.meta.copy()
out_meta.update({"driver": "GTiff",
"height": out_image.shape[1],
"width": out_image.shape[2],
"transform": out_transform})
错误
typeerror:不能通过非启动序列乘以“仿射”类型的序列
I am trying to clip the raster file with geojson file. both files have same coordinates system and overlap. here is my code and i am getting the error ( TypeError: can't multiply sequence by non-int of type 'Affine')
shape_geojson=path of jeojson
input_file= path of geotiff filesenter code here
with open(shape_geojson) as data_file:
geoms= json.load(data_file)
geoms = [{'type': 'Polygon', 'coordinates': [[[372187.1496072686, 5068258.904150674, 0.0],
[373626.0661280414, 5068286.477440579, 0.0], [373548.73687596567, 5069922.161341429, 0.0],
[372152.12599016255, 5069847.257662993, 0.0], [372187.1496072686, 5068258.904150674, 0.0]]]}]
for file in os.listdir(input_file):
with rio.open(os.path.join(input_file, file)) as src:
out_image, out_transform = rio.mask.mask(src, geoms, crop=True)
out_meta = src.meta.copy()
out_meta.update({"driver": "GTiff",
"height": out_image.shape[1],
"width": out_image.shape[2],
"transform": out_transform})
Error
TypeError: can't multiply sequence by non-int of type 'Affine'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
非常不寻常的多边形在3D坐标中定义。将它们更改为2D,错误消失了。提供光栅的URL,可以显示完整的MWE。
Very unusually your polygons are defined in 3D coordinates. Change them to 2D and the error goes away. Provide the URL of your raster and a full MWE can be shown.
罗布的回答使我接近了,但是我的坐标嵌套了。
最终必须这样做:
Rob's answer got me close, but my coords were nested.
Ended up having to do this: