Esempio n. 1
0
def test_successful_intersection():

    featureset1 = json2ogr(INTERSECT_PARTIALLY_WITHIN_GEOJSON)
    featureset2 = json2ogr(INTERSECT_BASE_GEOJSON)

    result_featureset = intersect(featureset1, featureset2)
    assert len(result_featureset['features']) == 1
    assert isinstance(result_featureset['features'][0]['geometry'],
                      MultiPolygon)
def test_count():
    featureset1 = json2ogr(INTERSECT_BASE_GEOJSON)
    featureset2 = json2ogr(INTERSECT_MULTIPLE_FEATURES)

    intersection = intersect(featureset1, featureset2)
    assert len(intersection['features']) == 2

    count = get_intersect_count(intersection, 'id')
    assert count == 3
def test_area_percent_no_categories():
    featureset1 = json2ogr(INTERSECT_PARTIALLY_WITHIN_GEOJSON)
    featureset2 = json2ogr(INTERSECT_BASE_GEOJSON)

    result_featureset = intersect(featureset1, featureset2)
    assert len(result_featureset['features']) == 1

    pct_overlap = get_intersect_area_percent(featureset1, result_featureset)
    assert isinstance(pct_overlap, float)
    assert pct_overlap > 0 and pct_overlap <= 100
def test_z_scores():
    featureset1 = json2ogr(INTERSECT_BASE_GEOJSON)
    featureset2 = json2ogr(INTERSECT_MULTIPLE_FEATURES)

    intersection = intersect(featureset1, featureset2)
    assert len(intersection['features']) == 2

    scores = get_intersect_z_scores(intersection, 'id', 'value')
    assert len(scores) == 2
    assert 1 in scores.keys() and 2 in scores.keys()
    assert isinstance(scores[1], float)
def test_area_percent_no_categories_fail():
    featureset1 = json2ogr(INTERSECT_BASE_GEOJSON)
    featureset2 = json2ogr(INTERSECT_MULTIPLE_FEATURES)

    intersection = intersect(featureset1, featureset2)
    assert len(intersection['features']) == 2
    field_vals = [f['properties']['id'] for f in intersection['features']]
    assert len(field_vals) == len(set(field_vals))

    try:
        pct_overlap = get_intersect_area_percent(featureset1,
                                                 intersection,
                                                 category='id')
    except ValueError as e:
        assert str(e) == 'Intersected area must be dissolved to a single \
def test_area_stats_with_categories():
    featureset1 = json2ogr(INTERSECT_BASE_GEOJSON)
    featureset2 = json2ogr(INTERSECT_MULTIPLE_FEATURES)

    intersection = intersect(featureset1, featureset2)
    assert len(intersection['features']) == 2
    field_vals = [f['properties']['id'] for f in intersection['features']]
    assert len(field_vals) == len(set(field_vals))

    pct_overlap = get_intersect_area_percent(featureset1,
                                             intersection,
                                             category='id')
    assert isinstance(pct_overlap, dict)
    assert len(pct_overlap.keys()) == 2
    for val in pct_overlap.keys():
        assert pct_overlap[val] > 0 and pct_overlap[val] <= 100
Esempio n. 7
0
def test_area_percent_no_categories():
    featureset1 = json2ogr(INTERSECT_PARTIALLY_WITHIN_GEOJSON)
    for i,f in enumerate(featureset1['features']):
        f['properties']['id'] = i
    featureset2 = json2ogr(INTERSECT_BASE_GEOJSON)

    result_featureset = intersect(featureset1, featureset2)
    assert len(result_featureset['features']) == 1

    featureset1_projected = project_local(featureset1)
    result_projected = project_local(result_featureset)

    aoi_area = get_area(featureset1_projected)
    area_pct = get_area_percent(result_projected, aoi_area)

    assert area_pct
    assert isinstance(area_pct, float)
    assert area_pct > 0 and area_pct <=100
Esempio n. 8
0
def test_area_percent_with_categories():
    featureset1 = json2ogr(INTERSECT_BASE_GEOJSON)
    for i,f in enumerate(featureset1['features']):
        f['properties']['id'] = i
    featureset2 = json2ogr(INTERSECT_MULTIPLE_FEATURES)

    result_featureset = intersect(featureset1, featureset2)
    assert len(result_featureset['features']) == 2
    field_vals = [f['properties']['value'] for f in result_featureset['features']]
    assert len(field_vals) == len(set(field_vals))

    featureset1_projected = project_local(featureset1)
    result_projected = project_local(result_featureset)

    aoi_area = get_area(featureset1_projected, 'id')
    area_pct = get_area_percent(result_projected, aoi_area, 'id', 'value')

    assert area_pct
    assert isinstance(area_pct, dict)
    for area_pct_cats in area_pct.values():
        assert isinstance(area_pct_cats, dict)
        for val in area_pct_cats.values():
            assert isinstance(val, float)
            assert val > 0 and val <=100