Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_queen_on_four_square_grid(self, four_square_grid):
adjs = adjacencies(four_square_grid, "queen")
assert set(adjs.index) == {(0, 1), (1, 3), (2, 3), (0, 2), (1, 2), (0, 3)}
def test_sets_crs(self, four_square_grid):
assert four_square_grid.crs
adjs = adjacencies(four_square_grid)
assert adjs.crs == four_square_grid.crs
def test_warns_for_islands(self, four_square_grid):
with pytest.warns(IslandWarning):
adjacencies(four_square_grid.loc[[0, 3]])
def test_raises_for_invalid_adj_type(self, four_square_grid):
with pytest.raises(ValueError):
adjacencies(four_square_grid, "knight")
def test_on_four_square_grid(self, four_square_grid):
adjs = adjacencies(four_square_grid)
assert set(adjs.index) == {(0, 1), (1, 3), (2, 3), (0, 2)}
def test_warns_for_overlaps(self, squares_some_neat_some_overlapping):
with pytest.warns(OverlapWarning):
adjacencies(squares_some_neat_some_overlapping)
def test_returns_geometries(self, four_square_grid):
adjs = adjacencies(four_square_grid)
assert len(adjs.length) == 4
for geom in adjs:
assert isinstance(geom, BaseGeometry)
def resolve_overlaps(geometries, relative_threshold=0.1):
"""For any pair of overlapping geometries, assigns the overlapping area to the
geometry that shares the most perimeter with the overlap. Returns the GeoSeries
of geometries, which will have no overlaps.
If the ratio of the overlap's area to either of the overlapping geometries'
areas is greater than `relative_threshold`, then the overlap is ignored.
The default `relative_threshold` is `0.1`. This default is chosen to include
tiny overlaps that can be safely auto-fixed while preserving major overlaps
that might indicate deeper issues and should be handled on a case-by-case
basis. Set `relative_threshold=None` to resolve all overlaps.
"""
geometries = get_geometries(geometries)
inters = adjacencies(geometries, warn_for_islands=False, warn_for_overlaps=False)
overlaps = inters[inters.area > 0].buffer(0)
if relative_threshold is not None:
left_areas, right_areas = split_by_level(geometries.area, overlaps.index)
under_threshold = ((overlaps.area / left_areas) < relative_threshold) & (
(overlaps.area / right_areas) < relative_threshold
)
overlaps = overlaps[under_threshold]
if len(overlaps) == 0:
return geometries
to_remove = GeoSeries(
pandas.concat([overlaps.droplevel(1), overlaps.droplevel(0)]), crs=overlaps.crs
)
with_overlaps_removed = geometries.difference(to_remove)