Last active
August 27, 2019 12:22
-
-
Save prakharcode/dd1a4398948d0ae438fe9e8cc59d2de7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def calc_poi_opr_in_radius(poi, entity, radius, **kwargs): | |
entity = entity.copy() | |
KDT = KDTree(poi[['lat', 'long']]) | |
deg_to_m = 1/108000.0 | |
query = entity.progress_apply(lambda g: KDT.query_radius([[g.lat, g.long1]], r= deg_to_m * radius), axis=1) | |
name = kwargs['name'] if kwargs['name'] else 'default' | |
pos_item = list(poi.columns).index(kwargs['avg_by']) | |
col = kwargs['avg_by'] | |
entity.loc[:, kwargs['opr'] + "_" + name] = [ eval("poi.iloc[ x[0], pos_item].{0}()".format(kwargs['opr']), {'poi': poi, 'x':x,'pos_item': pos_item, 'col':col }) if len(x[0]) > 0 else 0 for x in tqdm(query)] | |
return entity |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
pois = {'parlours': [parlours, 'count', 100, 'name'],
'doctors':[doctors, 'count', 100, 'link'],
'salons': [salons, 'count', 100, 'name'],
'schools': [schools, 'count', 100, 'objectid'],
'family': [family_size, 'sum', 1000, 'FamilyCounts'],
'NF': [family_size, 'sum', 1000, 'NuclearFamilyCounts']
}