Deltares / xugrid

Xarray and unstructured grids
https://deltares.github.io/xugrid/
MIT License
61 stars 8 forks source link

snap_to_grid edge cases #262

Closed JoerivanEngelen closed 1 month ago

JoerivanEngelen commented 1 month ago

I have added some extra tests in https://github.com/Deltares/xugrid/pull/263 for snap_to_grid and found some edge cases:

Lines in series:

    line_x = [2.2, 2.2]
    line_y1 = [82.0, 60.0]
    line_y2 = [60.0, 40.0]
    line_y3 = [40.0, 20.0]
    line_y4 = [20.0, 0.0]
    line1 = shapely.linestrings(line_x, line_y1)
    line2 = shapely.linestrings(line_x, line_y2)
    line3 = shapely.linestrings(line_x, line_y3)
    line4 = shapely.linestrings(line_x, line_y4)
    geometry = gpd.GeoDataFrame(
        geometry=[line1, line2, line3, line4], data={"a": [1.0, 1.0, 1.0, 1.0]}
    )
    uds, gdf = snap_to_grid(geometry, structured, max_snap_distance=0.5)

Produces a UgridDataset with only line indices 0 and 1; line location seems fine.

Crossing lines, produces this:

    line_x = [40.0, 40.0, 40.0]
    line_y = [82.0, 40.0, 0.0]
    line1 = shapely.linestrings(line_x, line_y)
    line2 = shapely.linestrings(line_y, line_x)
    geometry = gpd.GeoDataFrame(
        geometry=[line1, line2], data={"a": [1.0, 2.0]}
    )
    uds, gdf = snap_to_grid(geometry, structured, max_snap_distance=0.5)

image

I'm not sure if the latter is a case we want to support, but in that case at least a clear error would be useful.

JoerivanEngelen commented 1 month ago

Fixed in https://github.com/Deltares/xugrid/pull/263