Skip to content
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

HRA regression when rasterizing spatial criteria #1120

Closed
phargogh opened this issue Nov 21, 2022 · 5 comments · Fixed by #1121
Closed

HRA regression when rasterizing spatial criteria #1120

phargogh opened this issue Nov 21, 2022 · 5 comments · Fixed by #1121
Assignees
Labels
bug Something isn't working in progress This issue is actively being worked on

Comments

@phargogh
Copy link
Member

phargogh commented Nov 21, 2022

A user on the forums noticed a difference in how spatial criteria were being represented between InVEST 3.9 (former HRA) and InVEST 3.12 (the new HRA implementation), specifically around how input vectors are being rasterized.

After digging into this for a while, it appears that the InVEST 3.9 implementation makes the following distinction that I missed when rewriting HRA:

  • Habitat and stressor vectors are rasterized with ALL_TOUCHED=TRUE
  • Spatial criteria vectors are rasterized with ALL_TOUCHED=FALSE

The current HRA does not make this distinction, but probably should, at least for backwards compatibility.

For what it's worth, I could not find this distinction in the InVEST 3.3.0 HRA.

@phargogh phargogh self-assigned this Nov 21, 2022
@phargogh phargogh added bug Something isn't working in progress This issue is actively being worked on labels Nov 21, 2022
phargogh added a commit to phargogh/invest that referenced this issue Nov 21, 2022
Only habitats and stressors should now be rasterized with
ALL_TOUCHED=TRUE.  Spatial criteria vectors should not be.

RE:natcap#1120
@davemfish
Copy link
Contributor

Habitat and stressor vectors are rasterized with ALL_TOUCHED=TRUE
Spatial criteria vectors are rasterized with ALL_TOUCHED=FALSE

@phargogh Do you think there is a reason these were different in 3.9? Otherwise it might be nice make them consistent, if it wouldn't ruffle too many feathers.

@davemfish
Copy link
Contributor

Oh, whoops, maybe I misinterpreted. My suggestion is probably exactly what was ruffling the feathers in the first place. Nevermind.

@phargogh
Copy link
Member Author

phargogh commented Nov 21, 2022

Yeah, the change in rasterization behavior is what was ruffling feathers in the forums thread, and this change was by accident.

If there was a deliberate reason to have these cases be handled differently, I can't find a reference for it in the source code or the user's guide, and all the references to rasterization I can find in the original InVEST 3.3.0 use a consistent ALL_TOUCHED=TRUE, so I think it'll be worth looking into this more closely and seeing what makes more sense in the long run and then deliberately making that change.

What do you think?

Looking back at the very first version of HRA, the ArcGIS edition of HRA used pixel centerpoints to determine whether a pixel is rasterized (at least as of ArcGIS 10.1). GDAL uses Bresenham's line algorithm in addition to centerpoint checking (source). So we've been all over the place, historically, with our rasterization methodologies.

@davemfish
Copy link
Contributor

I'm in favor of making the rasterization internally consistent; using the same ALL_TOUCHED rule for all rasterizations. If a user really needs full control over the rasterization method, they have the option to do it themselves and feed rasters into the model instead of vectors, right?

My take is that the new HRA represents a correction rather than a regression.

@davemfish
Copy link
Contributor

I just took a quick look at the sample data. It seems commonplace for the footprint of a spatial criteria layer to exactly match the footprint of either a habitat or stressor. So I could imagine that rasterizing with different rules could result in a problem where, after rasterizing, a pixel on the margin might have presence of both the habitat & stressor, but would be missing the spatial criteria rating associated with that habitat-stressor pair.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working in progress This issue is actively being worked on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants