-
-
Notifications
You must be signed in to change notification settings - Fork 430
v.overlay: add option to remove small areas #7370
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| import pytest | ||
| import grass.script as gs | ||
|
|
||
| # run in a GRASS session with nc_spm_full_v2beta1 | ||
|
|
||
|
|
||
| class TestVOverlay: | ||
| """Test v.overlay output against expected output""" | ||
|
|
||
| # create test data | ||
| @pytest.fixture(scope="class", autouse=True) | ||
| def create_testdata(self): | ||
| # set up | ||
| gs.run_command( | ||
| "v.extract", | ||
| input="boundary_county", | ||
| output="boundary_county_extract1", | ||
| where="NAME in ('CURRITUCK')", | ||
| ) | ||
| gs.run_command( | ||
| "v.extract", | ||
| input="boundary_county", | ||
| output="boundary_county_extract2", | ||
| where="NAME in ('CAMDEN')", | ||
| ) | ||
| # modify extract 1 | ||
| gs.run_command( | ||
| "v.buffer", | ||
| input="boundary_county_extract1", | ||
| output="boundary_county_extract1_buffer_out", | ||
| type="area", | ||
| distance=2, | ||
| ) | ||
| gs.run_command( | ||
| "v.buffer", | ||
| input="boundary_county_extract1_buffer_out", | ||
| output="boundary_county_extract1_buffer_in", | ||
| type="area", | ||
| distance=-2, | ||
| ) | ||
|
|
||
| # run the tests | ||
| yield | ||
|
|
||
| # clean up test data regardless of test success/failure | ||
| gs.run_command( | ||
| "g.remove", type="vector", flags="f", pattern="boundary_county_extract*" | ||
| ) | ||
|
Comment on lines
+7
to
+48
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is the grass temporary session/project created? There is no default data available by default (that could be affected destructively by a low-quality test), unlike gunittest, that these tests already assume a project with certain maps are available and loaded (which end up being integration tests because of that).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the explanation! Indeed I assumed that a default GRASS session with the NC data is already active. So how can I make use of the NC data in a pytest test for a simple fast test? Alternatively, I would extract the test data from the NC data and add them to the GRASS source code, but that seems wrong. |
||
|
|
||
| def test_voverlay_nocleaning(self): | ||
| """ | ||
| Overlay two input vectors and compare the output to the expected output. | ||
| The output will have many very small areas. | ||
| This test would fail in GRASS84 with a too small number of centroids. | ||
| Since GRASS84, calculation for centroids has been improved for | ||
| edge cases like very small areas.""" | ||
| gs.run_command( | ||
| "v.overlay", | ||
| ainput="boundary_county_extract1_buffer_in", | ||
| atype="area", | ||
| binput="boundary_county_extract2", | ||
| btype="area", | ||
| output="boundary_county_extract_overlay_nocleaning", | ||
| operator="or", | ||
| snap=-1, | ||
| quiet=True, | ||
| ) | ||
|
|
||
| reference = { | ||
| "nodes": 1050, | ||
| "primitives": 1802, | ||
| "points": 0, | ||
| "lines": 0, | ||
| "boundaries": 1572, | ||
| "centroids": 230, | ||
| "areas": 529, | ||
| "islands": 7, | ||
| } | ||
|
|
||
| observed = gs.vector_info_topo( | ||
| map="boundary_county_extract_overlay_nocleaning", | ||
| ) | ||
|
|
||
| # compare results | ||
| for key in list(reference): | ||
| # all integers, simple comparison is ok | ||
| assert reference[key] == observed[key], ( | ||
| f"Difference in {key}, expected {reference[key]}, got {observed[key]}" | ||
| ) | ||
|
|
||
| def test_voverlay_withcleaning(self): | ||
| """Overlay two input vectors and compare the output to the expected output. | ||
| The output will have many very small areas. | ||
| This is a test for the cleaning options snap and minsize""" | ||
| gs.run_command( | ||
| "v.overlay", | ||
| ainput="boundary_county_extract1_buffer_in", | ||
| atype="area", | ||
| binput="boundary_county_extract2", | ||
| btype="area", | ||
| output="boundary_county_extract_overlay_withcleaning", | ||
| operator="or", | ||
| snap=1.0e-6, | ||
| minsize=0.00001, | ||
| quiet=True, | ||
| ) | ||
|
|
||
| reference = { | ||
| "nodes": 1232, | ||
| "primitives": 2164, | ||
| "points": 0, | ||
| "lines": 0, | ||
| "boundaries": 1847, | ||
| "centroids": 317, | ||
| "areas": 622, | ||
| "islands": 7, | ||
| } | ||
|
|
||
| observed = gs.vector_info_topo( | ||
| map="boundary_county_extract_overlay_withcleaning", | ||
| ) | ||
|
|
||
| # compare results | ||
| for key in list(reference): | ||
| # all integers, simple comparison is ok | ||
| assert reference[key] == observed[key], ( | ||
| f"Difference in {key}, expected {reference[key]}, got {observed[key]}" | ||
| ) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is autouse a pattern we want to use, or we prefer being explicit of the side effects?