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_returns_geoseries_with_multiindex(self, sources, targets):
result = intersections(sources, targets)
assert isinstance(result, geopandas.GeoSeries)
assert isinstance(result.index, pandas.MultiIndex)
def test_gives_expected_index(self, sources, targets_with_str_index):
expected = manually_compute_intersections(sources, targets_with_str_index)
result = intersections(sources, targets_with_str_index)
they_match = result.index == expected.index
assert they_match.all()
def test_works_with_non_range_index(self, sources, targets_with_str_index):
result = intersections(sources, targets_with_str_index)
assert isinstance(result, geopandas.GeoSeries)
assert isinstance(result.index, pandas.MultiIndex)
def test_indexed_by_source_then_target(self, sources, targets_with_str_index):
result = intersections(sources, targets_with_str_index)
assert (result.index.levels[0] == sources.index).all()
assert (result.index.levels[1] == targets_with_str_index.index).all()
def test_expected_intersections(self, sources, targets_with_str_index):
expected = manually_compute_intersections(sources, targets_with_str_index)
result = intersections(sources, targets_with_str_index)
assert (result == expected).all()
def test_sets_crs(self, sources, targets):
crs = sources.crs
assert crs
inters = intersections(sources, targets)
assert inters.crs == crs
def absorb_by_shared_perimeter(sources, targets, relative_threshold=None):
if len(sources) == 0:
return targets
if len(targets) == 0:
raise IndexError("targets must be nonempty")
inters = intersections(sources, targets, area_cutoff=None).buffer(0)
assignment = assign_to_max(inters.length)
if relative_threshold is not None:
under_threshold = (
sources.area / assignment.map(targets.area)
) < relative_threshold
assignment = assignment[under_threshold]
sources_to_absorb = GeoSeries(
sources.groupby(assignment).apply(unary_union), crs=sources.crs,
)
result = targets.union(sources_to_absorb)
# The .union call only returns the targets who had a corresponding
# source to absorb. Now we fill in all of the unchanged targets.
def assign_by_area(sources, targets):
return assign_to_max(intersections(sources, targets, area_cutoff=0).area)