{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Calculate Isochrones\n", "\n", "This example illustrates how to calculate and visualize isochrones using Data Services.\n", "\n", "_Note: You'll need [CARTO Account](https://carto.com/signup) credentials to reproduce this example._" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from cartoframes.auth import set_default_credentials\n", "\n", "set_default_credentials('creds.json')" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from geopandas import GeoDataFrame, points_from_xy\n", "\n", "gdf = GeoDataFrame([\n", " ['Calle Serrano 15', -3.68831, 40.42478],\n", " ['Calle de San Pedro 21', -3.69488, 40.41089],\n", " ['Calle Gran Vía 46', -3.70588, 40.42049],\n", " ['Paseo de la Castellana 200', -3.68898, 40.46239],\n", " ['Calle Ntra. Sra. del Carmen 7', -3.70221, 40.45840],\n", " ['Calle de San Germán 12', -3.69286, 40.45651],\n", " ['Calle de Bravo Murillo 377', -3.69093, 40.46575],\n", " ],\n", " columns=['address', 'lng', 'lat']\n", ")\n", "gdf.set_geometry(points_from_xy(gdf['lng'], gdf['lat']), inplace=True)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", " None\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "\n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", " Static map image\n", " \n", " \n", "
\n", "
\n", "
\n", " \n", " \n", "
\n", "
\n", "
\n", "\n", " \n", "\n", "
\n", "
\n", " :\n", "
\n", " \n", " \n", "
\n", "
\n", "\n", "
\n", " StackTrace\n", "
    \n", "
    \n", "
    \n", "\n", "\n", "\n", "\n", "\n", "\">\n", "\n", "" ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from cartoframes.viz import Layer\n", "\n", "Layer(gdf)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Success! Isolines created correctly\n" ] } ], "source": [ "from cartoframes.data.services import Isolines\n", "\n", "iso_service = Isolines()\n", "isochrones_gdf, isochrones_metadata = iso_service.isochrones(gdf, [100, 200, 300], mode='walk', exclusive=True)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
    \n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
    source_iddata_rangelower_data_rangethe_geomrange_label
    001000MULTIPOLYGON (((-3.68926 40.42557, -3.68797 40...2 min.
    10200100POLYGON ((-3.69012 40.42505, -3.69003 40.42557...3 min.
    20300200POLYGON ((-3.69063 40.42625, -3.69020 40.42643...5 min.
    311000MULTIPOLYGON (((-3.69544 40.41183, -3.69484 40...2 min.
    41200100POLYGON ((-3.69630 40.41063, -3.69621 40.41115...3 min.
    \n", "
    " ], "text/plain": [ " source_id data_range lower_data_range \\\n", "0 0 100 0 \n", "1 0 200 100 \n", "2 0 300 200 \n", "3 1 100 0 \n", "4 1 200 100 \n", "\n", " the_geom range_label \n", "0 MULTIPOLYGON (((-3.68926 40.42557, -3.68797 40... 2 min. \n", "1 POLYGON ((-3.69012 40.42505, -3.69003 40.42557... 3 min. \n", "2 POLYGON ((-3.69063 40.42625, -3.69020 40.42643... 5 min. \n", "3 MULTIPOLYGON (((-3.69544 40.41183, -3.69484 40... 2 min. \n", "4 POLYGON ((-3.69630 40.41063, -3.69621 40.41115... 3 min. " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "isochrones_gdf.head(5)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'required_quota': 21}" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "isochrones_metadata" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", " None\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "\n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", " Static map image\n", " \n", " \n", "
    \n", "
    \n", "
    \n", " \n", " \n", "
    \n", "
    \n", "
    \n", "\n", " \n", "\n", "
    \n", "
    \n", " :\n", "
    \n", " \n", " \n", "
    \n", "
    \n", "\n", "
    \n", " StackTrace\n", "
      \n", "
      \n", "
      \n", "\n", "\n", "\n", "\n", "\n", "\">\n", "\n", "" ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from cartoframes.viz import Map, Layer, basic_style\n", "\n", "Map([\n", " Layer(isochrones_gdf, basic_style(color='green', opacity='0.3')),\n", " Layer(gdf, basic_style(size=3))\n", "])" ] } ], "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.6.7" } }, "nbformat": 4, "nbformat_minor": 2 }