How to use the maup.intersections.intersections function in maup

To help you get started, we’ve selected a few maup examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mggg / maup / tests / test_intersections.py View on Github external
def test_returns_geoseries_with_multiindex(self, sources, targets):
        result = intersections(sources, targets)

        assert isinstance(result, geopandas.GeoSeries)
        assert isinstance(result.index, pandas.MultiIndex)
github mggg / maup / tests / test_intersections.py View on Github external
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()
github mggg / maup / tests / test_intersections.py View on Github external
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)
github mggg / maup / tests / test_intersections.py View on Github external
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()
github mggg / maup / tests / test_intersections.py View on Github external
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()
github mggg / maup / tests / test_intersections.py View on Github external
def test_sets_crs(self, sources, targets):
        crs = sources.crs
        assert crs
        inters = intersections(sources, targets)
        assert inters.crs == crs
github mggg / maup / maup / repair.py View on Github external
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.
github mggg / maup / maup / assign.py View on Github external
def assign_by_area(sources, targets):
    return assign_to_max(intersections(sources, targets, area_cutoff=0).area)