diff --git a/guide/10-mapping-and-visualization/working-with-web-maps-and-web-scenes.ipynb b/guide/10-mapping-and-visualization/working-with-web-maps-and-web-scenes.ipynb index 9a2b1d2665..e34e2d09b0 100644 --- a/guide/10-mapping-and-visualization/working-with-web-maps-and-web-scenes.ipynb +++ b/guide/10-mapping-and-visualization/working-with-web-maps-and-web-scenes.ipynb @@ -1 +1,816 @@ -{"cells": [{"cell_type": "markdown", "metadata": {}, "source": ["# Working with web maps and web scenes"]}, {"cell_type": "markdown", "metadata": {"toc": true}, "source": ["

Table of Contents

\n", "
"]}, {"cell_type": "markdown", "metadata": {}, "source": ["An ArcGIS web map is an interactive display of geographic information through a composition of web layers, basemap and much more. A web scene is analogous to a web map but in the 3D space. To get and overview, visit the product documentation for [web maps](http://doc.arcgis.com/en/arcgis-online/reference/what-is-web-map.htm) and [web scenes](http://doc.arcgis.com/en/arcgis-online/reference/what-is-web-scene.htm).\n", "\n", "Web maps and scenes are stored as items on your portal and their content is in JavaScript Object Notation (JSON), a text format that can easily be transferred, stored, and edited. In this guide we will observe how to work maps and scenes using the `arcgis.mapping` module.\n", "\n", "## Working with web maps\n", "2D maps in your GIS are stored as web map items. A web map contains a JSON defining the bookmarks, layers, their symbology, order and other cartographic information. If you are interested in learning more about this specification, refer to this [documentation](/web-map-specification/). In the `mapping` module, web maps are represented using a `WebMap` class. At version 1.3 of the Python API, the `WebMap` class has been enhanced with the ability to easily add, remove layers and a few other basic operations."]}, {"cell_type": "code", "execution_count": 21, "metadata": {"collapsed": true}, "outputs": [], "source": ["from IPython.display import display\n", "import arcgis\n", "from arcgis.gis import GIS\n", "\n", "# connect to your GIS\n", "gis = GIS('home')"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Searching for web maps\n", "We can search for web maps just like any other item:"]}, {"cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [{"data": {"text/plain": ["[,\n", " ,\n", " ,\n", " ,\n", " ]"]}, "execution_count": 26, "metadata": {}, "output_type": "execute_result"}], "source": ["webmap_search = gis.content.search(\"Ebola maps\", item_type=\"Web Map\")\n", "webmap_search"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Let us take a look at one of the web maps"]}, {"cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [{"data": {"text/html": ["
\n", "
\n", " \n", " \n", " \n", "
\n", "\n", "
\n", " Ebola treatment locations\n", " \n", "
This map shows locations of Ebola treatment centers in AfricaWeb Map by arcgis_python\n", "
Last Modified: December 06, 2017\n", "
0 comments, 2 views\n", "
\n", "
\n", " "], "text/plain": [""]}, "execution_count": 27, "metadata": {}, "output_type": "execute_result"}], "source": ["ebola_map_item = webmap_search[1]\n", "ebola_map_item"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Creating a `WebMap` object\n", "You can create an empty web map with a default basemap and no operational layers from the `WebMap` class:"]}, {"cell_type": "code", "execution_count": 35, "metadata": {"collapsed": true}, "outputs": [], "source": ["from arcgis.mapping import WebMap\n", "empty_webmap = WebMap()"]}, {"cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [{"data": {"text/plain": ["[]"]}, "execution_count": 36, "metadata": {}, "output_type": "execute_result"}], "source": ["empty_webmap.layers"]}, {"cell_type": "markdown", "metadata": {}, "source": ["You can also create a `WebMap` object from an existing web map item by passing the web map item as the parameter to the constructor:"]}, {"cell_type": "code", "execution_count": 28, "metadata": {"collapsed": true}, "outputs": [], "source": ["ebola_map = WebMap(ebola_map_item)"]}, {"cell_type": "markdown", "metadata": {}, "source": ["A typical web map consists of a few operational layers and one or more basemap layers. To view the operational layers, call the `layers` property:"]}, {"cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["Ebola_Treatment_Units - Ebola_Treatment_Units_Unclassed\n", "Ebola_Treatment_Units - Ebola_Treatment_Units_Classed\n"]}], "source": ["for layer in ebola_map.layers:\n", " print(layer.title)"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Similarly, you can find what basemap is used in this web map by querying the `baseMap` property:"]}, {"cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [{"data": {"text/plain": ["{\n", " \"baseMapLayers\": [\n", " {\n", " \"id\": \"World_Topo_Map_9991\",\n", " \"layerType\": \"ArcGISTiledMapServiceLayer\",\n", " \"url\": \"https://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer\",\n", " \"visibility\": true,\n", " \"opacity\": 1,\n", " \"title\": \"World Topographic Map\"\n", " }\n", " ],\n", " \"title\": \"Topographic\"\n", "}"]}, "execution_count": 31, "metadata": {}, "output_type": "execute_result"}], "source": ["ebola_map.basemap"]}, {"cell_type": "markdown", "metadata": {}, "source": ["At any time, you can get the full definition of the web map by calling the `definition` property:"]}, {"cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [{"data": {"text/plain": ["{\n", " \"wkid\": 102100,\n", " \"latestWkid\": 3857\n", "}"]}, "execution_count": 32, "metadata": {}, "output_type": "execute_result"}], "source": ["ebola_map.definition.spatialReference"]}, {"cell_type": "markdown", "metadata": {}, "source": ["You can also cast the `definition` into a Python `dictionary` and print out the keys:"]}, {"cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [{"data": {"text/plain": ["dict_keys(['operationalLayers', 'baseMap', 'spatialReference', 'authoringApp', 'authoringAppVersion', 'version'])"]}, "execution_count": 33, "metadata": {}, "output_type": "execute_result"}], "source": ["dict(ebola_map.definition).keys()"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Displaying the web map\n", "When using the Jupyter notebook environment, a `WebMap` object can be easily visualized by simply querying it. A map widget loads up and the map is rendered:"]}, {"cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [{"data": {"application/vnd.jupyter.widget-view+json": {"model_id": "e65b5032957e40e7a94d19e55ff7903a"}}, "metadata": {}, "output_type": "display_data"}], "source": ["ebola_map"]}, {"cell_type": "markdown", "metadata": {}, "source": ["![img: ebola webmap](http://esri.github.io/arcgis-python-api/notebooks/nbimages/guide_mapping_webmaps_01.png)"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Removing layers from a web map\n", "You can update a web map by adding or removing layers. For instance, the cell below removes one of the layers from the web map and adds a different layer."]}, {"cell_type": "code", "execution_count": 37, "metadata": {"collapsed": true}, "outputs": [], "source": ["# remove the first - unclassed layer from the map\n", "ebola_map.remove_layer(ebola_map.layers[0])"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Adding layers to a web map\n", "To add new layers, call the `add_layer()` method. You can layer objects such as `FeatureLayer`, `ImageryLayer`, `FeatureCollection` objects and also `Item` objects. When adding a layer to the web map you can specify options such as title, custom symbols, visibility, opaticy etc. The code below adds a feature layer collection item to the web map."]}, {"cell_type": "code", "execution_count": 42, "metadata": {}, "outputs": [{"data": {"text/plain": ["True"]}, "execution_count": 42, "metadata": {}, "output_type": "execute_result"}], "source": ["liberia_item = gis.content.get('49161527a2bc4f4782b50d2c14e38f4a')\n", "ebola_map.add_layer(liberia_item, options={'title':'Liberia facilities and hospitals'})"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Saving or Updating a web map\n", "To save a web map, simply call the `save()` method. Similarly, if you created the `WebMap` object from an existing web map item, then you can call the `update()` method to update it. \n", "\n", "Note, `save()` method always creates a new item with updated web map definition, so if you want to create a copy of an existing web map, this is a great way. For instance, the cell below calls the `save()` method and creates a new web map item with the new set of layers without disturbing the original Ebola web map item."]}, {"cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [{"data": {"text/html": ["
\n", "
\n", " \n", " \n", " \n", "
\n", "\n", "
\n", " Ebola incidents and facilities\n", " \n", "
Map created using Python API showing locations of Ebola treatment centersWeb Map by arcgis_python\n", "
Last Modified: December 06, 2017\n", "
0 comments, 0 views\n", "
\n", "
\n", " "], "text/plain": [""]}, "execution_count": 44, "metadata": {}, "output_type": "execute_result"}], "source": ["webmap_item_properties = {'title':'Ebola incidents and facilities',\n", " 'snippet':'Map created using Python API showing locations of Ebola treatment centers',\n", " 'tags':['automation', 'ebola', 'world health', 'python']}\n", "\n", "ebola_map.save(webmap_item_properties, thumbnail='./webmap_thumbnail.png')"]}, {"cell_type": "markdown", "metadata": {}, "source": ["## Working with web scenes\n", "In your GIS, 3D maps are stored as web scene items. Similar to web maps, web scenes contain the definition of the layers, their cartography in JSON. In the `mapping` module, a web scene is represented using a `WebScene` object.\n", "\n", "You can search for a web scene similar to any other item:"]}, {"cell_type": "markdown", "metadata": {}, "source": ["## Searching for web scene items"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [{"data": {"text/plain": ["[,\n", " ,\n", " ,\n", " ,\n", " ]"]}, "execution_count": null, "metadata": {}, "output_type": "execute_result"}], "source": ["webscene_search = gis.content.search(\"\", item_type=\"Web Scene\")\n", "webscene_search"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Let us access the first web scene from this list."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [{"data": {"text/html": ["
\n", "
\n", " \n", " \n", " \n", "
\n", "\n", "
\n", " Toprical Cyclones - Summer\n", " \n", "
Subset of Western Pacific Typhoons (2005) published by esri_3dWeb Scene by demo_deldev\n", "
Last Modified: December 15, 2016\n", "
0 comments, 1 views\n", "
\n", "
\n", " "], "text/plain": [""]}, "execution_count": null, "metadata": {}, "output_type": "execute_result"}], "source": ["webscene_item = webscene_search[0]\n", "webscene_item"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Creating a `WebScene` object\n", "You can create a `WebScene` object using the constructor and passing the web scene item as the parameter:"]}, {"cell_type": "code", "execution_count": null, "metadata": {"collapsed": true}, "outputs": [], "source": ["from arcgis.mapping import WebScene\n", "webscene_obj = WebScene(webscene_item)"]}, {"cell_type": "markdown", "metadata": {}, "source": ["The `WebScene` object provides a dictionary representation of the information contained in the web scene. For instance, you can view the list of layers in this web map by querying the operationalLayers key."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [{"data": {"text/plain": ["[{'id': '14a37c397dc-layer17',\n", " 'layerType': 'GroupLayer',\n", " 'layers': [{'id': '56803f3d64184140950f0ef1256a0603',\n", " 'layerDefinition': {'drawingInfo': {'renderer': {'description': '',\n", " 'label': '',\n", " 'symbol': {'name': 'Pushpin 1',\n", " 'styleName': 'EsriIconsStyle',\n", " 'type': 'styleSymbolReference'},\n", " 'type': 'simple',\n", " 'visualVariables': [{'axis': 'all',\n", " 'minSize': 25,\n", " 'type': 'sizeInfo',\n", " 'valueUnit': 'unknown'}]}},\n", " 'elevationInfo': {'mode': 'absoluteHeight'}},\n", " 'layerType': 'ArcGISFeatureLayer',\n", " 'opacity': 1,\n", " 'showLabels': True,\n", " 'title': 'Labels Q2',\n", " 'url': 'http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/PacificTyphoons2005_WFL/FeatureServer/5',\n", " 'visibility': False},\n", " {'id': '72668fcc8a904bd6a1444bef2e72f420',\n", " 'layerDefinition': {'drawingInfo': {'renderer': {'description': '',\n", " 'label': '',\n", " 'symbol': {'name': 'Standing Cylinder',\n", " 'styleName': 'EsriThematicShapesStyle',\n", " 'type': 'styleSymbolReference'},\n", " 'type': 'simple',\n", " 'visualVariables': [{'axis': 'height',\n", " 'field': 'windspeed',\n", " 'minDataValue': 0.0001,\n", " 'minSize': 1,\n", " 'type': 'sizeInfo'},\n", " {'axis': 'widthAndDepth',\n", " 'minSize': 100000,\n", " 'type': 'sizeInfo',\n", " 'valueUnit': 'meters'},\n", " {'field': 'airpressure',\n", " 'stops': [{'color': [245, 0, 0], 'value': 920},\n", " {'color': [245, 245, 0], 'value': 1014}],\n", " 'type': 'colorInfo'}]}},\n", " 'elevationInfo': {'mode': 'absoluteHeight'}},\n", " 'layerType': 'ArcGISFeatureLayer',\n", " 'opacity': 1,\n", " 'popupInfo': {'mediaInfos': [{'caption': \"

Pressure: {airpressure} hPa

Wind speed: {wind_mph} mph / {wind_kph} kph

Date: {timedescription}

\",\n", " 'title': \"

{typhoonclass} {typhoon}

\",\n", " 'type': 'image',\n", " 'value': {'sourceURL': '{image}'}}],\n", " 'title': '{typhoon}'},\n", " 'title': 'Typhoons Q2',\n", " 'url': 'http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/PacificTyphoons2005_WFL/FeatureServer/4',\n", " 'visibility': False}],\n", " 'listMode': 'hide-children',\n", " 'opacity': 1,\n", " 'title': 'April - June',\n", " 'visibility': True,\n", " 'visibilityMode': 'inherited'}]"]}, "execution_count": null, "metadata": {}, "output_type": "execute_result"}], "source": ["webscene_obj['operationalLayers']"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Similar to a `WebMap` seen earlier, you can find the list of all keys that you can query for by calling the keys() function:"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [{"data": {"text/plain": ["odict_keys(['authoringApp', 'baseMap', 'initialState', 'version', 'operationalLayers', 'presentation', 'authoringAppVersion'])"]}, "execution_count": null, "metadata": {}, "output_type": "execute_result"}], "source": ["webscene_obj.keys()"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Displaying the web scene\n", "When using the Jupyter notebook environment, a `WebScene` object can be easily visualized by simply querying it. A map widget loads up and the scene is rendered:"]}, {"cell_type": "code", "execution_count": null, "metadata": {"collapsed": true}, "outputs": [], "source": ["webscene_obj"]}, {"cell_type": "markdown", "metadata": {}, "source": ["![tropical cyclones web scene](http://esri.github.io/arcgis-python-api/notebooks/nbimages/05_Using_updating_GIS_06.PNG)"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### Updating a web scene\n", "The `WebScene` object provides an `update()` method that allows you to modify a web scene and save those changes back. To update a web scene, you modify its definition by changing the adding, removing or changing the values of its keys and then call the update() method. Refer to the sample notebook on [using and updating a web scene](https://developers.arcgis.com/python/sample-notebooks/using-and-updating-gis-content/#Using-and-updating-a-web-scene) for an example."]}], "metadata": {"anaconda-cloud": {}, "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.8.2"}, "toc": {"base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": true, "toc_position": {}, "toc_section_display": true, "toc_window_display": true}}, "nbformat": 4, "nbformat_minor": 1} \ No newline at end of file +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Working with web maps and web scenes" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "toc": true + }, + "source": [ + "

Table of Contents

\n", + "" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "An ArcGIS web map is an interactive display of geographic information through a composition of web layers, basemap and much more. A web scene is analogous to a web map but in the 3D space. To get and overview, visit the product documentation for [web maps](http://doc.arcgis.com/en/arcgis-online/reference/what-is-web-map.htm) and [web scenes](http://doc.arcgis.com/en/arcgis-online/reference/what-is-web-scene.htm).\n", + "\n", + "Web maps and scenes are stored as items on your portal and their content is in JavaScript Object Notation (JSON), a text format that can easily be transferred, stored, and edited. In this guide we will observe how to work maps and scenes using the `arcgis.layers` module.\n", + "\n", + "## Working with web maps\n", + "2D maps in your GIS are stored as web map items. A web map contains a JSON defining the bookmarks, layers, their symbology, order and other cartographic information. If you are interested in learning more about this specification, refer to this [documentation](/web-map-specification/). In the `mapping` module, web maps are represented using a `WebMap` class. At version 1.3 of the Python API, the `WebMap` class has been enhanced with the ability to easily add, remove layers and a few other basic operations." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "from IPython.display import display\n", + "import arcgis\n", + "from arcgis.gis import GIS\n", + "\n", + "# connect to your GIS\n", + "gis = GIS('home')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Searching for web maps\n", + "We can search for web maps just like any other item:" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[]" + ] + }, + "execution_count": 44, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "webmap_search = gis.content.search(\"Drilling *\", item_type=\"Web Map\")\n", + "webmap_search" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Let us take a look at one of the web maps" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "
\n", + " \n", + " \n", + " \n", + "
\n", + "\n", + "
\n", + " USA WebMap with Drilling Platforms\n", + " \n", + "
Jupyter notebook widget saved as a web map
Web Map by arcgis_python\n", + "
Last Modified: August 12, 2024\n", + "
0 comments, 62 views\n", + "
\n", + "
\n", + " " + ], + "text/plain": [ + "" + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "drilling_item = webmap_search[0]\n", + "drilling_item" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Creating a `Map` object\n", + "You can create an empty web map with a default basemap and no operational by initializing the `Map` class with no arguments:" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [], + "source": [ + "from arcgis.map import Map\n", + "empty_webmap = Map()" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "arcgis.map.map_widget.Map" + ] + }, + "execution_count": 47, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(empty_webmap)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The operational layers information is empty:" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[]" + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "empty_webmap.content.layers" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The basemap information uses the properties of the organization:" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'baseMapLayers': [{'id': 'VectorTile_7665',\n", + " 'itemId': '273bf8d5c8ac400183fc24e109d20bcf',\n", + " 'layerType': 'VectorTileLayer',\n", + " 'opacity': 1.0,\n", + " 'styleUrl': 'https://www.arcgis.com/sharing/rest/content/items/273bf8d5c8ac400183fc24e109d20bcf/resources/styles/root.json',\n", + " 'title': 'Community',\n", + " 'type': 'VectorTileLayer',\n", + " 'visibility': True}],\n", + " 'title': 'Community Map'}" + ] + }, + "execution_count": 50, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "empty_webmap.basemap.basemap" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You can also create a `WebMap` object from an existing web map item by passing the web map item as the parameter to the constructor:" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [], + "source": [ + "drilling_map = Map(\n", + " item=drilling_item\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "A typical web map consists of a few operational layers and one or more basemap layers. To view the operational layers, call the `content` property to initialize a _Map Content_ object, and then use the content's `layers` property:" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[,\n", + " ]" + ] + }, + "execution_count": 53, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "drilling_map.content.layers" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Similarly, you can find what basemap is used in this web map by querying the _Map_ `basemap` property to initialize the `BasemapManager`, and then using the manager's `basemap` property:" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Basemap Manager" + ] + }, + "execution_count": 58, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "drilling_map.basemap" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'baseMapLayers': [{'id': 'World_Hillshade_3689',\n", + " 'layerType': 'ArcGISTiledMapServiceLayer',\n", + " 'opacity': 1.0,\n", + " 'refreshInterval': 0,\n", + " 'title': 'World Hillshade',\n", + " 'url': 'https://services.arcgisonline.com/arcgis/rest/services/Elevation/World_Hillshade/MapServer',\n", + " 'visibility': True},\n", + " {'id': 'VectorTile_6451',\n", + " 'layerType': 'VectorTileLayer',\n", + " 'opacity': 1.0,\n", + " 'styleUrl': 'https://cdn.arcgis.com/sharing/rest/content/items/7dc6cea0b1764a1f9af2e679f642f0f5/resources/styles/root.json',\n", + " 'title': 'World Topographic Map',\n", + " 'visibility': True}],\n", + " 'title': 'Topographic'}" + ] + }, + "execution_count": 55, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "drilling_map.basemap.basemap" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Displaying the web map\n", + "When using the Jupyter Lab notebook environment, a `Map` object can be easily visualized by simply querying it. A map widget loads up and the map is rendered:" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 60, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "drilling_map" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Removing layers from a web map\n", + "You can update a web map by adding or removing layers. For instance, the cell below removes one of the layers from the web map." + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 \n", + "1 \n" + ] + } + ], + "source": [ + "for idx, lyr in enumerate(drilling_map.content.layers):\n", + " print(f\"{idx:<6}{lyr}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 65, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "drilling_map.content.remove(1)" + ] + }, + { + "cell_type": "code", + "execution_count": 66, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 \n" + ] + } + ], + "source": [ + "for idx, lyr in enumerate(drilling_map.content.layers):\n", + " print(f\"{idx:<6}{lyr}\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Adding layers to a web map\n", + "To add new layers, call the `Map.content.add()` method. You can add many different types of layers with this method, such as `FeatureLayer`, `ImageryLayer`, or `FeatureCollection` objects, as well as using `Items` as input. The code below adds a feature layer collection item to the web map and updates the layer's title property at the same timeC." + ] + }, + { + "cell_type": "code", + "execution_count": 67, + "metadata": {}, + "outputs": [], + "source": [ + "trunks_item = gis.content.get('bb2aee97117d403ea63bcfe6be4a12c8')\n", + "\n", + "drilling_map.content.add(\n", + " trunks_item, options={'title':'Crude Oil Trunk Pipelines'})" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Saving or Updating a web map\n", + "To save a web map from a brand new widget, simply call the `save()` method on the _Map_ object. If you created the `Map` object from an existing web map item, then you can call the `update()` method to update its properties. \n", + "\n", + "> **Note:** - `save()` always creates a new item with updated web map definition, so if you want to create a copy of an existing web map, this is a great way. For instance, the cell below calls the `save()` method and creates a new web map item with the new set of layers without disturbing the original web map item." + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "
\n", + " \n", + " \n", + " \n", + "
\n", + "\n", + "
\n", + " USA Drilling Platforms and Crude Trunks\n", + " \n", + "
Map created using Python API showing locations of US oil platforms and crude trunks.
Web Map by arcgis_python\n", + "
Last Modified: August 12, 2024\n", + "
0 comments, 0 views\n", + "
\n", + "
\n", + " " + ], + "text/plain": [ + "" + ] + }, + "execution_count": 68, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "webmap_item_properties = {'title':'USA Drilling Platforms and Crude Trunks',\n", + " 'snippet':'Map created using Python API showing locations of US oil platforms and crude trunks.',\n", + " 'tags':['oil', 'raw materies', 'utilities', 'python']}\n", + "\n", + "drilling_map.save(webmap_item_properties, thumbnail='./webmap_thumbnail.png')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Working with web scenes\n", + "In your GIS, 3D maps are stored as Web Scene items. Similar to web maps, web scenes contain the definition of the layers and their cartography in JSON format. In the `map` module, a web scene is represented using the `Scene` class.\n", + "\n", + "You can search for a web scene similar to any other item:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Searching for web scene items" + ] + }, + { + "cell_type": "code", + "execution_count": 78, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[,\n", + " ,\n", + " ,\n", + " ,\n", + " ,\n", + " ,\n", + " ,\n", + " ,\n", + " ,\n", + " ]" + ] + }, + "execution_count": 78, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "webscene_search = gis.content.search(\"Typhoons\", item_type=\"Web Scene\")\n", + "webscene_search" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Let us access the first web scene from this list." + ] + }, + { + "cell_type": "code", + "execution_count": 79, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "
\n", + " \n", + " \n", + " \n", + "
\n", + "\n", + "
\n", + " Recent Storm Scene\n", + " \n", + "
Global scene of recent hurricanes, cyclones, and typhoons
Web Scene by arcgis_python\n", + "
Last Modified: August 12, 2024\n", + "
0 comments, 0 views\n", + "
\n", + "
\n", + " " + ], + "text/plain": [ + "" + ] + }, + "execution_count": 79, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "webscene_item = webscene_search[8]\n", + "webscene_item" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Creating a `Scene` object\n", + "You can create a `Scene` object by passing an existing web scene item as the `Scene` class's _item_ argument:" + ] + }, + { + "cell_type": "code", + "execution_count": 188, + "metadata": {}, + "outputs": [], + "source": [ + "from arcgis.map import Scene\n", + "\n", + "scene_obj = Scene(\n", + " item=webscene_item\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You can view the list of layers in this web scene by querying the `content` property to return a `SceneContent` object, then using its `layers` property to list the operational layers:" + ] + }, + { + "cell_type": "code", + "execution_count": 189, + "metadata": {}, + "outputs": [], + "source": [ + "scene_content = scene_obj.content" + ] + }, + { + "cell_type": "code", + "execution_count": 190, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[Group Layer: Recent Hurricanes, Cyclones and Typhoons]" + ] + }, + "execution_count": 190, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "scene_content.layers" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Displaying the web scene\n", + "When using the Jupyter Lab notebook environment, a `Scene` object can be easily visualized by simply querying it. A map widget loads up and the scene is rendered:" + ] + }, + { + "cell_type": "code", + "execution_count": 195, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 195, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "scene_obj" + ] + }, + { + "cell_type": "code", + "execution_count": 192, + "metadata": {}, + "outputs": [], + "source": [ + "scene_obj.center = [20.138470, -88.870125]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "> **note:** Use the rotate button to change the tilt and elevation position values to observe 3D properties and create a view like that above. You can print out the _camera_ properties after using the interactive buttons to see how the camera operates:" + ] + }, + { + "cell_type": "code", + "execution_count": 194, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'position': {'spatialReference': {'latestWkid': 3857, 'wkid': 102100},\n", + " 'x': -9835222.48051016,\n", + " 'y': 252804.4801989533,\n", + " 'z': 1955763.3549772874},\n", + " 'heading': 358.4031426650046,\n", + " 'tilt': 41.37345157801427}" + ] + }, + "execution_count": 194, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "scene_obj.camera" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Updating a web scene\n", + "The `Scene` object provides an `update()` method that allows you to modify the Web Scene item used to initialize the _Scene_ object. To update a web scene, you can add or remove content, as well as change any item properties by submitting a dictionary argument to the _item_properties_ argument, or provide a thumbnail and new metadata. We'll update the tags and title of the current scene:\n", + "\n", + "> **note:** The _title_, _tags_ and _snippet_ keys are required when updating." + ] + }, + { + "cell_type": "code", + "execution_count": 202, + "metadata": {}, + "outputs": [], + "source": [ + "updated_scene = scene_obj.save(\n", + " item_properties={\n", + " \"title\":\"Storm Scene Updates\",\n", + " \"snippet\":\"Web Scene updated through the API.\",\n", + " \"tags\": scene_obj.item.tags + [\"api_updates\"]\n", + " }\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 203, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "
\n", + " \n", + " \n", + " \n", + "
\n", + "\n", + "
\n", + " Storm Scene Updates\n", + " \n", + "
Web Scene updated through the API.
Web Scene by arcgis_python\n", + "
Last Modified: August 12, 2024\n", + "
0 comments, 0 views\n", + "
\n", + "
\n", + " " + ], + "text/plain": [ + "" + ] + }, + "execution_count": 203, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "updated_scene" + ] + } + ], + "metadata": { + "anaconda-cloud": {}, + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.11.0" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": true, + "sideBar": true, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": true, + "toc_position": {}, + "toc_section_display": true, + "toc_window_display": true + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}