Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
0.4.0
~~~~~
- Optional `iconCreateFunction` for `MarkerCluster` to customize the icons (odovad #701)
- Added `HeatMapWithTime` (Padarn #567)
- Added `MeasureControl` (ocefpaf #669)
- Added `VideoOverlay` plugin (ocefpaf #665)
Expand All @@ -14,6 +15,9 @@

API changes

- `choropleth` now takes a single `geo_data` instad of `geo_path`/`geo_str`
leaving the parsing to `GeoJSON`, remove the unused `data_out` option,
add geopandas support (ocefpaf #702)
- All popups are considered HTML text by default (ocefpaf #689)
If a popup requires rendering use the `kwarg` `parse_html=True`.
- `PolyLine`, `Circle` and `CircleMarker` are set to leaflet's defaults and
Expand Down
8 changes: 4 additions & 4 deletions examples/CheckZorder.ipynb

Large diffs are not rendered by default.

198 changes: 108 additions & 90 deletions examples/GeoJSON_and_choropleth.ipynb

Large diffs are not rendered by default.

80 changes: 40 additions & 40 deletions examples/Quickstart.ipynb

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions folium/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

from jinja2 import Template

import requests

from six import binary_type, text_type


Expand Down Expand Up @@ -466,19 +468,18 @@ def __init__(self, data, style_function=None, name=None,
super(GeoJson, self).__init__(name=name, overlay=overlay,
control=control)
self._name = 'GeoJson'
if hasattr(data, 'read'):
self.embed = True
self.data = json.load(data)
elif isinstance(data, dict):
if isinstance(data, dict):
self.embed = True
self.data = data
elif isinstance(data, text_type) or isinstance(data, binary_type):
if data.lstrip()[0] in '[{': # This is a GeoJSON inline string
self.embed = True
self.embed = True
if data.lower().startswith(('http:', 'ftp:', 'https:')):
self.data = requests.get(data).json()
elif data.lstrip()[0] in '[{': # This is a GeoJSON inline string
self.data = json.loads(data)
else: # This is a filename
self.embed = False
self.data = data
with open(data) as f:
self.data = json.loads(f.read())
elif data.__class__.__name__ in ['GeoDataFrame', 'GeoSeries']:
self.embed = True
if hasattr(data, '__geo_interface__'):
Expand Down
30 changes: 6 additions & 24 deletions folium/folium.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
from folium.features import GeoJson, TopoJson
from folium.map import FitBounds, LegacyMap

import requests


class Map(LegacyMap):
"""Create a Map with Folium and Leaflet.js
Expand Down Expand Up @@ -143,11 +141,10 @@ def fit_bounds(self, bounds, padding_top_left=None,
)
)

def choropleth(self, geo_path=None, geo_str=None, data_out='data.json',
data=None, columns=None, key_on=None, threshold_scale=None,
fill_color='blue', fill_opacity=0.6, line_color='black',
line_weight=1, line_opacity=1, legend_name='',
topojson=None, reset=False, smooth_factor=None,
def choropleth(self, geo_data, data=None, columns=None, key_on=None,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C901 'Map.choropleth' is too complex (17)

threshold_scale=None, fill_color='blue', fill_opacity=0.6,
line_color='black', line_weight=1, line_opacity=1,
legend_name='', topojson=None, reset=False, smooth_factor=None,
highlight=None):
"""
Apply a GeoJSON overlay to the map.
Expand Down Expand Up @@ -177,12 +174,8 @@ def choropleth(self, geo_path=None, geo_str=None, data_out='data.json',

Parameters
----------
geo_path: string, default None
URL or File path to your GeoJSON data
geo_str: string, default None
String of GeoJSON, alternative to geo_path
data_out: string, default 'data.json'
Path to write Pandas DataFrame/Series to JSON if binding data
geo_path: string/object
URL, file path, or data (json, dict, geopandas, etc) to your GeoJSON geometries
data: Pandas DataFrame or Series, default None
Data to bind to the GeoJSON.
columns: dict or tuple, default None
Expand Down Expand Up @@ -252,17 +245,6 @@ def choropleth(self, geo_path=None, geo_str=None, data_out='data.json',
raise ValueError('Please pass a valid color brewer code to '
'fill_local. See docstring for valid codes.')

# Create GeoJson object
if geo_path:
if geo_path.lower().startswith(('http:', 'ftp:', 'https:')):
geo_data = requests.get(geo_path).json()
else:
geo_data = open(geo_path)
elif geo_str:
geo_data = geo_str
else:
geo_data = {}

# Create color_data dict
if hasattr(data, 'set_index'):
# This is a pd.DataFrame
Expand Down
9 changes: 3 additions & 6 deletions tests/test_folium.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,8 @@ def test_topo_json_smooth_factor(self):
self.m = folium.Map([43, -100], zoom_start=4)

# Adding TopoJSON as additional layer.
path = os.path.join(rootpath, 'or_counties_topo.json')
self.m.choropleth(geo_path=path,
topojson='objects.or_counties_geo',
smooth_factor=0.5)
with open(os.path.join(rootpath, 'or_counties_topo.json')) as f:
self.m.choropleth(f, topojson='objects.or_counties_geo', smooth_factor=0.5)

out = self.m._parent.render()

Expand Down Expand Up @@ -462,8 +460,7 @@ def test_json_request(self):
self.m = folium.Map(zoom_start=4)

# Adding remote GeoJSON as additional layer.
self.m.choropleth(geo_path=remote_url,
smooth_factor=0.5)
self.m.choropleth(remote_url, smooth_factor=0.5)

self.m._parent.render()
bounds = self.m.get_bounds()
Expand Down