{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Publish a visualization from a GeoDataFrame\n", "\n", "This example illustrate how to publish a visualization using a GeoDataFrame.\n", "\n", "Read more about Maps API Keys: https://carto.com/developers/auth-api/guides/types-of-API-Keys/\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 read_file\n", "\n", "gdf = read_file('http://libs.cartocdn.com/cartoframes/files/sustainable_palm_oil_production_mills.geojson')" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "from cartoframes.viz import Map, Layer\n", "\n", "map_viz = Map(Layer(gdf))" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'id': 'e1ee8600-de8d-48a0-b650-16d050507963',\n", " 'url': 'https://cartoframes-org.carto.com/u/cartoframes/kuviz/e1ee8600-de8d-48a0-b650-16d050507963',\n", " 'name': 'map_gdf',\n", " 'privacy': 'password'}" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "map_viz.publish(\n", " name='map_gdf',\n", " password='1234',\n", " if_exists='replace')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Recommendation\n", "\n", "The performance of visualizations can be affected by using large GeoDataFrames. There is also a size limit of 10MB per visualization published. Our recommendation in these cases is to upload the data to a table in CARTO, and use the table as the source in the Layer." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Success! Data uploaded to table \"table_name\" correctly\n" ] }, { "data": { "text/plain": [ "'table_name'" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from cartoframes import to_carto\n", "\n", "to_carto(gdf, 'table_name', if_exists='replace')" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "map_viz = Map(Layer('table_name'))" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "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.\n" ] }, { "data": { "text/plain": [ "{'id': 'd92b9d44-f292-4bdd-8715-56368d8e57ee',\n", " 'url': 'https://cartoframes-org.carto.com/u/cartoframes/kuviz/d92b9d44-f292-4bdd-8715-56368d8e57ee',\n", " 'name': 'map_table',\n", " 'privacy': 'password'}" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "map_viz.publish(\n", " name='map_table',\n", " password='1234',\n", " if_exists='replace')" ] } ], "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 }