I'm updating a Python script which currently calls gdal_contour as a subprocess to extract contours. I'd like to replace gdal_contour
with skimage.find_contours.
However the output of the GDAL script differs slightly from scikit-image's output when used on a raster with angled sides. Here are a few images to illustrate:
Before extracting contours, my source raster is first masked (via rasterio.mask.mask) with a rectangular polygon, producing something like this:
When I use skimage.find_contours
, it produces open contours (which is what I want) when the desired height disappears out of bounds, as in the bottom of the right edge below:
But when the mask is rotated, like this:
The contours produced by skimage.find_contours
now follow the edge of the raster when they pass out of bounds and are closed, as in the bottom-right corner.
(Contours produced by GDAL from the same raster are open in the same corner.)
I guess I could add a margin, then clip the contours to the correct bounds, but is there another way to deal with this situation?
(I'm open to alternatives to scikit-image, see my previous question here.)
skimage.measure.find_contours
doesn't take nodata into account (only the edge of the array) when deciding whether to open or close a contour. From the docs: "contours which intersect the array edge will be left open. All other contours will be closed." I think I might end up extracting the contours for the whole raster, then clipping by the rotated mask.find_contours
and it seems it doesn't offer any options. consider sticking togdal_contours
since you can specify a null_value to take into account. I'm not sure if that means it returns open isohypses, though...