-
Notifications
You must be signed in to change notification settings - Fork 523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Functional code suddenly breaking at rasterio.mask.mask(src, shapes) #2745
Comments
@jonnyzwi are you able to provide code/files to reproduce this issue? |
This portion of the code is really only a few lines long:
If you run the below in Google Colab, it will import all the necessary input files:
|
Hi @snowman2 — any ideas on this problem? |
Unfortunately, I haven't had a free moment to take a look. I haven't used Google Colab before and so it will likely take longer to dig in. If you can upload the files directly here, that may help save time. |
@jonnyzwi I just tested, and it worked for me 🤷♂️ print(rasterio.__version__)
print(rasterio.__gdal_version__)
print(rasterio.__geos_version__)
print(rasterio.__proj_version__) Here are the files @snowman2 (note I created a COG from the tif because it was 600Mb) |
Thanks @vincentsarago 👍. @jonnyzwi mind providing the output of |
@snowman2 — indeed I had not uploaded because the files were too large. Here is a link to a colab notebook containing the cnode snippet, which you can simply run via the browser https://colab.research.google.com/drive/1tt-NRhPXvgsF9Y3nxWeco2ddCehZeN7R This notebook includes your request to print
which result in
@vincentsarago — did you successfully execute the code in a colab notebook, or elsewhere? I should note that I also attempted to run my code with version 1.3.4 (which was the latest version when this code last worked) by calling |
The bounds computation is happening because you have The line that is throwing the exception: https://github.com/rasterio/rasterio/blob/1.3.5.post1/rasterio/_features.pyx#L413 North_up has no relevance here. In fact, @snowman2, rasterio.features.geometry_window needs to be issuing deprecation warnings for a couple keyword arguments (per the docstring). Inspecting the geointerface of your first shape, we see
The presence of that geometries key is throwing _bounds down the wrong branch. Removing that key results in the correct bounds computation. I don't believe any of the code in this call stack has changed in a couple of years. There are two possibilities I can think of:
Solutions:
elif 'geometries' in geometry and geometry['geometries']:
... |
Good catch. A PR or issue to track is welcome. |
@groutr thanks for digging in. You are likely correct. Fiona 1.9 was recently released with new interfaces to Features/Geometry. |
@groutr thank you for catching that. The problem occurs even when I have filtered out the
Unfortunately, a new issue arises:
|
@jonnyzwi yeah, that's my mistake, it computes the bounds all the time. You need to remove the geometries key like this: shapes = []
for i in shapefile:
shape = i['geometry']
if shape is not None:
geom = dict(shape.__geo_interface__)
del geom['geometries']
shapes.append(geom) # <-- shapes should be a list of dictionaries |
@groutr Thank you! Things appear to be working again. |
This is a Fiona bug, introduced in 1.9.0: Toblerity/Fiona#1197. |
Wait, we can also fix this in rasterio for 1.3.6. I'll do that now. |
Plus a 30-40% speed gain by using zip. Resolves #2745.
Working code (as of two weeks ago) has stopped working. Neither the script itself nor the input has changed.
However, it appears that there was a new merge of rasterio into Main last week. Perhaps this is causing the sudden error?
After inspecting
rasterio/_features.pyx in rasterio._features._bounds()
that was mentioned in the error, my guess is thatnorth_up
is the empty sequence thatValueError: min() arg is an empty sequence
is complaining about.However, it is unclear as to how my call to
rasterio.mask.mask(src, shapes)
interacts withbounds()
or_bounds()
, or wherenorth_up
is supposed to be getting passed in viarasterio.mask.mask
.Any assistance would be appreciated.
The text was updated successfully, but these errors were encountered: