簡體   English   中英

使用 geojson 文件剪輯柵格時出錯

[英]Error while clip raster using geojson file

我正在嘗試使用 geojson 文件剪輯光柵文件。 這兩個文件具有相同的坐標系和重疊。 這是我的代碼,我收到錯誤(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})         

錯誤

TypeError:無法將序列乘以“Affine”類型的非整數

非常不尋常的是,您的多邊形是在 3D 坐標中定義的。 將它們更改為 2D,錯誤消失。 提供柵格的 URL 即可顯示完整的 MWE。

geoms2d = [
    {
        "type": g["type"],
        "coordinates": [[xyz[0:2] for xyz in p] for p in g["coordinates"]],
    }
    for g in geoms
]

out_image, out_transform = rasterio.mask.mask(src, geoms2d, crop=True)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM