equinor / xtgeo

XTGeo Python class library for subsurface Surfaces, Cubes, Wells, Grids, Points, etc
https://xtgeo.readthedocs.io/en/latest/
GNU Lesser General Public License v3.0
109 stars 57 forks source link

FIX: Inrease robustness in boundary polygons #1163

Closed tnatt closed 7 months ago

tnatt commented 7 months ago

PR to address #1160. After changing to using shapely to create boundary polygons for surfaces in #1140, it seems shapely in some cases fails to create the polygons. Leading to the "POLY_ID" error which derives from an empty polygon and hence an empty dataframe.

This PR should add more robustness to the boundary polygons method by:

  1. Added noding of the linestrings before running the polygonize function to handle potensial crossing lines. See https://github.com/shapely/shapely/issues/1736

  2. Fixing a bug that sometimes created small triangular polygons along the boundary. This cleans up the dataset before running the shapely polygonize function. (This was the case for our complex test case, hence some adjustment was needed there.)

  3. Lastly if in case the dataset is truly unfit for creating a boundary and the polygon returns empty, a more proper error massage is returned before coming to the confusing "POLY_ID" one.

codecov-commenter commented 7 months ago

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (6addf60) 80.08% compared to head (45835d9) 80.08%.

Files Patch % Lines
src/xtgeo/xyz/_polygons_oper.py 86.36% 2 Missing and 1 partial :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1163 +/- ## ======================================= Coverage 80.08% 80.08% ======================================= Files 97 97 Lines 13606 13612 +6 Branches 2185 2186 +1 ======================================= + Hits 10896 10901 +5 - Misses 1980 1981 +1 Partials 730 730 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.