admin管理员组

文章数量:1391943

I used this script to crop a raster using a polygon shapefile with python gdal.Warp, but it seems it leaves many pixels with value = 1 outside the cropline

gdal.Warp(rasterOut.jp2,
           rasterIn.jp2, 
           cutlineDSName=mask.shp,
           cropToCutline=True,
           dstNodata = nodata)

I can select any nodata, like 0 or np.nan, but the results doesn't change

I used this script to crop a raster using a polygon shapefile with python gdal.Warp, but it seems it leaves many pixels with value = 1 outside the cropline

gdal.Warp(rasterOut.jp2,
           rasterIn.jp2, 
           cutlineDSName=mask.shp,
           cropToCutline=True,
           dstNodata = nodata)

I can select any nodata, like 0 or np.nan, but the results doesn't change

Share Improve this question asked Mar 13 at 10:37 ilFontailFonta 3014 silver badges20 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Can you try setting stricter clipping with warpOptions=["CUTLINE_ALL_TOUCHED=TRUE"])

gdal.Warp("rasterOut.jp2", "rasterIn.jp2",
          cutlineDSName="mask.shp",
          cropToCutline=True,
          dstNodata=nodata,  
          warpOptions=["CUTLINE_ALL_TOUCHED=TRUE"]) 

本文标签: python gdalwarp doesn39t properly crop raster over shapefile polygonsStack Overflow