{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.3.0.dev\n" ] } ], "source": [ "import os\n", "import folium\n", "\n", "print(folium.__version__)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Illustration of CRS effect\n", "\n", "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.\n", "\n", "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.\n", "\n", "Let's create a GeoJSON map, and change it's CRS." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import json\n", "\n", "us_states = os.path.join('data', 'us-states.json')\n", "\n", "geo_json_data = json.load(open(us_states))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## EPSG3857 ; the standard\n", "\n", "Provided that our tiles are computed with this projection, this map has the expected behavior." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "kw = dict(tiles=None, location=[43, -100], zoom_start=3)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m = folium.Map(crs='EPSG3857', **kw)\n", "\n", "folium.GeoJson(geo_json_data).add_to(m)\n", "\n", "m.save(os.path.join('results', 'CRS_0.html'))\n", "\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## EPSG4326\n", "\n", "This projection is a *common CRS among GIS enthusiasts* according to Leaflet's documentation. And we see it's quite different." ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m = folium.Map(crs='EPSG4326', **kw)\n", "\n", "folium.GeoJson(geo_json_data).add_to(m)\n", "\n", "m.save(os.path.join('results', 'CRS_1.html'))\n", "\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## EPSG3395\n", "\n", "The elliptical projection is almost equal to EPSG3857 ; though different." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m = folium.Map(crs='EPSG3395', **kw)\n", "\n", "folium.GeoJson(geo_json_data).add_to(m)\n", "\n", "m.save(os.path.join('results', 'CRS_2.html'))\n", "\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Simple\n", "\n", "At last, Leaflet also give the possibility to use no projection at all. With this, you get flat charts.\n", "\n", "It can be useful if you want to use folium to draw non-geographical data." ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m = folium.Map(crs='Simple', **kw)\n", "\n", "folium.GeoJson(geo_json_data).add_to(m)\n", "\n", "m.save(os.path.join('results', 'CRS_3.html'))\n", "\n", "m" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.2" } }, "nbformat": 4, "nbformat_minor": 0 }