Функция, производящая пространственное агрегирование (python) - PullRequest
0 голосов
/ 27 апреля 2020

Необходимо написать функцию «пространственный_результат», которая производит пространственное агрегирование (python). Он принимает в качестве аргументов

init - initial geo-splitting

agg - a new geo-splitting that will be used for spatial aggregation

column - name of the column of the quantitative variable in init that will be aggregated

method - aggregation method (sum or mean)

kind - method for aggregation when polygons from agg_polygons and init_polygons partially intersect. 
It can be 'max' - assign a value in column to a polygon from agg with the maximum intersection area; 
and 'per' -split the value in column in proportion to the intersection areas.

Вот пример ввода и вывода для этой функции:

P1 = gpd.read_file('./P1.shp')
P1.crs = "EPSG:4326"  
P2 = gpd.read_file('./P2.shp')
P1['random_value'] = np.random.randint(0, 100, len(P1))

mean_resample = spatial_resample(agg=P2, init=P1, method='mean', column='random_value', kind='max')
sum_resample = spatial_resample(agg_polygons=P2, init_polygons=P1, method='sum', 
                                column='random_value', kind='max')
mean_resample.head()

OUTPUT

Я пытался сделать это, используя пространственное соединение для «init» и «agg», и после этого применить метод агрегации, но я действительно не знаю, как учитывать параметр «kind» в реализации. Не могли бы вы помочь мне, пожалуйста.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...