Calculate Isochrones

This example illustrates how to calculate and visualize isochrones using Location Data Services.

Note: You'll need CARTO Account credentials to reproduce this example.


In [1]:
from cartoframes.auth import set_default_credentials

set_default_credentials('creds.json')

In [2]:
from geopandas import GeoDataFrame, points_from_xy

gdf = GeoDataFrame([
         ['Calle Serrano 15', -3.68831, 40.42478],
         ['Calle de San Pedro 21', -3.69488, 40.41089],
         ['Calle Gran Vía 46', -3.70588, 40.42049],
         ['Paseo de la Castellana 200', -3.68898, 40.46239],
         ['Calle Ntra. Sra. del Carmen 7', -3.70221, 40.45840],
         ['Calle de San Germán 12', -3.69286, 40.45651],
         ['Calle de Bravo Murillo 377', -3.69093, 40.46575],
    ],
    columns=['address', 'lng', 'lat']
)
gdf.set_geometry(points_from_xy(gdf['lng'], gdf['lat']), inplace=True)

In [3]:
from cartoframes.viz import Layer

Layer(gdf)


Out[3]:
:
StackTrace
    ">
    
    
    In [4]:
    from cartoframes.data.services import Isolines
    
    iso_service = Isolines()
    isochrones_gdf, isochrones_metadata = iso_service.isochrones(gdf, [100, 200, 300], mode='walk', exclusive=True)
    
    
    
    
    Success! Isolines created correctly
    
    
    
    In [5]:
    isochrones_gdf.head(5)
    
    
    
    
    Out[5]:
    source_id data_range lower_data_range the_geom range_label
    0 6 300 200 POLYGON ((-3.69355 40.46556, -3.69347 40.46608... 5 min.
    1 3 300 200 POLYGON ((-3.69201 40.46265, -3.69072 40.46265... 5 min.
    2 0 300 200 POLYGON ((-3.69063 40.42625, -3.69020 40.42643... 5 min.
    3 5 300 200 MULTIPOLYGON (((-3.69544 40.45715, -3.69518 40... 5 min.
    4 1 300 200 POLYGON ((-3.69681 40.41183, -3.69638 40.41201... 5 min.
    
    
    In [6]:
    isochrones_metadata
    
    
    
    
    Out[6]:
    {'required_quota': 21}
    
    
    In [9]:
    from cartoframes.viz import Map, Layer, basic_style
    
    Map([
        Layer(isochrones_gdf, basic_style(color='green', opacity='0.3')),
        Layer(gdf, basic_style(size=3))
    ])
    
    
    
    
    Out[9]:
    :
    StackTrace
      ">