You can clip a raster by a vector easily, so first step is to convert your raster to vector.
GDAL > Raster Conversion > Polygonize.
You will have polygons with attribute called DN with values 0 and 1. Select all polygons with value 1 with expression like DN = 1
Use GDAL > Raster Extraction > Clip raster by mask layer. Select the polygonized layer as the ...
If you create a clipping layer with only the circular feature to use, your code can be simplified in this way (I use my own paths):
from osgeo import gdal, ogr
OutTile = gdal.Warp("/home/zeito/pyqgis_data/cut.tif",
@Vince gave an educational comment, @Cyril named it directly, and I like to avoid further confusion; the simple answer is:
clip those grometries!
All queries present in this post do one thing, one way or another, that is selecting every row whose geometries minimum bounding rectangle, the bbox, intersects the created envelope, another bbox.
And that's ...
You can also use raster calculator for this:
Select 'Raster' > 'Raster Calculator...' use the expression ("Mask_raster@1"=1)*"Raster1@1" + ("Mask_raster@1"=0)*-9999 (replace Mask_raster and Raster1 with your layer names).
Select 'Raster' > 'Conversion' > 'Translate (Convert Format)...'. Set the input layer as the layer you just created in raster calculator ...
I noticed later that, even being only one feature, there were tiny islands around the boundary, and maybe the issue was in those. But i wasn't able to delete all of them, because i was in a hurry.
So, to solve my issue, i used Simplify, with "Distance (Douglas-Peucker)" method, using a 1km tolerance. Any type of polygon based directly on the original (...