{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Calculate Isodistances\n", "\n", "This example illustrates how to calculate and visualize isodistances 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", "isodistances_gdf, isodistances_metadata = iso_service.isodistances(gdf, [600, 1200, 2400], 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
    006000MULTIPOLYGON (((-3.69149 40.42368, -3.69123 40...10 min.
    101200600POLYGON ((-3.69750 40.42694, -3.69690 40.42694...20 min.
    2024001200POLYGON ((-3.70917 40.43037, -3.70651 40.43037...40 min.
    316000MULTIPOLYGON (((-3.69973 40.41338, -3.69947 40...10 min.
    411200600MULTIPOLYGON (((-3.70660 40.41578, -3.70634 40...20 min.
    \n", "
    " ], "text/plain": [ " source_id data_range lower_data_range \\\n", "0 0 600 0 \n", "1 0 1200 600 \n", "2 0 2400 1200 \n", "3 1 600 0 \n", "4 1 1200 600 \n", "\n", " the_geom range_label \n", "0 MULTIPOLYGON (((-3.69149 40.42368, -3.69123 40... 10 min. \n", "1 POLYGON ((-3.69750 40.42694, -3.69690 40.42694... 20 min. \n", "2 POLYGON ((-3.70917 40.43037, -3.70651 40.43037... 40 min. \n", "3 MULTIPOLYGON (((-3.69973 40.41338, -3.69947 40... 10 min. \n", "4 MULTIPOLYGON (((-3.70660 40.41578, -3.70634 40... 20 min. " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "isodistances_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": [ "isodistances_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(isodistances_gdf, basic_style(color='green', opacity='0.3', stroke_width=0)),\n", " Layer(gdf)\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 }