Publish a visualization from a GeoDataFrame

This example illustrate how to publish a visualization using a GeoDataFrame.

Read more about Maps API Keys: https://carto.com/developers/auth-api/guides/types-of-API-Keys/

Note: CARTO Account credentials are needed to reproduce this example. https://carto.com/signup


In [1]:
from cartoframes.auth import set_default_credentials

set_default_credentials('creds.json')

In [2]:
from geopandas import read_file

gdf = read_file('http://libs.cartocdn.com/cartoframes/files/sustainable_palm_oil_production_mills.geojson')

In [3]:
from cartoframes.viz import Map, Layer

map_viz = Map(Layer(gdf))

In [4]:
map_viz.publish(
    name='map_gdf',
    password='1234',
    if_exists='replace')


Out[4]:
{'id': 'e1ee8600-de8d-48a0-b650-16d050507963',
 'url': 'https://cartoframes-org.carto.com/u/cartoframes/kuviz/e1ee8600-de8d-48a0-b650-16d050507963',
 'name': 'map_gdf',
 'privacy': 'password'}

Recomendation

The performance of visualizations can be affected by using large GeoDataFrames. There is also a size limit of 10MB per visualization published. Our recomentation in these cases is to upload the data to a table in CARTO, and use the table as the source in the Layer.


In [5]:
from cartoframes import to_carto

to_carto(gdf, 'table_name', if_exists='replace')


Success! Data uploaded to table "table_name" correctly
Out[5]:
'table_name'

In [6]:
map_viz = Map(Layer('table_name'))

In [7]:
map_viz.publish(
    name='map_table',
    password='1234',
    if_exists='replace')


The map has been published. The "cartoframes_0a8a065b2cc026c5c33ee3dc269afcf1" Maps API key with value "YTAEiju-Utii8mgtERiEkA" is being used for the datasets: "table_name". You can manage your API keys on your account.
Out[7]:
{'id': 'd92b9d44-f292-4bdd-8715-56368d8e57ee',
 'url': 'https://cartoframes-org.carto.com/u/cartoframes/kuviz/d92b9d44-f292-4bdd-8715-56368d8e57ee',
 'name': 'map_table',
 'privacy': 'password'}