In [1]:
import os
import folium

print(folium.__version__)


0.3.0.dev

Illustration of CRS effect

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))

EPSG3857 ; the standard

Provided that our tiles are computed with this projection, this map has the expected behavior.


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]:

EPSG4326

This projection is a common CRS among GIS enthusiasts according to Leaflet's documentation. And we see it's quite different.


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]:

EPSG3395

The elliptical projection is almost equal to EPSG3857 ; though different.


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]:

Simple

At last, Leaflet also give the possibility to use no projection at all. With this, you get flat charts.

It can be useful if you want to use folium to draw non-geographical data.


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]: