Skip to content

Commit

Permalink
update table to pdf
Browse files Browse the repository at this point in the history
  • Loading branch information
nanaeaubry committed Oct 23, 2024
1 parent 366b1ec commit 8d0b8ff
Showing 1 changed file with 14 additions and 109 deletions.
123 changes: 14 additions & 109 deletions samples/05_content_publishers/pdf_table_to_pdf_map.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1246,8 +1246,7 @@
],
"source": [
"map1 = gis.map('California, USA')\n",
"map1.layout.height = '650px'\n",
"map1.legend = True\n",
"map1.legend.enabled = True\n",
"map1"
]
},
Expand All @@ -1268,15 +1267,17 @@
}
],
"source": [
"map1.clear_graphics()\n",
"overlap_rows.spatial.plot(kind='map', map_widget=map1,\n",
" renderer_type='c', # for class breaks renderer\n",
" method='esriClassifyNaturalBreaks', # classification algorithm\n",
" class_count=7, # choose the number of classes\n",
" col='ACRES', # numeric column to classify\n",
" cmap='hot', # color map to pick colors from for each class\n",
" alpha=0.7 # specify opacity\n",
" )"
"overlap_rows.spatial.plot(map_widget=map1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"smm = map1.content.renderer(0).smart_mapping()\n",
"smm.class_breaks_renderer(break_type=\"color\", classification_method='natural-breaks', num_classes=7, field=\"ACRES\")"
]
},
{
Expand Down Expand Up @@ -1342,101 +1343,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"If you would also like to export the fire impacting counties into a PDF map, the required steps are: (1) obtain the web map json via the `Item.get_data()` API method, (2) modify the web map json to also include `exportOptions` and `mapOptions`, and (3) use `arcgis.mapping.export_map()` to get the PDF deliverable of the web map."
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"dict_keys(['operationalLayers', 'baseMap', 'spatialReference', 'version', 'authoringApp', 'authoringAppVersion'])"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"webmap_json = item.get_data()\n",
"webmap_json.keys()"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'spatialReference': {'latestWkid': 3857, 'wkid': 102100},\n",
" 'xmin': -14383204.412078053,\n",
" 'ymin': 3664734.601863475,\n",
" 'xmax': -11976355.265435062,\n",
" 'ymax': 5254624.790194718}"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"map1.extent"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Based on <a href=\"https://enterprise.arcgis.com/en/server/latest/create-web-apps/windows/exportwebmap-specification.htm\">webmap spec</a>, the `mapOptions` and `exportOptions` also need to be specified for the json input. Here, the `extent` and `scale` are chosen based on the extents of the California State <a href=\"#References\">[2]</a>."
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
"webmap_json['mapOptions'] = {\n",
" \"extent\" : {\n",
" \"xmin\": -14383204.412078043,\n",
" \"ymin\": 3664734.6018634685,\n",
" \"xmax\": -11976355.2654350533,\n",
" \"ymax\": 5254624.790194712,\n",
" \"spatialReference\": {\n",
" \"latestWkid\": 3857,\n",
" \"wkid\": 102100\n",
" }\n",
" },\n",
" \"scale\" : 9244648.868618,\n",
" \"spatialReference\" : {\n",
" \"wkid\" : 102100\n",
" }\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [],
"source": [
"webmap_json['exportOptions'] = { \"dpi\" : 96,\n",
" \"outputSize\" : [746, 575]\n",
" }"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Finally, we used <a href=\"https://developers.arcgis.com/python/api-reference/arcgis.mapping.toc.html?highlight=export#arcgis.mapping.export_map\">`export_map`</a> method to create a PDF output of the web map item <a href=\"#References\">[3]</a>."
"Finally, we used <a href=\"https://developers.arcgis.com/python/latest/api-reference/arcgis.map.toc.html#arcgis.map.Map.print\">`print`</a> method to create a PDF output of the web map item <a href=\"#References\">[3]</a>."
]
},
{
Expand All @@ -1456,9 +1363,7 @@
}
],
"source": [
"from arcgis.mapping import export_map\n",
"res = export_map(web_map_as_json=webmap_json, format='PDF', layout_template='MAP_ONLY')\n",
"#res[\"url\"]\n",
"res = map1.print(file_format='PDF', layout_template='MAP_ONLY')\n",
"res.url"
]
},
Expand Down

0 comments on commit 8d0b8ff

Please sign in to comment.