{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Illustration of CRS effect" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "../folium/__init__.py\n", "0.2.0.dev\n" ] } ], "source": [ "import json\n", "import sys\n", "sys.path.insert(0,'..')\n", "import folium\n", "print (folium.__file__)\n", "print (folium.__version__)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's create a GeoJSON map, and change it's CRS." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "geo_json_data = json.load(open('us-states.json'))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## EPSG3857 ; the standard" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Provided that our tiles are computed with this projection, this map has the expected behavior." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", " \n", "
" ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m = folium.Map([43,-100], zoom_start=4, crs='EPSG3857')\n", "\n", "folium.GeoJson(geo_json_data).add_to(m)\n", "\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## EPSG4326" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", " \n", "
" ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m = folium.Map([43,-100], zoom_start=4, crs='EPSG4326')\n", "\n", "folium.GeoJson(geo_json_data).add_to(m)\n", "\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## EPSG3395" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The elliptical projection is almost equal to EPSG3857 ; though different." ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", " \n", "
" ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m = folium.Map([43,-100], zoom_start=4, crs='EPSG3395')\n", "\n", "folium.GeoJson(geo_json_data).add_to(m)\n", "\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Simple" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", " \n", "
" ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m = folium.Map([43,-100], zoom_start=4, crs='Simple')\n", "\n", "folium.GeoJson(geo_json_data).add_to(m)\n", "\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "That's all folks !\n", "\n", "Hope it'll be useful to you. Don't hesitate to provide a feedback on what can be improved, which method do you prefer, etc." ] } ], "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.4.3" } }, "nbformat": 4, "nbformat_minor": 0 }