import os
import folium
print(folium.__version__)
0.3.0.dev
import numpy as np
def get_coordinates(bbox):
"""
Create bounding box coordinates for the map. It takes flat or
nested list/numpy.array and returns 5 points that closes square
around the borders.
Examples
--------
>>> bbox = [-87.40, 24.25, -74.70, 36.70]
>>> len(get_coordinates(bbox))
5
"""
bbox = np.asanyarray(bbox).ravel()
if bbox.size == 4:
bbox = bbox.reshape(2, 2)
coordinates = []
coordinates.append([bbox[0][1], bbox[0][0]])
coordinates.append([bbox[0][1], bbox[1][0]])
coordinates.append([bbox[1][1], bbox[1][0]])
coordinates.append([bbox[1][1], bbox[0][0]])
coordinates.append([bbox[0][1], bbox[0][0]])
else:
raise ValueError('Wrong number corners.'
' Expected 4 got {}'.format(bbox.size))
return coordinates
lon = lat = 0
zoom_start = 1
m = folium.Map(location=[lat, lon], zoom_start=zoom_start)
kw = dict(opacity=1.0, weight=4)
# Wrong.
l0 = folium.PolyLine(locations=[(2, 179), (2, -179)], color='red', **kw)
# Correct.
l1 = folium.PolyLine(locations=[(-2, 179), (-2, 181)], color='blue', **kw)
# Correct.
l2 = folium.PolyLine(locations=[(-6, -179), (-6, 179)], color='green', **kw)
# Artifact?
l3 = folium.PolyLine(locations=[(12, -179), (12, 190)], color='orange', **kw)
for l in [l0, l1, l2, l3]:
m.add_child(l)
m.save(os.path.join('results', 'DateLineExample.html'))
m