from shapely.wkt import loads as wkt_loads
import pysal
from pysal.lib.cg.kdtree import KDTree
from shapely.geometry import GeometryCollection
import pandas
points = pandas.read_csv('selected-features.csv')
points
points = [wkt_loads(p) for p in points['LongitudeLatitudeWkt'].values if 'POINT' in p]
GeometryCollection(points)
selected_point = points[0].y, points[0].x
locations = [(p.y, p.x) for p in points[1:]]
locations
# new york
selected_point
'''
locations = [(40.702566, -73.816859),
(40.70546, -73.810708),
(40.709179, -73.820574),
(40.700486, -73.807969),
(40.694624, -73.820593),
(40.695132, -73.820841),
(40.694095, -73.821334),
(40.694165, -73.822368),
(40.695077, -73.822817),
(40.6747769261, -73.8092618174)]
'''
tree = KDTree(locations, distance_metric='Arc', radius=pysal.lib.cg.RADIUS_EARTH_MILES)
current_point = (40.709523, -73.802472)
# get all points within 1 mile of 'current_point'
indices = tree.query_ball_point(selected_point, 85)
for i in indices:
print(locations[i])