Re: rasterio.features.shapes with holes in polygons

Sean Gillies

Hi Paolo,

Welcome! I ran the your file through rio-shapes and jq

rio shapes --bidx 1 ~/Downloads/sample_cover.tif | jq -c 'select(.properties.val == 3.0)' | fio collect

and then uploaded to a gist:

It looks like the holes aren't lost there. How did you make the second image?

On Tue, Dec 15, 2020 at 3:47 PM Paolo Corti <pcorti@...> wrote:
Hello users and devs

First: thanks a lot for this wonderful project, I am really enjoying using it for my geospatial needs.

For a specific process I am using rasterio.features.shapes and it is working greatly for my purpose. However I have a few cases where I am experiencing strange results.
For example, see this 1 band raster: 

Screen Shot 2020-12-15 at 5.33.13 PM.png
I would like to extract the polygons for the yellow area (value: 3).

When running the following code:

with as src:
cover_arr =
mask = (cover_arr == 3)
polygons = shapes(cover_arr, mask=mask, transform=src.transform)

I get these results (in blue):

Screen Shot 2020-12-15 at 5.35.37 PM.png

Apparently holes are not correctly parsed.

It would be great to know if I am doing something wrong here or if it is something which is not working properly.

For your reference, I am attaching a copy of the raster I am using here so you can reproduce this (sample_cover.tif)

Thanks in advance!

Paolo Corti
Geospatial software developer
twitter: @capooti
skype: capooti

Sean Gillies

Join to automatically receive all group messages.