Thanks to Kashfi Fahim for suggesting this tool.
{ search_address : Search Address ? Find the basketball courts closest to this address }
{ search_count : Search Count ? Limit the number of basketball courts shown }
{ source_table_url : NYC Open Data JSON URL ? Specify the data source }
The Table of Basketball Courts in NYC is from the NYC Open Data Website.
The Tech Incubator at CUNY Queens College is hosting a Student Showcase of Tools Made with NYC Open Data Using Python on Sunday, March 4, 2018 from 3pm to 4:30pm.
Visit NYC Open Data Week for more events featuring NYC Open Data.
# CrossCompute
search_address = '2435 Grand Concourse, Bronx, NY 10468'
search_count = 5
source_table_url = 'https://www.nycgovparks.org/bigapps/DPR_Basketball_001.json'
target_folder = '/tmp'
import pandas as pd
t = pd.read_json(source_table_url)
t.head()
# Drop rows that are missing coordinates
t.dropna(subset=['lat', 'lon'], inplace=True)
t.iloc[0]
t[['lat', 'lon']][:3]
source_latlons = t[['lat', 'lon']].values
source_latlons
import geopy
# Convert address to latitude and longitude
geocode = geopy.GoogleV3('AIzaSyDNqc0tWzXHx_wIp1w75-XTcCk4BSphB5w').geocode
search_location = geocode(search_address)
search_latlon = search_location.latitude, search_location.longitude
search_latlon
import pip
pip.main(['install', 'pysal'])
from pysal.cg import RADIUS_EARTH_MILES
from pysal.cg.kdtree import KDTree
source_tree = KDTree(source_latlons, distance_metric='Arc', radius=RADIUS_EARTH_MILES)
distances, indices = source_tree.query(search_latlon, k=search_count)
print(distances)
print(indices)
selected_t = t.iloc[indices].copy()
selected_t['Distance'] = distances
selected_t
from os.path import join
target_path = join(target_folder, 'locations.csv')
selected_t.to_csv(target_path, index=False)
print('selected_location_geotable_path = %s' % target_path)
{ selected_location_geotable : Nearest Basketball Courts ? Click on a circle to see details }