I have a raster data set with an irregular outline (every value outside is NaN) in Python (loaded from rasterio v.1.3a3 ):
I'd like to extract its outline to a vector shape, such as a Shapely geometry or a WKT/WKB string (red in the figure below) so that, if I use that shape to clip the larger original region which is entirely containing the raster here above, I will end up on the exact same raster data set.
Is there a smarter and more direct way than extracting all the indices of the NaN values to a numpy array (but, hmm, this would be a bunch of useless data as only the ones 'at the border of where the values are' are of interest), figuring a way to apply the affine transform from the raster metadata to that numpy array (how? I can't find a natural way to do so here: https://rasterio.readthedocs.io/en/latest/api/rasterio.transform.html), and finally converting this to a shape so that's it's correctly georeferenced?
I was also thinking using OpenCV but this would probably be overkill...

