In [1]:
import os
import folium
print(folium.__version__)
Leaflet is able to handle several CRS (coordinate reference systems). It means that depending on the data you have, you may need to use the one or the other.
Don't worry ; in practice, almost everyone on the web uses EPSG3857 (the default value for folium and Leaflet). But it may be interesting to know the possible values.
Let's create a GeoJSON map, and change it's CRS.
In [2]:
import json
us_states = os.path.join('data', 'us-states.json')
geo_json_data = json.load(open(us_states))
In [3]:
kw = dict(tiles=None, location=[43, -100], zoom_start=3)
In [4]:
m = folium.Map(crs='EPSG3857', **kw)
folium.GeoJson(geo_json_data).add_to(m)
m.save(os.path.join('results', 'CRS_0.html'))
m
Out[4]:
In [5]:
m = folium.Map(crs='EPSG4326', **kw)
folium.GeoJson(geo_json_data).add_to(m)
m.save(os.path.join('results', 'CRS_1.html'))
m
Out[5]:
In [6]:
m = folium.Map(crs='EPSG3395', **kw)
folium.GeoJson(geo_json_data).add_to(m)
m.save(os.path.join('results', 'CRS_2.html'))
m
Out[6]:
In [7]:
m = folium.Map(crs='Simple', **kw)
folium.GeoJson(geo_json_data).add_to(m)
m.save(os.path.join('results', 'CRS_3.html'))
m
Out[7]: