Created
August 27, 2019 10:28
-
-
Save prakharcode/3f5cc2e6527532d193ed40de1b4006cf 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_avg_in_r(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' | |
entity.loc[:, f'{name}'] = [ len(x[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