text_html_output_1.png
from geopandas.tools import geocode

import folium

import numpy as np

import pandas as pd

import numpy as np
import pandas as pd
import geopandas as gpd
from geopandas.tools import geocode
import folium
agent = 'my_colls_app'

ramp_path = '../input/rampdatalog/RampDataLog.xlsm'
ramp_df = pd.read_excel(ramp_path, sheet_name='data')

ramp_df.rename(columns={'Cross Street 1': 'CS_1', 'Cross Street 2': 'CS_2'}, inplace=True)

ramp_df.replace(' NE', 'NE', inplace=True)
ramp_df.Notes.fillna('None', inplace=True)

import math
def cs_comb_str(cs1, cs2):
    """
    Take an intersection's cross streets as arguments and return
    a string of the complete location
    """
    inter = ''
    suffixes = ['Ave', 'Ln', 'Terr']
    if 'btw' in cs1:
        inter = cs1.split('btw')[0] + 'Ave btw ' + cs2
    elif type(cs2) != str:
        inter = cs1
    elif '(' in cs2:
        inter = cs1 + ' Ave and ' + cs2.split()[0] + ' Ave ' + cs2.split()[1]
    else:
        if not any([suf in cs1 for suf in suffixes]):
            cs1 += ' Ave'
        if not any([suf in cs2 for suf in suffixes]) and (not any([landmark in cs2 for landmark in ['alleyway', 'exit']])) and (len(cs2.split()[-1]) > 1):
            cs2 += ' Ave'
        inter = ' and '.join([cs1, cs2])
    return inter

ramp_df['Inter'] = ramp_df.apply(lambda row: cs_comb_str(row['CS_1'], row['CS_2']), axis=1)

cols = ramp_df.columns.tolist()
cols = cols[:3] + cols[-2:] + cols[3:-2]
ramp_df = ramp_df[cols]

ramp_df.to_csv('CollingswoodADA_LatLong_checkpoint.csv', index=False)

ramp_df = pd.read_csv('../input/collingswoodada-clean-latlong/CollingswoodADA_LatLong_checkpoint.csv')

def geo_short(location):
    """
    Take address, cross-street, etc. and return geocoded point at which
    lat/long can conveniently accessed.  Uses Nominatim.
    """
    pt = geocode(location, provider='nominatim', user_agent=agent)
    return pt.geometry.iloc[0]

def basemap_with_buffer(location, buffer_radius_miles):
    centerpoint = geo_short(location)
    basemap = folium.Map(location=[centerpoint.y, centerpoint.x], tiles='openstreetmap', zoom_start=15)
    buffer_radius_meters = buffer_radius_miles * 5280 / 3.28084
    basemap_buffer = folium.Circle(location=[centerpoint.y, centerpoint.x], radius=buffer_radius_meters).add_to(basemap)
    return basemap

patco_address = '100 Lees Ave, Collingswood, NJ 08108'
patco_base = basemap_with_buffer(patco_address, 0.5)
patco_base

patco_base = basemap_with_buffer(patco_address, 0.5)
for i, location in ramp_df.iterrows():
    if not np.isnan(location.Lat) and (not np.isnan(location.Long)):
        folium.Marker(location=[location.Lat, location.Long], tooltip=location.Inter).add_to(patco_base)
patco_base

from folium.plugins import MarkerCluster
patco_base = basemap_with_buffer(patco_address, 0.5)
marker_cluster = folium.plugins.MarkerCluster()
for i, location in ramp_df.iterrows():
    if not np.isnan(location.Lat) and (not np.isnan(location.Long)):
        marker_cluster.add_child(folium.Marker([location.Lat, location.Long], tooltip=location.Inter))
patco_base.add_child(marker_cluster)
patco_base