Skip to content

Instantly share code, notes, and snippets.

@prakharcode
Created August 27, 2019 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prakharcode/3f5cc2e6527532d193ed40de1b4006cf to your computer and use it in GitHub Desktop.
Save prakharcode/3f5cc2e6527532d193ed40de1b4006cf to your computer and use it in GitHub Desktop.
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