Skip to content

Commit 6cfe327

Browse files
committed
updates in carto to mapbox migration notebook
1 parent 5082b4f commit 6cfe327

File tree

1 file changed

+295
-0
lines changed

1 file changed

+295
-0
lines changed

ResourceWatch/data_management/migration/Cartocss_mapbox_migration.ipynb

Lines changed: 295 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@
2525
"More info can be found on the ````cartocssParser-VLSCompiler notebook````."
2626
]
2727
},
28+
{
29+
"cell_type": "code",
30+
"execution_count": 932,
31+
"metadata": {},
32+
"outputs": [],
33+
"source": []
34+
},
2835
{
2936
"cell_type": "code",
3037
"execution_count": 563,
@@ -7698,6 +7705,294 @@
76987705
"source": [
76997706
"len(failed)"
77007707
]
7708+
},
7709+
{
7710+
"cell_type": "markdown",
7711+
"metadata": {},
7712+
"source": [
7713+
"# QA on updated layers:"
7714+
]
7715+
},
7716+
{
7717+
"cell_type": "code",
7718+
"execution_count": null,
7719+
"metadata": {},
7720+
"outputs": [],
7721+
"source": []
7722+
},
7723+
{
7724+
"cell_type": "code",
7725+
"execution_count": 1083,
7726+
"metadata": {},
7727+
"outputs": [
7728+
{
7729+
"data": {
7730+
"text/html": [
7731+
"<div class='item_container' style='height: auto; overflow: hidden; border: 1px solid #2BA4A0;border-radius: 2px; background: #2BA4A0; line-height: 1.21429em; padding: 10px;''><div class='item_left' style='width: 210px; float: left;''><a href='https://resourcewatch.org/' target='_blank'><img class='itemThumbnail' src='https://resourcewatch.org/static/images/logo-embed.png'></a></div><div class='item_right' style='float: none; width: auto; hidden;padding-left: 10px; overflow: hidden;''><a href=https://api.resourcewatch.org/v1/layer/cfb9e2f8-e34d-41e8-b7f9-bcb1d9201919?includes=vocabulary,metadata target='_blank'><b>2014 Global Conflict Risk Index—Food Insecurity</b></a><br> Data source cartodb | Layer in RW.<br>Last Modified: 2020-02-14T08:38:46.197Z<br><a href='https://api.resourcewatch.org/v1/fields/cfb9e2f8-e34d-41e8-b7f9-bcb1d9201919' target='_blank'>Fields</a> Connector: cartodb | Published: True </div> </div>"
7732+
],
7733+
"text/plain": [
7734+
"Layer cfb9e2f8-e34d-41e8-b7f9-bcb1d9201919 2014 Global Conflict Risk Index—Food Insecurity"
7735+
]
7736+
},
7737+
"execution_count": 1083,
7738+
"metadata": {},
7739+
"output_type": "execute_result"
7740+
}
7741+
],
7742+
"source": [
7743+
"layer = lmi.Layer('cfb9e2f8-e34d-41e8-b7f9-bcb1d9201919')\n",
7744+
"layer"
7745+
]
7746+
},
7747+
{
7748+
"cell_type": "code",
7749+
"execution_count": 1084,
7750+
"metadata": {},
7751+
"outputs": [
7752+
{
7753+
"data": {
7754+
"text/plain": [
7755+
"{'account': 'wri-rw',\n",
7756+
" 'body': {'maxzoom': 18,\n",
7757+
" 'minzoom': 3,\n",
7758+
" 'layers': [{'type': 'mapnik',\n",
7759+
" 'options': {'sql': 'SELECT wri.cartodb_id, wri.the_geom_webmercator, data.rw_country_name, data.food FROM soc_055_global_conflict_risk_index data LEFT OUTER JOIN wri_countries_a wri ON wri.iso_a3=data.rw_country_code WHERE year=2014 AND data.food IS NOT NULL',\n",
7760+
" 'cartocss': '#soc_055_global_conflict_risk_index {polygon-opacity:1; line-width:0.3; line-color:#adadad; line-opacity:1;} [food>=8]{polygon-fill:#0868ac;} [food>=6][food<8]{polygon-fill:#43a2ca;} [food>=4][food<6]{polygon-fill:#7bccc4;} [food>=2][food<4]{polygon-fill:#bae4bc;} [food<2]{polygon-fill:#f0f9e8;}',\n",
7761+
" 'cartocss_version': '2.3.0'}}],\n",
7762+
" 'vectorLayers': [{'paint': {'line-width': 0.3,\n",
7763+
" 'line-color': '#adadad',\n",
7764+
" 'line-opacity': 1},\n",
7765+
" 'source-layer': 'layer0',\n",
7766+
" 'type': 'line',\n",
7767+
" 'filter': ['all']},\n",
7768+
" {'paint': {'fill-opacity': 1},\n",
7769+
" 'source-layer': 'layer0',\n",
7770+
" 'type': 'fill',\n",
7771+
" 'filter': ['all']},\n",
7772+
" {'paint': {'fill-color': '#0868ac'},\n",
7773+
" 'source-layer': 'layer0',\n",
7774+
" 'type': 'fill',\n",
7775+
" 'filter': ['all', ['>=', 'food', 8]]},\n",
7776+
" {'paint': {'fill-color': '#43a2ca'},\n",
7777+
" 'source-layer': 'layer0',\n",
7778+
" 'type': 'fill',\n",
7779+
" 'filter': ['all', ['>=', 'food', 6], ['<', 'food', 8]]},\n",
7780+
" {'paint': {'fill-color': '#7bccc4'},\n",
7781+
" 'source-layer': 'layer0',\n",
7782+
" 'type': 'fill',\n",
7783+
" 'filter': ['all', ['>=', 'food', 4], ['<', 'food', 6]]},\n",
7784+
" {'paint': {'fill-color': '#bae4bc'},\n",
7785+
" 'source-layer': 'layer0',\n",
7786+
" 'type': 'fill',\n",
7787+
" 'filter': ['all', ['>=', 'food', 2], ['<', 'food', 4]]},\n",
7788+
" {'paint': {'fill-color': '#f0f9e8'},\n",
7789+
" 'source-layer': 'layer0',\n",
7790+
" 'type': 'fill',\n",
7791+
" 'filter': ['all', ['<', 'food', 2]]}]},\n",
7792+
" 'layerType': 'vector'}"
7793+
]
7794+
},
7795+
"execution_count": 1084,
7796+
"metadata": {},
7797+
"output_type": "execute_result"
7798+
}
7799+
],
7800+
"source": [
7801+
"layer.attributes['layerConfig']"
7802+
]
7803+
},
7804+
{
7805+
"cell_type": "code",
7806+
"execution_count": 1089,
7807+
"metadata": {},
7808+
"outputs": [],
7809+
"source": [
7810+
"payload = {\n",
7811+
" 'layerConfig':{'account': 'wri-rw',\n",
7812+
" 'body': {'maxzoom': 18,\n",
7813+
" 'minzoom': 3,\n",
7814+
" 'layers': [{'type': 'mapnik',\n",
7815+
" 'options': {'sql': 'SELECT wri.cartodb_id, wri.the_geom_webmercator, data.rw_country_name, data.food FROM soc_055_global_conflict_risk_index data LEFT OUTER JOIN wri_countries_a wri ON wri.iso_a3=data.rw_country_code WHERE year=2014 AND data.food IS NOT NULL',\n",
7816+
" 'cartocss': '#soc_055_global_conflict_risk_index {polygon-opacity:1; line-width:0.3; line-color:#adadad; line-opacity:1;} [food>=8]{polygon-fill:#0868ac;} [food>=6][food<8]{polygon-fill:#43a2ca;} [food>=4][food<6]{polygon-fill:#7bccc4;} [food>=2][food<4]{polygon-fill:#bae4bc;} [food<2]{polygon-fill:#f0f9e8;}',\n",
7817+
" 'cartocss_version': '2.3.0'}}],\n",
7818+
" 'vectorLayers': [{'paint': {'line-width': 0.3,\n",
7819+
" 'line-color': '#adadad',\n",
7820+
" 'line-opacity': 1},\n",
7821+
" 'source-layer': 'layer0',\n",
7822+
" 'type': 'line',\n",
7823+
" 'filter': ['all']},\n",
7824+
" {'paint': {'fill-opacity': 1},\n",
7825+
" 'source-layer': 'layer0',\n",
7826+
" 'type': 'fill',\n",
7827+
" 'filter': ['all']},\n",
7828+
" {'paint': {'fill-color': '#0868ac'},\n",
7829+
" 'source-layer': 'layer0',\n",
7830+
" 'type': 'fill',\n",
7831+
" 'filter': ['all', ['>=', 'food', '8']]},\n",
7832+
" {'paint': {'fill-color': '#43a2ca'},\n",
7833+
" 'source-layer': 'layer0',\n",
7834+
" 'type': 'fill',\n",
7835+
" 'filter': ['all', ['>=', 'food', '6'], ['<', 'food', '8']]},\n",
7836+
" {'paint': {'fill-color': '#7bccc4'},\n",
7837+
" 'source-layer': 'layer0',\n",
7838+
" 'type': 'fill',\n",
7839+
" 'filter': ['all', ['>=', 'food', '4'], ['<', 'food', '6']]},\n",
7840+
" {'paint': {'fill-color': '#bae4bc'},\n",
7841+
" 'source-layer': 'layer0',\n",
7842+
" 'type': 'fill',\n",
7843+
" 'filter': ['all', ['>=', 'food', '2'], ['<', 'food', '4']]},\n",
7844+
" {'paint': {'fill-color': '#f0f9e8'},\n",
7845+
" 'source-layer': 'layer0',\n",
7846+
" 'type': 'fill',\n",
7847+
" 'filter': ['all', ['<', 'food', '2']]}]},\n",
7848+
" 'layerType': 'vector'}\n",
7849+
"}"
7850+
]
7851+
},
7852+
{
7853+
"cell_type": "code",
7854+
"execution_count": 1086,
7855+
"metadata": {},
7856+
"outputs": [],
7857+
"source": [
7858+
"payload = {\n",
7859+
" 'layerConfig':{'account': 'wri-rw',\n",
7860+
" 'body': {'maxzoom': 18,\n",
7861+
" 'minzoom': 3,\n",
7862+
" 'layers': [{'type': 'mapnik',\n",
7863+
" 'options': {'sql': 'SELECT wri.cartodb_id, wri.the_geom_webmercator, data.rw_country_name, data.food FROM soc_055_global_conflict_risk_index data LEFT OUTER JOIN wri_countries_a wri ON wri.iso_a3=data.rw_country_code WHERE year=2014 AND data.food IS NOT NULL',\n",
7864+
" 'cartocss': '#soc_055_global_conflict_risk_index {polygon-opacity:1; line-width:0.3; line-color:#adadad; line-opacity:1;} [food>=8]{polygon-fill:#0868ac;} [food>=6][food<8]{polygon-fill:#43a2ca;} [food>=4][food<6]{polygon-fill:#7bccc4;} [food>=2][food<4]{polygon-fill:#bae4bc;} [food<2]{polygon-fill:#f0f9e8;}',\n",
7865+
" 'cartocss_version': '2.3.0'}}],\n",
7866+
" 'vectorLayers': []},\n",
7867+
" 'layerType': 'vector'}\n",
7868+
"}"
7869+
]
7870+
},
7871+
{
7872+
"cell_type": "code",
7873+
"execution_count": 1090,
7874+
"metadata": {},
7875+
"outputs": [
7876+
{
7877+
"data": {
7878+
"text/html": [
7879+
"<div class='item_container' style='height: auto; overflow: hidden; border: 1px solid #2BA4A0;border-radius: 2px; background: #2BA4A0; line-height: 1.21429em; padding: 10px;''><div class='item_left' style='width: 210px; float: left;''><a href='https://resourcewatch.org/' target='_blank'><img class='itemThumbnail' src='https://resourcewatch.org/static/images/logo-embed.png'></a></div><div class='item_right' style='float: none; width: auto; hidden;padding-left: 10px; overflow: hidden;''><a href=https://api.resourcewatch.org/v1/layer/cfb9e2f8-e34d-41e8-b7f9-bcb1d9201919?includes=vocabulary,metadata target='_blank'><b>2014 Global Conflict Risk Index—Food Insecurity</b></a><br> Data source cartodb | Layer in RW.<br>Last Modified: 2020-03-25T17:50:13.268Z<br><a href='https://api.resourcewatch.org/v1/fields/cfb9e2f8-e34d-41e8-b7f9-bcb1d9201919' target='_blank'>Fields</a> Connector: cartodb | Published: True </div> </div>"
7880+
],
7881+
"text/plain": [
7882+
"Layer cfb9e2f8-e34d-41e8-b7f9-bcb1d9201919 2014 Global Conflict Risk Index—Food Insecurity"
7883+
]
7884+
},
7885+
"execution_count": 1090,
7886+
"metadata": {},
7887+
"output_type": "execute_result"
7888+
}
7889+
],
7890+
"source": [
7891+
"layer"
7892+
]
7893+
},
7894+
{
7895+
"cell_type": "code",
7896+
"execution_count": 1091,
7897+
"metadata": {},
7898+
"outputs": [
7899+
{
7900+
"data": {
7901+
"text/html": [
7902+
"<div class='item_container' style='height: auto; overflow: hidden; border: 1px solid #2BA4A0;border-radius: 2px; background: #2BA4A0; line-height: 1.21429em; padding: 10px;''><div class='item_left' style='width: 210px; float: left;''><a href='https://resourcewatch.org/' target='_blank'><img class='itemThumbnail' src='https://resourcewatch.org/static/images/logo-embed.png'></a></div><div class='item_right' style='float: none; width: auto; hidden;padding-left: 10px; overflow: hidden;''><a href=https://api.resourcewatch.org/v1/layer/cfb9e2f8-e34d-41e8-b7f9-bcb1d9201919?includes=vocabulary,metadata target='_blank'><b>2014 Global Conflict Risk Index—Food Insecurity</b></a><br> Data source cartodb | Layer in RW.<br>Last Modified: 2020-03-25T17:50:21.309Z<br><a href='https://api.resourcewatch.org/v1/fields/cfb9e2f8-e34d-41e8-b7f9-bcb1d9201919' target='_blank'>Fields</a> Connector: cartodb | Published: True </div> </div>"
7903+
],
7904+
"text/plain": [
7905+
"Layer cfb9e2f8-e34d-41e8-b7f9-bcb1d9201919 2014 Global Conflict Risk Index—Food Insecurity"
7906+
]
7907+
},
7908+
"execution_count": 1091,
7909+
"metadata": {},
7910+
"output_type": "execute_result"
7911+
}
7912+
],
7913+
"source": [
7914+
"layer.update(update_params=payload, token=API_TOKEN)"
7915+
]
7916+
},
7917+
{
7918+
"cell_type": "code",
7919+
"execution_count": 1092,
7920+
"metadata": {},
7921+
"outputs": [
7922+
{
7923+
"data": {
7924+
"text/html": [
7925+
"<div class='item_container' style='height: auto; overflow: hidden; border: 1px solid #2BA4A0;border-radius: 2px; background: #2BA4A0; line-height: 1.21429em; padding: 10px;''><div class='item_left' style='width: 210px; float: left;''><a href='https://resourcewatch.org/' target='_blank'><img class='itemThumbnail' src='https://resourcewatch.org/static/images/logo-embed.png'></a></div><div class='item_right' style='float: none; width: auto; hidden;padding-left: 10px; overflow: hidden;''><a href=https://api.resourcewatch.org/v1/layer/f12a4fb3-943b-4124-aba5-59e8c4a55e3c?includes=vocabulary,metadata target='_blank'><b>2016 Gini Index</b></a><br> Data source cartodb | Layer in RW.<br>Last Modified: 2020-03-11T04:04:42.158Z<br><a href='https://api.resourcewatch.org/v1/fields/f12a4fb3-943b-4124-aba5-59e8c4a55e3c' target='_blank'>Fields</a> Connector: cartodb | Published: True </div> </div>"
7926+
],
7927+
"text/plain": [
7928+
"Layer f12a4fb3-943b-4124-aba5-59e8c4a55e3c 2016 Gini Index"
7929+
]
7930+
},
7931+
"execution_count": 1092,
7932+
"metadata": {},
7933+
"output_type": "execute_result"
7934+
}
7935+
],
7936+
"source": [
7937+
"gini = lmi.Layer(\"f12a4fb3-943b-4124-aba5-59e8c4a55e3c\")\n",
7938+
"gini"
7939+
]
7940+
},
7941+
{
7942+
"cell_type": "code",
7943+
"execution_count": 1093,
7944+
"metadata": {},
7945+
"outputs": [
7946+
{
7947+
"data": {
7948+
"text/plain": [
7949+
"{'account': 'wri-rw',\n",
7950+
" 'timelineLabel': '2016',\n",
7951+
" 'order': 2016,\n",
7952+
" 'timeline': True,\n",
7953+
" 'body': {'maxzoom': 18,\n",
7954+
" 'minzoom': 3,\n",
7955+
" 'layers': [{'type': 'mapnik',\n",
7956+
" 'options': {'sql': 'SELECT wri.cartodb_id, wri.the_geom_webmercator, data.rw_country_name, data.rw_country_code, data.datetime, data.yr_data FROM soc_020_gini data LEFT OUTER JOIN wri_countries_a wri ON data.rw_country_code = wri.iso_a3 WHERE EXTRACT(YEAR FROM data.datetime) = 2016 and data.yr_data IS NOT NULL',\n",
7957+
" 'cartocss': '#soc_020_gini {polygon-opacity: 1; line-width: 0.5; line-color: #FFF; line-opacity: 1;} [yr_data>=50]{polygon-fill:#63589f;} [yr_data>=40][yr_data<50]{polygon-fill:#9178c4;} [yr_data>=35][yr_data<40]{polygon-fill:#b998dd;} [yr_data<35]{polygon-fill:#dbbaed;}',\n",
7958+
" 'cartocss_version': '2.3.0'}}],\n",
7959+
" 'vectorLayers': [{'paint': {'fill-color': ['step',\n",
7960+
" ['to-number', ['get', 'yr_data']],\n",
7961+
" '#dbbaed',\n",
7962+
" 35,\n",
7963+
" '#b998dd',\n",
7964+
" 40,\n",
7965+
" '#9178c4',\n",
7966+
" 50,\n",
7967+
" '#63589f',\n",
7968+
" 60,\n",
7969+
" '#fff'],\n",
7970+
" 'fill-opacity': 1},\n",
7971+
" 'source-layer': 'layer0',\n",
7972+
" 'type': 'fill',\n",
7973+
" 'filter': ['all']},\n",
7974+
" {'paint': {'line-width': 0.5, 'line-color': '#fff', 'line-opacity': 0.8},\n",
7975+
" 'source-layer': 'layer0',\n",
7976+
" 'type': 'line',\n",
7977+
" 'filter': ['all']}]},\n",
7978+
" 'layerType': 'vector'}"
7979+
]
7980+
},
7981+
"execution_count": 1093,
7982+
"metadata": {},
7983+
"output_type": "execute_result"
7984+
}
7985+
],
7986+
"source": [
7987+
"gini.attributes['layerConfig']"
7988+
]
7989+
},
7990+
{
7991+
"cell_type": "code",
7992+
"execution_count": null,
7993+
"metadata": {},
7994+
"outputs": [],
7995+
"source": []
77017996
}
77027997
],
77037998
"metadata": {

0 commit comments

Comments
 (0)