This example illustrates how to calculate and visualize isodistances using Data Services.
Note: You'll need CARTO Account credentials to reproduce this example.
from cartoframes.auth import set_default_credentials
set_default_credentials('creds.json')
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)
from cartoframes.viz import Layer
Layer(gdf)
from cartoframes.data.services import Isolines
iso_service = Isolines()
isodistances_gdf, isodistances_metadata = iso_service.isodistances(gdf, [600, 1200, 2400], exclusive=True)
Success! Isolines created correctly
isodistances_gdf.head(5)
source_id | data_range | lower_data_range | the_geom | range_label | |
---|---|---|---|---|---|
0 | 0 | 600 | 0 | MULTIPOLYGON (((-3.69149 40.42368, -3.69123 40... | 10 min. |
1 | 0 | 1200 | 600 | POLYGON ((-3.69750 40.42694, -3.69690 40.42694... | 20 min. |
2 | 0 | 2400 | 1200 | POLYGON ((-3.70917 40.43037, -3.70651 40.43037... | 40 min. |
3 | 1 | 600 | 0 | MULTIPOLYGON (((-3.69973 40.41338, -3.69947 40... | 10 min. |
4 | 1 | 1200 | 600 | MULTIPOLYGON (((-3.70660 40.41578, -3.70634 40... | 20 min. |
isodistances_metadata
{'required_quota': 21}
from cartoframes.viz import Map, Layer, basic_style
Map([
Layer(isodistances_gdf, basic_style(color='green', opacity='0.3', stroke_width=0)),
Layer(gdf)
])