def test_project_already_projected(): featureset = json2ogr(DISSOLVE_GEOJSON) assert len(featureset['features']) == 4 geom_projected1 = project_local(featureset) try: geom_projected2 = project_local(geom_projected1) except ValueError as e: assert str(e) == 'geometries have already been projected with the \
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
def test_project(): featureset = json2ogr(DISSOLVE_GEOJSON) assert len(featureset['features']) == 4 geom_projected = project_local(featureset) assert isinstance(geom_projected, dict) assert 'features' in geom_projected.keys() assert (geom_projected['crs']['properties']['name'] == 'urn:ogc:def:uom:EPSG::9102') assert (featureset['crs']['properties']['name'] != 'urn:ogc:def:uom:EPSG::9102')
def test_projected_buffer(): featureset = json2ogr(DISSOLVE_GEOJSON) assert len(featureset['features']) == 4 geom_projected = project_local(featureset) geom_buffered = buffer_to_dist(geom_projected, 10) assert isinstance(geom_buffered, dict) assert 'features' in geom_buffered.keys() assert len(geom_buffered['features']) == 4 for f_in, f_out in zip(featureset['features'], geom_buffered['features']): assert f_out['geometry'].area > f_in['geometry'].area
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