Repository navigation
r.lake: Only set seed point when coordinates are given - #7874
Merged
Merged
Conversation
Missing braces made the seed assignment run on every invocation, adding an unintended seed at the north-west corner of the computational region when seed= is used.
Member
|
I'm waiting for the CI results, the description and changes seem fine |
echoix
approved these changes
Sep 1, 2026
marisn
approved these changes
Sep 1, 2026
marisn
left a comment
Contributor
There was a problem hiding this comment.
Looks good to me, but I can not judge Python code in tests, as I am not that familiar with latest trends in GRASS Python code writing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In
raster/r.lake/main.cthe statement that plants the seed point sits outside the bracelessif (sdxy_opt->answer)block that is meant to guard it, so it runs on every invocation:start_rowandstart_colare initialised to0and are only assigned in thecoordinates=branch. The parser makesseed=andcoordinates=mutually exclusive, so on everyseed=<raster>run the line above setsout_water[0][0] = 1, adding a seed at the north-west corner cell of the computational region that the user never asked for.The stray seed is not inert. If the terrain at that corner is below
water_level, the flood fill spreads from it exactly as it would from a real seed, producing a second water body unconnected to the seed map. If the corner is abovewater_levelit is cleared on the first sweep and nothing happens, which is why the defect is easy to miss.Impact
The tool exits 0 and emits no warning, so the result looks correct. The reported
Lake areaandLake volumeinclude the spurious body, and the documented workflow of feeding a lake map from one run back in as the seed for the next carries the contamination forward.Reproduction
A 20x20 region with a basin in the south-east at elevation 5, a separate low area in the north-west at elevation 8, a ridge at elevation 50 between them, one seed cell inside the south-east basin, and
water_level=10. Only the south-east basin is reachable from the seed, so the expected result is 36 wet cells in a single water body.Fix
Add the braces so the seed point is set only when coordinates are given. With
seed=,out_wateris already fully populated from the seed raster, so nothing else is needed.Tests
r.lakehad no tests. This addsraster/r.lake/tests/r_lake_test.pywith three cases covering the seed map path: total wet cells, the unseeded low area staying dry, and the number of distinct water bodies. All three fail onmainand pass with the fix.The
coordinates=path is unchanged. Seeding inside the basin still yields 36 cells, and seeding on the dry ridge still fails withGiven water level at seed point is below earth surface.