Commit 86bb3659 authored by  Lukas Eller's avatar Lukas Eller

Updated assign land use classes:

- number of categories now dynamic
- included a category function for aggregation

New release
parent 36c18f1c
......@@ -4,7 +4,7 @@ from shapely.geometry import LineString, Point, Polygon, box
from shapely.ops import unary_union
from tqdm import tqdm
import pandas as pd
from typing import Dict
from typing import Dict, Union, Callable
def project_onto_streets(
point_series: gpd.GeoSeries,
......@@ -206,13 +206,16 @@ def delete_indoor_meas(
return outdoor_meas_gdf.geometry
def assign_landuse_classes(
point_geodataframe: gpd.GeoDataFrame,
polygon_geodataframe: gpd.GeoDataFrame,
cut_polygons_by_buffer: bool = False,
buffer_size: int = 0,
category_function : Union[None, Callable] = lambda land_use_code: "Urban" if land_use_code < 200 else "Rural",
epsg: str = "EPSG:31287",
) -> Dict:
n_categories: int = 5
) -> gpd.GeoDataFrame:
'''
Returns a DataFrame with the landuse class distribution in the area defined by the buffer_size around the passed locations
Landuseclasses are defined according to the Corine Land Cover Project:
......@@ -230,7 +233,9 @@ def assign_landuse_classes(
:param polygon_geodataframe: A GeoDataFrame with the landuse class polygons. Can be retrieved from
:param cut_polygons_by_buffer: If True the polygon_geodataframe will be cut by the total bounds of the point series. Can result in a speedup.
:param buffer_size: The buffer_size in meters used to construct the area around points for which the distribution of classes will be computed.
:param category_function: If not None a additional dataframe is returned which aggregates land_use classes to the defined categories
:param epsg: The projection used for the computation of the area. Defaults to EPSG:31287 for Austria.
:param n_categories: Maximum number of top categories sorted by the respective percentage values to be considered.
:return: A GeoDataFrame with columns describing the percentage of the area assigned to the respective land use class.
'''
......@@ -273,8 +278,22 @@ def assign_landuse_classes(
for key, value in zip(codes, percentages):
code_percent_dict[key] = code_percent_dict.get(key, 0) + value
code_percent_dict = dict(sorted(code_percent_dict.items(), key=lambda x: x[1], reverse =True))
first5pairs = {k: dict(code_percent_dict)[k] for k in list(dict(code_percent_dict))[:5]}
firstnpairs = {int(k): dict(code_percent_dict)[k] for k in list(dict(code_percent_dict))[:n_categories]}
results[i] = firstnpairs
if category_function is not None:
processed = {}
for key, result in results.items():
processed[key] = {}
for land_use, area_percentage in result.items():
category = category_function(land_use)
processed[key][category] = processed[key].get(category, 0) + area_percentage
processed_result = pd.DataFrame(processed).transpose()
processed_result.replace(np.nan, 0, inplace=True)
results[i] = first5pairs
return results, processed_result
return results
else:
return results
......@@ -12,7 +12,7 @@ README = (HERE / "README.md").read_text()
# This call to setup() does all the work
setup(
name="measprocess",
version="0.6.6",
version="0.6.7",
description="Collection of measurement processing tools",
long_description=README,
long_description_content_type="text/markdown",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment