In [1]:
import folium
import pandas as pd
import psycopg2

In [2]:
# import road database with crime
dbname = 'routing_db_crime'
username = 'nishan'
password = 'vikaspuri'
con = psycopg2.connect(database=dbname, user=username, password=password)

In [2]:
folium.PolyLine?

In [3]:
query = """
        SELECT osm_id,the_geom,cost_crime0 FROM ways LIMIT 50;
        """
df = pd.read_sql(query, con)

In [4]:
# df['osm_id'] = df['osm_id'].astype(float)

In [5]:
df.osm_id


Out[5]:
0       5674297
1     440891792
2     440947098
3     420878087
4     441041240
5      46890025
6     440891792
7     414893144
8     440887372
9     440887370
10    206610786
11    276061809
12    440887361
13      5699134
14      5707384
15      5704942
16      5717475
17    441393113
18    441393113
19      5710410
20      5710726
21    440891793
22    441041240
23    441919507
24    441405436
25    196117090
26    441919507
27    441919507
28      5709734
29      5707511
30      5707487
31    353231143
32    441393113
33      5701051
34    359253980
35      5713499
36    353228325
37      5699664
38    356123689
39    195743147
40      5717040
41    441904430
42    353220115
43     22897633
44    441919507
45    441637777
46    359184734
47     11583504
48     25346304
49    361086503
Name: osm_id, dtype: int64

In [12]:
df[df['osm_id'] == 5029221]


Out[12]:
osm_id the_geom cost_crime0

In [2]:
# Insight's office
# map_mapbox = folium.Map(location=[40.7438973, -73.9909419], tiles='https://api.mapbox.com/styles/v1/mapbox/streets-v9/tiles/256/{z}/{x}/{y}?access_token=pk.eyJ1IjoibmFoc2luIiwiYSI6ImNpdDdwdDV0bzA5dHkyeW13ZTh4enl0c3MifQ.iOW2JTxp_HkABm9wuTuPqA', attr='My Data Attribution', zoom_start=13)
map0 = folium.Map(location=[40.7438973, -73.9909419],)

In [8]:
# folium.Marker([40.7438973, -73.9909419], popup='Insight\'s Office').add_to(map_osm)fol
folium.

In [ ]:
#map0.save('test.html')

In [ ]:
map0.choropleth?

In [9]:
f_geojson = r'data/new-york_new-york.imposm-geojson/new-york_new-york_roads.geojson'

In [13]:
# map0.choropleth(geo_path=f_geojson, data=df, columns=['osm_id', 'cost_crime0'], key_on='feature.properties.osm_id', fill_color='BuGn')
map0.choropleth(geo_path=f_geojson, line_color='blue', line_weight=3)

In [14]:
map0


---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/home/nishan/.local/lib/python3.5/site-packages/IPython/core/formatters.py in __call__(self, obj)
    309             method = get_real_method(obj, self.print_method)
    310             if method is not None:
--> 311                 return method()
    312             return None
    313         else:

/home/nishan/.local/lib/python3.5/site-packages/folium/map.py in _repr_html_(self, **kwargs)
    177             self._parent = None
    178         else:
--> 179             out = self._parent._repr_html_(**kwargs)
    180         return out
    181 

/home/nishan/.local/lib/python3.5/site-packages/folium/element.py in _repr_html_(self, **kwargs)
    367 
    368         """
--> 369         html = self.render(**kwargs)
    370         html = "data:text/html;base64," + base64.b64encode(html.encode('utf8')).decode('utf8')  # noqa
    371 

/home/nishan/.local/lib/python3.5/site-packages/folium/element.py in render(self, **kwargs)
    357         """Renders the HTML representation of the element."""
    358         for name, child in self._children.items():
--> 359             child.render(**kwargs)
    360         return self._template.render(this=self, kwargs=kwargs)
    361 

/home/nishan/.local/lib/python3.5/site-packages/folium/element.py in render(self, **kwargs)
    665 
    666         for name, element in self._children.items():
--> 667             element.render(**kwargs)

/home/nishan/.local/lib/python3.5/site-packages/folium/element.py in render(self, **kwargs)
    661         script = self._template.module.__dict__.get('script', None)
    662         if script is not None:
--> 663             figure.script.add_children(Element(script(self, kwargs)),
    664                                        name=self.get_name())
    665 

/home/nishan/.local/lib/python3.5/site-packages/jinja2/runtime.py in __call__(self, *args, **kwargs)
    434             raise TypeError('macro %r takes not more than %d argument(s)' %
    435                             (self.name, len(self.arguments)))
--> 436         return self._func(*arguments)
    437 
    438     def __repr__(self):

<template> in macro(l_this, l_kwargs)

/home/nishan/.local/lib/python3.5/site-packages/jinja2/runtime.py in call(_Context__self, _Context__obj, *args, **kwargs)
    194                 args = (__self.environment,) + args
    195         try:
--> 196             return __obj(*args, **kwargs)
    197         except StopIteration:
    198             return __self.environment.undefined('value was undefined because '

/home/nishan/.local/lib/python3.5/site-packages/folium/features.py in style_data(self)
    352 
    353         for feature in self.data['features']:
--> 354             feature.setdefault('properties', {}).setdefault('style', {}).update(self.style_function(feature))  # noqa
    355         return json.dumps(self.data, sort_keys=True)
    356 

/home/nishan/.local/lib/python3.5/site-packages/folium/folium.py in style_function(x)
    671                 "color": line_color,
    672                 "fillOpacity": fill_opacity,
--> 673                 "fillColor": color_scale_fun(x)
    674             }
    675 

/home/nishan/.local/lib/python3.5/site-packages/folium/folium.py in color_scale_fun(x)
    659             def color_scale_fun(x):
    660                 return color_range[len(
--> 661                     [u for u in color_domain if
    662                      u <= color_data[get_by_key(x, key_on)]])]
    663         else:

/home/nishan/.local/lib/python3.5/site-packages/folium/folium.py in <listcomp>(.0)
    660                 return color_range[len(
    661                     [u for u in color_domain if
--> 662                      u <= color_data[get_by_key(x, key_on)]])]
    663         else:
    664             def color_scale_fun(x):

KeyError: 5029221.0
Out[14]:
<folium.folium.Map at 0x7fe631ab3c88>

In [ ]:


In [ ]: