In [1]:
import pandas as pd
import numpy as np
import urllib
import os
import folium
from folium import plugins
from fastkml.kml import KML
from IPython.display import IFrame


Package `lxml` missing. Pretty print will be disabled

In [2]:
def read_kml(fname='Preschools.kml'):
    kml = KML()
    kml.from_string(open(fname).read())
    points = dict()
    for feature in kml.features():
        for placemark in feature.features():
            points.update({placemark.name:
                            (placemark.geometry.y, placemark.geometry.x, )})
    return points

In [3]:
ps = read_kml()

In [4]:
print(len(ps))
ps


53
Out[4]:
{'Tiggers Honeypot': (-33.915571, 151.236203),
 'Uniting Frederick Street Preschool Rockdale': (-33.9518685, 151.1332963),
 "KU Children's Services": (-33.869126, 151.193269),
 'Waratah Cottage Early Learning Centre': (-34.044405, 150.810212),
 'Lansvale Public School': (-33.8916589, 150.9535235),
 'Globe Wilkins Preschool': (-33.9014902, 151.1552004),
 'KU Killara Park Preschool': (-33.7593637, 151.1715553),
 'Uniting Dove Cottage Early Learning Bankstown': (-33.912414, 151.039072),
 'Ballykin at Rose Bay': (-33.8707524, 151.2710661),
 "Cranbrook School- St Mark's Pre-school": (-33.874815, 151.237039),
 "St Michael's Pre-school": (-33.8606396, 151.2705937),
 "KU Rushcutter's Bay": (-33.8743913, 151.2282235),
 'The Third Bear Preparatory School': (-33.8904917, 151.2499098),
 'Woollahra Preschool': (-33.8748835, 151.2464249),
 'KU Mosman Community Preschool': (-33.8285277, 151.2381812),
 'Neutral Bay Kindergarten': (-33.828413, 151.22516),
 'Uniting Forest Pre-school Belrose': (-33.722442, 151.218076),
 'St. Stephens Belrose Kindergarten': (-33.7395004, 151.2069525),
 'Mowbray Place Early Learning Centre': (-33.804337, 151.206634),
 'East Willoughby Pre-School': (-33.795411, 151.20528),
 'Glenaeon Rudolf Steiner Extended Hours Preschool': (-33.7979544, 151.194356),
 'Only About Children North Sydney': (-33.8372194, 151.207922),
 'Walker Street Early Learning Centre': (-33.8382862, 151.209288),
 'St Thomas North Sydney Preschool': (-33.8344583, 151.2063175),
 'St. Thomas Child Care Centre': (-33.8636297, 151.1704426),
 'KU Grandstand Preschool': (-33.83105, 151.209318),
 'KU Killarney Heights Preschool': (-33.774358, 151.21774),
 'UnitingCare Forestville Pre-school': (-33.762209, 151.213567),
 'Little Learning School': (-33.8241133, 151.1929545),
 'KU Chatswood West Preschool': (-33.804798, 151.174298),
 'KU Chatswood Community Preschool': (-33.799022, 151.182614),
 'Waterford Pre-School': (-33.9005268, 151.2572876),
 'Lalor Park Preschool': (-33.7614818, 150.9324933),
 'Little Learning School Wahroonga': (-33.7037043, 151.1113356),
 'MindChamps Early Learning Centre Hornsby': (-33.7016818, 151.0970007),
 'KU Grevillea Preschool': (-33.678009, 151.09859),
 'Balamara Preschool': (-33.7069397, 151.110719),
 'Asquith Norwood Community Pre-School': (-33.6894749, 151.1162831),
 'SDN Childrens Services': (-33.8278728, 151.2079994),
 'Uniting Shirley Road Pre-school Crows Nest': (-33.82819, 151.199679),
 'Willoughby Community Pre-School': (-33.816016, 151.201862),
 'Atchison Preschool': (-33.822832, 151.201836),
 'Crows Nest Kindergarten': (-33.8291954, 151.2046542),
 'KU Greenwich Community Preschool': (-33.8291447, 151.188385),
 'Possums Corner Child Care Centre': (-33.8034096, 151.147372),
 'KU Osborne Park Preschool': (-33.8228652, 151.1750205),
 'Birrahlee Preschool': (-33.815375, 151.167126),
 'Kidzville': (-33.9087455, 151.1523406),
 'KU Crusader Preschool': (-33.9079266, 151.156133),
 'Marrickville Rd Preschool': (-33.9087632, 151.1518914),
 'FROEBEL St Leonards Early Learning Centre': (-33.8248064, 151.1978633),
 'Berry Cottage Childcare': (-33.8182345, 151.1954088),
 'Concord West Rhodes Preschool': (-33.8350386, 151.0905241)}

In [18]:
m = folium.Map(location=[-33.87, 151.2], zoom_start=12, tiles='stamentoner') #'cartodbpositron')

# mark each preschool as a point
for key, val in ps.items():
    folium.CircleMarker(val,
                        radius=5,
                        tooltip=key.replace("'","´"),
                        fill_color="#3db7e4", # divvy color
                        ).add_to(m)

In [21]:
ps_array = np.array(list(ps.values()))
m.add_child(plugins.HeatMap(ps_array, radius=20))
m.save(outfile="sydney_ps.html")
#IFrame(src='sydney_ps.html', width=800, height=600)
m


Out[21]:

In [ ]:


In [ ]:


In [ ]:
state_geo = 'sydney.geojson'

state_unemployment = 'US_Unemployment_Oct2012.csv'
state_data = pd.read_csv(state_unemployment)

m = folium.Map(location=[-33.87, 151.2], zoom_start=12, tiles='cartodbpositron')

m.choropleth(
    geo_data=state_geo,
    name='choropleth',
    data=state_data,
    columns=['State', 'Unemployment'],
    key_on='feature.id',
    fill_color='YlGn',
    fill_opacity=0.7,
    line_opacity=0.2,
    legend_name='Unemployment Rate (%)'
)


folium.LayerControl().add_to(m)
m.save(outfile="sydney.html")

#https://github.com/qingkaikong/blog/blob/master/19_folium_map_3_heatmap/Folium-3%20heatmap.ipynb

In [ ]:
IFrame(src='sydney.html', width=500, height=600)

In [ ]: