Using and updating GIS content

The GIS is a warehouse of geographic content and services. Arcgis includes several classes to make use of these content, publish new items and update the them when needed. This sample on updating the content of web maps and web scenes will demonstrate the following

  • Replace web layers of a web map. For instance, you can use this to update a web map when the services it points to were deleted. The sample shows how to read a web feature layer as a FeatureService object and inspect its properties.
  • Drive the map widget by code. In addition to displaying the interactive map widget, you can also set it to load at a particular extent. This is great for presentation purposes. During this process, the sample shows how to create and use a MapView object and a Geocoder object.
  • Make a copy of a public web scene item into your contents and then update it.
    • Edit the list of layers to remove unnecessary ones.
    • Replace the basemap of the web scene. In this step the sample shows how to search for groups and query the member items.
    • Change visibility of layers.
from arcgis.gis import GIS
from IPython.display import display

gis = GIS("https://pythonapi.playground.esri.com/portal")

Using and updating a web map

We will search for that web map that has broken layers, render it on the notebook and update it.

search_result = gis.content.search("title:Ebola treatment locations", item_type = "Web Map")
display(search_result)
[<Item title:"Ebola treatment locations original" type:Web Map owner:arcgis_python>,
 <Item title:"Ebola treatment locations" type:Web Map owner:arcgis_python>]

Read the web map as a WebMap object

wm_item = search_result[1]

from arcgis.mapping import WebMap
web_map_obj = WebMap(wm_item)
# display the web map obj in an interactive widget
web_map_obj

Fix errors in web map

The widget loads an empty web map with just a basemap. Let us investigate the contents of the web map to determine the issue. You can query the layers in the web map using the layers property.

web_map_obj.layers
[{
   "id": "layer1",
   "layerType": "ArcGISFeatureLayer",
   "url": "https://services.arcgis.com/ORGID/arcgis/rest/services/Ebola_Facilities/FeatureServer/1",
   "visibility": true,
   "opacity": 1,
   "title": "Ebola_Treatment_Units - Ebola_Treatment_Units_Classed",
   "itemId": "f53d5907296e43e28e8570a24b1d1d26"
 }]

The web map has only 1 layer and that points to a feature service named Ebola_Facilities. Let us verify if a feature service of that name exists on the server. If not, let us try to find the closest match.

search_result = gis.content.search('title:Ebola_Facilities', item_type = 'Feature Service')
display(search_result)
[]

Let us change the search query leaving just the word Ebola in the title.

search_result = gis.content.search('title:Ebola', item_type='Feature Layer')
search_result[0]
Ebola_Treatment_Units
Locations of Ebola treatment units in Africa.Feature Layer Collection by arcgis_python
Last Modified: July 05, 2017
0 comments, 7 views

It is likely the old service was deleted and a new one was with a different name was published. Let us update the web map with the new feature layer

ebola = search_result[0]
ebola.layers
[<FeatureLayer url:"http://pythonapi.playground.esri.com/server/rest/services/Hosted/Ebola_Treatment_Units/FeatureServer/0">,
 <FeatureLayer url:"http://pythonapi.playground.esri.com/server/rest/services/Hosted/Ebola_Treatment_Units/FeatureServer/1">]

The new feature service does have a layer with id 1. Hence we can use the same layer id while switching the url. To remove the old layer, call remove_layer() method. Then add the correct FeatureLayer object by calling the add_layer() method on the WebMap object.

# remove the old layer from the web map
web_map_obj.remove_layer(web_map_obj.layers[0])
# add the correct layer. While adding you can customize the title
web_map_obj.add_layer(ebola.layers[1], options={'title':'Ebola_Treatment_Units - Ebola_Treatment_Units_Classed'})
True

Check the layers on the web map

for lyr in web_map_obj.layers:
    print(lyr.title + " " + lyr.url)
Ebola_Treatment_Units - Ebola_Treatment_Units_Classed http://pythonapi.playground.esri.com/server/rest/services/Hosted/Ebola_Treatment_Units/FeatureServer/1

Update the web map

Now the web map should be fixed as it points to a live service. To update the web map, we call the update() method. You have the option to update the thumbnail or any other item properties at this time.

web_map_obj.update(item_properties={'title':'Ebola treatment locations - updated'},
                  thumbnail = "./data/webmap_thumbnail.png")
True

Query the web map object to visualize it in the notebook

web_map_obj

The web map was sucessfully overwritten with correct operational layers. You can interact with the widget and zoom into the African coast to observe the locations of Ebola treatment centers.

Using and updating a web scene

In the sample above we observed how to update a web map. Updating the web scene is similar, we use the update() method. Let us look at the example of a web scene that displays tropical cyclones over the Pacific ocean.

search_result = gis.content.search('title:Western Pacific Typhoons (2005)', 
                                   item_type = 'Web Scene', outside_org = True)
search_result[0]
Western Pacific Typhoons (2005)
Web Scene by arcgis_python
Last Modified: July 05, 2017
0 comments, 0 views

Lets display the web scene in the notebook.

web_scene_item = search_result[0]
web_scene_obj = arcgis.mapping.WebScene(web_scene_item)

# display web scene in the notebook
web_scene_obj

This is a great web scene and it displays a lot of hurricane tracks. However, we want to create a new one with only a particular subset of data and customize the basemaps. To modify this web scene, let us first make a copy of it and publish it into your portal.

Make a copy of the public web scene item

To make a copy, we essentially download the content of the web scene JSON, remove the parts we don't want, add the layers that we want and publish a new item using that information. The publishing steps is similar to what is described earlier in the data preparation section and in detail in the sample titled Publishing web maps and web scenes.

Let's say, we are only interested in the storms that occur in summer. Summer in tropical Asia is around April-June and that matches with a layer in the existing web scene. Let us query the operationalLayers section of the web scene to understand how the layers look like.

Update operational layers of new web scene

display(web_scene_obj['operationalLayers'])
[{'id': '882ce65eceda4e2ba2ad65f9e2c0632f',
  'layerDefinition': {'drawingInfo': {'renderer': {'description': '',
     'label': '',
     'symbol': {'symbolLayers': [{'material': {'color': [0, 169, 230],
         'transparency': 0},
        'size': 5,
        'type': 'Line'}],
      'type': 'LineSymbol3D'},
     'type': 'simple'}},
   'elevationInfo': {'mode': 'onTheGround'},
   'minScale': 120000000},
  'layerType': 'ArcGISFeatureLayer',
  'opacity': 1,
  'popupInfo': {'description': "<div><p><span style='font-weight:bold;'>Typhoon {name}</span></p><p><span style='font-weight:bold;'>Started: </span><span>{datedescription}</span></p></div>",
   'mediaInfos': [],
   'title': '{name}'},
  'title': 'Typhoon Paths',
  'url': 'http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/PacificTyphoons2005_WFL/FeatureServer/18',
  'visibility': True},
 {'id': '14a37c86f84-layer21',
  'layerType': 'GroupLayer',
  'layers': [{'id': '7a24e304d2474d7eb29a712c95202140',
    'layerDefinition': {'drawingInfo': {'renderer': {'description': '',
       'label': '',
       'symbol': {'name': 'Pushpin 1',
        'styleName': 'EsriIconsStyle',
        'type': 'styleSymbolReference'},
       'type': 'simple',
       'visualVariables': [{'axis': 'all',
         'minSize': 25,
         'type': 'sizeInfo',
         'valueUnit': 'unknown'}]}},
     'elevationInfo': {'mode': 'absoluteHeight'}},
    'layerType': 'ArcGISFeatureLayer',
    'opacity': 1,
    'showLabels': True,
    'title': 'Labels Q4',
    'url': 'http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/PacificTyphoons2005_WFL/FeatureServer/17',
    'visibility': False},
   {'id': '10944e27c9f04bc39b5821c0046523a5',
    'layerDefinition': {'drawingInfo': {'renderer': {'description': '',
       'label': '',
       'symbol': {'name': 'Standing Cylinder',
        'styleName': 'EsriThematicShapesStyle',
        'type': 'styleSymbolReference'},
       'type': 'simple',
       'visualVariables': [{'axis': 'height',
         'field': 'windspeed',
         'minDataValue': 0.0001,
         'minSize': 1,
         'type': 'sizeInfo'},
        {'axis': 'widthAndDepth',
         'minSize': 100000,
         'type': 'sizeInfo',
         'valueUnit': 'meters'},
        {'field': 'airpressure',
         'stops': [{'color': [245, 0, 0], 'value': 920},
          {'color': [245, 245, 0], 'value': 1014}],
         'type': 'colorInfo'}]}},
     'elevationInfo': {'mode': 'absoluteHeight'}},
    'layerType': 'ArcGISFeatureLayer',
    'opacity': 1,
    'popupInfo': {'mediaInfos': [{'caption': "<div><p><span style='font-weight:bold;'>Pressure: </span><span>{airpressure} hPa</span></p><p><span style='font-weight:bold;'>Wind speed: </span><span>{wind_mph} mph / {wind_kph} kph</span></p><p><p><span style='font-weight:bold;'>Date: </span><span>{timedescription}</span></p></div></p>",
       'title': "<div><p><span style='font-weight:bold;'>{typhoonclass} {typhoon}</span></p></div>",
       'type': 'image',
       'value': {'sourceURL': '{image}'}}],
     'title': '{typhoon}'},
    'title': 'Typhoons Q4',
    'url': 'http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/PacificTyphoons2005_WFL/FeatureServer/16',
    'visibility': False}],
  'listMode': 'hide-children',
  'opacity': 1,
  'title': 'October - December',
  'visibility': False,
  'visibilityMode': 'inherited'},
 {'id': '14a37c7f247-layer20',
  'layerType': 'GroupLayer',
  'layers': [{'id': '90eba5af0b084c569a55ebc9b3bfc21e',
    'layerDefinition': {'drawingInfo': {'renderer': {'description': '',
       'label': '',
       'symbol': {'name': 'Pushpin 1',
        'styleName': 'EsriIconsStyle',
        'type': 'styleSymbolReference'},
       'type': 'simple',
       'visualVariables': [{'axis': 'all',
         'minSize': 25,
         'type': 'sizeInfo',
         'valueUnit': 'unknown'}]}},
     'elevationInfo': {'mode': 'absoluteHeight'}},
    'layerType': 'ArcGISFeatureLayer',
    'opacity': 1,
    'showLabels': True,
    'title': 'Labels Q3_3',
    'url': 'http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/PacificTyphoons2005_WFL/FeatureServer/14',
    'visibility': False},
   {'id': '341d7b380907439990e4c238147b46ce',
    'layerDefinition': {'drawingInfo': {'renderer': {'description': '',
       'label': '',
       'symbol': {'name': 'Standing Cylinder',
        'styleName': 'EsriThematicShapesStyle',
        'type': 'styleSymbolReference'},
       'type': 'simple',
       'visualVariables': [{'axis': 'height',
         'field': 'windspeed',
         'minDataValue': 0.0001,
         'minSize': 1,
         'type': 'sizeInfo'},
        {'axis': 'widthAndDepth',
         'minSize': 100000,
         'type': 'sizeInfo',
         'valueUnit': 'meters'},
        {'field': 'airpressure',
         'stops': [{'color': [245, 0, 0], 'value': 920},
          {'color': [245, 245, 0], 'value': 1014}],
         'type': 'colorInfo'}]}},
     'elevationInfo': {'mode': 'absoluteHeight'}},
    'layerType': 'ArcGISFeatureLayer',
    'opacity': 1,
    'popupInfo': {'mediaInfos': [{'caption': "<div><p><span style='font-weight:bold;'>Pressure: </span><span>{airpressure} hPa</span></p><p><span style='font-weight:bold;'>Wind speed: </span><span>{wind_mph} mph / {wind_kph} kph</span></p><p><p><span style='font-weight:bold;'>Date: </span><span>{timedescription}</span></p></div></p>",
       'title': "<div><p><span style='font-weight:bold;'>{typhoonclass} {typhoon}</span></p></div>",
       'type': 'image',
       'value': {'sourceURL': '{image}'}}],
     'title': '{typhoon}'},
    'title': 'Typhoons Q3_3',
    'url': 'http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/PacificTyphoons2005_WFL/FeatureServer/13',
    'visibility': False}],
  'listMode': 'hide-children',
  'opacity': 1,
  'title': 'September',
  'visibility': False,
  'visibilityMode': 'inherited'},
 {'id': '14a37c78bc8-layer19',
  'layerType': 'GroupLayer',
  'layers': [{'id': '6e54f2736388480ab0a214cb468d48f9',
    'layerDefinition': {'drawingInfo': {'renderer': {'description': '',
       'label': '',
       'symbol': {'name': 'Pushpin 1',
        'styleName': 'EsriIconsStyle',
        'type': 'styleSymbolReference'},
       'type': 'simple',
       'visualVariables': [{'axis': 'all',
         'minSize': 25,
         'type': 'sizeInfo',
         'valueUnit': 'unknown'}]}},
     'elevationInfo': {'mode': 'absoluteHeight'}},
    'layerType': 'ArcGISFeatureLayer',
    'opacity': 1,
    'showLabels': True,
    'title': 'Labels Q3_2',
    'url': 'http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/PacificTyphoons2005_WFL/FeatureServer/11',
    'visibility': False},
   {'id': '6b549bb78d824b4c8d24f5c90b93c4f6',
    'layerDefinition': {'drawingInfo': {'renderer': {'description': '',
       'label': '',
       'symbol': {'name': 'Standing Cylinder',
        'styleName': 'EsriThematicShapesStyle',
        'type': 'styleSymbolReference'},
       'type': 'simple',
       'visualVariables': [{'axis': 'height',
         'field': 'windspeed',
         'minDataValue': 0.0001,
         'minSize': 1,
         'type': 'sizeInfo'},
        {'axis': 'widthAndDepth',
         'minSize': 100000,
         'type': 'sizeInfo',
         'valueUnit': 'meters'},
        {'field': 'airpressure',
         'stops': [{'color': [245, 0, 0], 'value': 920},
          {'color': [245, 245, 0], 'value': 1014}],
         'type': 'colorInfo'}]}},
     'elevationInfo': {'mode': 'absoluteHeight'}},
    'layerType': 'ArcGISFeatureLayer',
    'opacity': 1,
    'popupInfo': {'mediaInfos': [{'caption': "<div><p><span style='font-weight:bold;'>Pressure: </span><span>{airpressure} hPa</span></p><p><span style='font-weight:bold;'>Wind speed: </span><span>{wind_mph} mph / {wind_kph} kph</span></p><p><p><span style='font-weight:bold;'>Date: </span><span>{timedescription}</span></p></div></p>",
       'title': "<div><p><span style='font-weight:bold;'>{typhoonclass} {typhoon}</span></p></div>",
       'type': 'image',
       'value': {'sourceURL': '{image}'}}],
     'title': '{typhoon}'},
    'title': 'Typhoons Q3_2',
    'url': 'http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/PacificTyphoons2005_WFL/FeatureServer/10',
    'visibility': False}],
  'listMode': 'hide-children',
  'opacity': 1,
  'title': 'August',
  'visibility': False,
  'visibilityMode': 'inherited'},
 {'id': '14a37c4590b-layer18',
  'layerType': 'GroupLayer',
  'layers': [{'id': 'b8cc403be27e475ca93db04a34845e89',
    'layerDefinition': {'drawingInfo': {'renderer': {'description': '',
       'label': '',
       'symbol': {'name': 'Pushpin 1',
        'styleName': 'EsriIconsStyle',
        'type': 'styleSymbolReference'},
       'type': 'simple',
       'visualVariables': [{'axis': 'all',
         'minSize': 25,
         'type': 'sizeInfo',
         'valueUnit': 'unknown'}]}},
     'elevationInfo': {'mode': 'absoluteHeight'}},
    'layerType': 'ArcGISFeatureLayer',
    'opacity': 1,
    'showLabels': True,
    'title': 'Labels Q3_1',
    'url': 'http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/PacificTyphoons2005_WFL/FeatureServer/8',
    'visibility': False},
   {'id': 'e60bd6abdb094bf2b9daacd8bb57495c',
    'layerDefinition': {'drawingInfo': {'renderer': {'description': '',
       'label': '',
       'symbol': {'name': 'Standing Cylinder',
        'styleName': 'EsriThematicShapesStyle',
        'type': 'styleSymbolReference'},
       'type': 'simple',
       'visualVariables': [{'axis': 'height',
         'field': 'windspeed',
         'minDataValue': 0.0001,
         'minSize': 1,
         'type': 'sizeInfo'},
        {'axis': 'widthAndDepth',
         'minSize': 100000,
         'type': 'sizeInfo',
         'valueUnit': 'meters'},
        {'field': 'airpressure',
         'stops': [{'color': [245, 0, 0], 'value': 920},
          {'color': [245, 245, 0], 'value': 1014}],
         'type': 'colorInfo'}]}},
     'elevationInfo': {'mode': 'absoluteHeight'}},
    'layerType': 'ArcGISFeatureLayer',
    'opacity': 1,
    'popupInfo': {'mediaInfos': [{'caption': "<div><p><span style='font-weight:bold;'>Pressure: </span><span>{airpressure} hPa</span></p><p><span style='font-weight:bold;'>Wind speed: </span><span>{wind_mph} mph / {wind_kph} kph</span></p><p><p><span style='font-weight:bold;'>Date: </span><span>{timedescription}</span></p></div></p>",
       'title': "<div><p><span style='font-weight:bold;'>{typhoonclass} {typhoon}</span></p></div>",
       'type': 'image',
       'value': {'sourceURL': '{image}'}}],
     'title': '{typhoon}'},
    'title': 'Typhoons Q3_1',
    'url': 'http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/PacificTyphoons2005_WFL/FeatureServer/7',
    'visibility': False}],
  'listMode': 'hide-children',
  'opacity': 1,
  'title': 'July',
  'visibility': False,
  'visibilityMode': 'inherited'},
 {'id': '14a37c397dc-layer17',
  'layerType': 'GroupLayer',
  'layers': [{'id': '56803f3d64184140950f0ef1256a0603',
    'layerDefinition': {'drawingInfo': {'renderer': {'description': '',
       'label': '',
       'symbol': {'name': 'Pushpin 1',
        'styleName': 'EsriIconsStyle',
        'type': 'styleSymbolReference'},
       'type': 'simple',
       'visualVariables': [{'axis': 'all',
         'minSize': 25,
         'type': 'sizeInfo',
         'valueUnit': 'unknown'}]}},
     'elevationInfo': {'mode': 'absoluteHeight'}},
    'layerType': 'ArcGISFeatureLayer',
    'opacity': 1,
    'showLabels': True,
    'title': 'Labels Q2',
    'url': 'http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/PacificTyphoons2005_WFL/FeatureServer/5',
    'visibility': False},
   {'id': '72668fcc8a904bd6a1444bef2e72f420',
    'layerDefinition': {'drawingInfo': {'renderer': {'description': '',
       'label': '',
       'symbol': {'name': 'Standing Cylinder',
        'styleName': 'EsriThematicShapesStyle',
        'type': 'styleSymbolReference'},
       'type': 'simple',
       'visualVariables': [{'axis': 'height',
         'field': 'windspeed',
         'minDataValue': 0.0001,
         'minSize': 1,
         'type': 'sizeInfo'},
        {'axis': 'widthAndDepth',
         'minSize': 100000,
         'type': 'sizeInfo',
         'valueUnit': 'meters'},
        {'field': 'airpressure',
         'stops': [{'color': [245, 0, 0], 'value': 920},
          {'color': [245, 245, 0], 'value': 1014}],
         'type': 'colorInfo'}]}},
     'elevationInfo': {'mode': 'absoluteHeight'}},
    'layerType': 'ArcGISFeatureLayer',
    'opacity': 1,
    'popupInfo': {'mediaInfos': [{'caption': "<div><p><span style='font-weight:bold;'>Pressure: </span><span>{airpressure} hPa</span></p><p><span style='font-weight:bold;'>Wind speed: </span><span>{wind_mph} mph / {wind_kph} kph</span></p><p><p><span style='font-weight:bold;'>Date: </span><span>{timedescription}</span></p></div></p>",
       'title': "<div><p style='font-weight:bold;'><span>{typhoonclass} {typhoon}</span></p></div>",
       'type': 'image',
       'value': {'sourceURL': '{image}'}}],
     'title': '{typhoon}'},
    'title': 'Typhoons Q2',
    'url': 'http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/PacificTyphoons2005_WFL/FeatureServer/4',
    'visibility': False}],
  'listMode': 'hide-children',
  'opacity': 1,
  'title': 'April - June',
  'visibility': False,
  'visibilityMode': 'inherited'},
 {'id': '14a37c2a1a7-layer16',
  'layerType': 'GroupLayer',
  'layers': [{'id': '16c9bf0e374443d394f0b77980171499',
    'layerDefinition': {'drawingInfo': {'renderer': {'description': '',
       'label': '',
       'symbol': {'name': 'Pushpin 1',
        'styleName': 'EsriIconsStyle',
        'type': 'styleSymbolReference'},
       'type': 'simple',
       'visualVariables': [{'axis': 'all',
         'minSize': 25,
         'type': 'sizeInfo',
         'valueUnit': 'unknown'}]}},
     'elevationInfo': {'mode': 'absoluteHeight'}},
    'layerType': 'ArcGISFeatureLayer',
    'opacity': 1,
    'showLabels': True,
    'title': 'Labels Q1',
    'url': 'http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/PacificTyphoons2005_WFL/FeatureServer/2',
    'visibility': True},
   {'id': '3921d1e5c45c41b4a0b498df8fab4e2c',
    'layerDefinition': {'drawingInfo': {'renderer': {'description': '',
       'label': '',
       'symbol': {'name': 'Standing Cylinder',
        'styleName': 'EsriThematicShapesStyle',
        'type': 'styleSymbolReference'},
       'type': 'simple',
       'visualVariables': [{'axis': 'height',
         'field': 'windspeed',
         'minDataValue': 0.0001,
         'minSize': 1,
         'type': 'sizeInfo'},
        {'axis': 'widthAndDepth',
         'minSize': 100000,
         'type': 'sizeInfo',
         'valueUnit': 'meters'},
        {'field': 'airpressure',
         'stops': [{'color': [245, 0, 0], 'value': 920},
          {'color': [245, 245, 0], 'value': 1014}],
         'type': 'colorInfo'}]}},
     'elevationInfo': {'mode': 'absoluteHeight'}},
    'layerType': 'ArcGISFeatureLayer',
    'opacity': 1,
    'popupInfo': {'mediaInfos': [{'caption': "<div><p><span style='font-weight:bold;'>Pressure: </span><span>{airpressure} hPa</span></p><p><span style='font-weight:bold;'>Wind speed: </span><span>{wind_mph} mph / {wind_kph} kph</span></p><p><p><span style='font-weight:bold;'>Date: </span><span>{timedescription}</span></p></div></p>",
       'title': "<div><p style='font-weight:bold;'><span>{typhoonclass} {typhoon}</span></p></div>",
       'type': 'image',
       'value': {'sourceURL': '{image}'}}],
     'title': '{typhoon}'},
    'title': 'Typhoons Q1',
    'url': 'http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/PacificTyphoons2005_WFL/FeatureServer/1',
    'visibility': True}],
  'listMode': 'hide-children',
  'opacity': 1,
  'title': 'January - March',
  'visibility': True,
  'visibilityMode': 'inherited'}]

There is a lot of information displayed above. Let us drill into this and display only layer names and their urls. If you notice, some of the layers above are group layers, meaning, they contain sub layers. So let us write a loop like below and print some details.

for layer in web_scene_obj['operationalLayers']:
    print(layer['title'] + " :: " + layer['layerType'])
    if layer['layerType'] == 'GroupLayer':
        for sub_layer in layer['layers']:
            print("\t" + sub_layer['title'] + " :: "+ sub_layer['url'])
Typhoon Paths :: ArcGISFeatureLayer
October - December :: GroupLayer
	Labels Q4 :: http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/PacificTyphoons2005_WFL/FeatureServer/17
	Typhoons Q4 :: http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/PacificTyphoons2005_WFL/FeatureServer/16
September :: GroupLayer
	Labels Q3_3 :: http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/PacificTyphoons2005_WFL/FeatureServer/14
	Typhoons Q3_3 :: http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/PacificTyphoons2005_WFL/FeatureServer/13
August :: GroupLayer
	Labels Q3_2 :: http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/PacificTyphoons2005_WFL/FeatureServer/11
	Typhoons Q3_2 :: http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/PacificTyphoons2005_WFL/FeatureServer/10
July :: GroupLayer
	Labels Q3_1 :: http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/PacificTyphoons2005_WFL/FeatureServer/8
	Typhoons Q3_1 :: http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/PacificTyphoons2005_WFL/FeatureServer/7
April - June :: GroupLayer
	Labels Q2 :: http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/PacificTyphoons2005_WFL/FeatureServer/5
	Typhoons Q2 :: http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/PacificTyphoons2005_WFL/FeatureServer/4
January - March :: GroupLayer
	Labels Q1 :: http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/PacificTyphoons2005_WFL/FeatureServer/2
	Typhoons Q1 :: http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/PacificTyphoons2005_WFL/FeatureServer/1

We are only interested in the layers that correspond to cyclones in summer. From the above report, we understand that information is in a group layer with two sub layers. Let us extract just that dictionary and compose a new web scene data.

# Let us construct a list comprehension and mine out that group layer.
subset_op_layers = [subset for subset in web_scene_obj['operationalLayers'] if subset['title'] == 'April - June']
display(subset_op_layers)
[{'id': '14a37c397dc-layer17',
  'layerType': 'GroupLayer',
  'layers': [{'id': '56803f3d64184140950f0ef1256a0603',
    'layerDefinition': {'drawingInfo': {'renderer': {'description': '',
       'label': '',
       'symbol': {'name': 'Pushpin 1',
        'styleName': 'EsriIconsStyle',
        'type': 'styleSymbolReference'},
       'type': 'simple',
       'visualVariables': [{'axis': 'all',
         'minSize': 25,
         'type': 'sizeInfo',
         'valueUnit': 'unknown'}]}},
     'elevationInfo': {'mode': 'absoluteHeight'}},
    'layerType': 'ArcGISFeatureLayer',
    'opacity': 1,
    'showLabels': True,
    'title': 'Labels Q2',
    'url': 'http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/PacificTyphoons2005_WFL/FeatureServer/5',
    'visibility': False},
   {'id': '72668fcc8a904bd6a1444bef2e72f420',
    'layerDefinition': {'drawingInfo': {'renderer': {'description': '',
       'label': '',
       'symbol': {'name': 'Standing Cylinder',
        'styleName': 'EsriThematicShapesStyle',
        'type': 'styleSymbolReference'},
       'type': 'simple',
       'visualVariables': [{'axis': 'height',
         'field': 'windspeed',
         'minDataValue': 0.0001,
         'minSize': 1,
         'type': 'sizeInfo'},
        {'axis': 'widthAndDepth',
         'minSize': 100000,
         'type': 'sizeInfo',
         'valueUnit': 'meters'},
        {'field': 'airpressure',
         'stops': [{'color': [245, 0, 0], 'value': 920},
          {'color': [245, 245, 0], 'value': 1014}],
         'type': 'colorInfo'}]}},
     'elevationInfo': {'mode': 'absoluteHeight'}},
    'layerType': 'ArcGISFeatureLayer',
    'opacity': 1,
    'popupInfo': {'mediaInfos': [{'caption': "<div><p><span style='font-weight:bold;'>Pressure: </span><span>{airpressure} hPa</span></p><p><span style='font-weight:bold;'>Wind speed: </span><span>{wind_mph} mph / {wind_kph} kph</span></p><p><p><span style='font-weight:bold;'>Date: </span><span>{timedescription}</span></p></div></p>",
       'title': "<div><p style='font-weight:bold;'><span>{typhoonclass} {typhoon}</span></p></div>",
       'type': 'image',
       'value': {'sourceURL': '{image}'}}],
     'title': '{typhoon}'},
    'title': 'Typhoons Q2',
    'url': 'http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/PacificTyphoons2005_WFL/FeatureServer/4',
    'visibility': False}],
  'listMode': 'hide-children',
  'opacity': 1,
  'title': 'April - June',
  'visibility': False,
  'visibilityMode': 'inherited'}]
# Let us apply the changes to a new web scene object.
new_web_scene_obj = web_scene_obj
new_web_scene_obj['operationalLayers'] = subset_op_layers

Update basemap of new web scene

We now have the necessary operationalLayers information. Let us also try to change the basemap to a darker shade. First let us search the basemaps available in the current portal. If no suitable one is found, we can widen the search outside the organization and use a basemap published by Esri.

Basemaps are web maps that are stored in a group usually called Basemaps. Thus to get the list of basemaps available on a portal, we can find the basemaps group and list all web maps that are a part of it.

To get the list of groups on the portal, we use groups property of the GIS class.

basemap_search = gis.content.search('title:dark', 
                                    outside_org=True, item_type='web map')
for item in basemap_search:
    display(item)
    print(item.tags)
Dark Gray Canvas
Web Map by arcgis_python
Last Modified: July 05, 2017
0 comments, 0 views
['basemap', 'esri_basemap', 'vector', 'canvas', 'dark', 'esri_vector']
Dark Gray Canvas
Web Map by arcgis_python
Last Modified: July 05, 2017
0 comments, 0 views
['neutral', 'subdued', 'canvas', 'shaded', 'world', 'Global', 'basemap', 'current', 'gray', 'grey', 'dark gray', 'dark grey', 'esri', 'esri_basemap']
Dark Gray Canvas (WGS84)
Web Map by arcgis_python
Last Modified: July 05, 2017
0 comments, 0 views
['basemap', 'esri_basemap', 'world', 'global', 'AFA250_base', 'maps', 'WGS84', 'GCS', 'wkid 4326', 'vector', 'esri_vector', 'dark', 'canvas', 'v1', 'general availability']
Dark Gray Canvas
This map is designed to focus attention on your thematic content by providing a neutral background with minimal colors, labels, and features.Web Map by esri_en
Last Modified: October 29, 2014
0 comments, 0 views
['basemap']
Dark Gray Canvas
Ova mapa dizajnirana je tako da usmeri pažnju na tematski sadržaj vaše mape pomoću neutralne pozadine sa minimalnim brojem boja, oznaka i funkcija.Web Map by esri_sr
Last Modified: April 28, 2016
0 comments, 0 views
['pozadinska mapa']

We have found the basemap of our choice. Let us read it as a WebMap object and query the baseMap dictionary.

dark_basemap_item = basemap_search[1]
dark_basemap_obj = arcgis.mapping.WebMap(dark_basemap_item)
dark_basemap_obj['baseMap']
{'baseMapLayers': [{'id': 'layer0',
   'layerType': 'ArcGISTiledMapServiceLayer',
   'opacity': 1,
   'title': 'World_Dark_Gray_Base',
   'url': 'https://services.arcgisonline.com/arcgis/rest/services/Canvas/World_Dark_Gray_Base/MapServer',
   'visibility': True},
  {'id': 'World_Dark_Gray_Reference_8618',
   'isReference': True,
   'layerType': 'ArcGISTiledMapServiceLayer',
   'opacity': 1,
   'title': 'World_Dark_Gray_Reference',
   'url': 'https://services.arcgisonline.com/arcgis/rest/services/Canvas/World_Dark_Gray_Reference/MapServer',
   'visibility': True}],
 'title': 'Dark Gray Canvas'}

Now let us explore how the baseMap dictionary of the web scene looks like.

new_web_scene_obj['baseMap']
{'baseMapLayers': [{'id': '73e9780a7d6f413f8547abbd19ec786c',
   'layerType': 'ArcGISTiledMapServiceLayer',
   'url': 'http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer'}],
 'elevationLayers': [{'id': 'globalElevation_0',
   'layerType': 'ArcGISTiledElevationServiceLayer',
   'url': 'http://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer'}],
 'id': 'basemap',
 'title': 'Topographic',
 'visibility': True}

To get the desired basemap, we need to update the only url key-value pair of the web scene's baseMap dictionary. Here we will only pick the first layer of the dark basemap web map.

new_web_scene_obj['baseMap']['baseMapLayers'][0]['url'] = \
dark_basemap_obj['baseMap']['baseMapLayers'][0]['url']

Now that we have performed the necessary updates, we can go ahead and publish this as a new web scene item on our portal.

new_web_scene_properties= {'title':'Toprical Cyclones - Summer',
                          'type' : 'Web Scene',
                          'tags' : 'ArcGIS Python API',
                          'snippet' : str.format('Subset of <a href={2}>{0}</a> published by {1}',
                                                 web_scene_item.title, web_scene_item.owner,
                                                "https://www.arcgis.com/home/item.html?id=" + web_scene_item.id),
                          'text' : json.dumps(new_web_scene_obj)}

new_item = gis.content.add(new_web_scene_properties)
new_item
Toprical Cyclones - Summer
Subset of Western Pacific Typhoons (2005) published by arcgis_pythonWeb Scene by arcgis_python
Last Modified: July 05, 2017
0 comments, 0 views

We have successfully published the new web scene. Now let us display in an interactive widget and observe if it has the necessary updates.

new_item.share(True)
new_web_scene_obj = arcgis.mapping.WebScene(new_item)
new_web_scene_obj

Our required updates have been applied to the new web scene. However notice the April - June layer is turned off by default. Let us fix that and update the web scene.

Let us query the operationalLayer dictionary of the new web scene and look for a key called visibility.

for layer in new_web_scene_obj['operationalLayers']:
    print(layer['visibility'])
False

As we know, there is just 1 group layer and it is turned off. Let us change that and update the web scene.

for layer in new_web_scene_obj['operationalLayers']:
    layer['visibility'] = True

To update the web scene call the update() method on the web scene object.

new_web_scene_obj.update()
new_web_scene_obj

Summary

In this sample, we observed how to consume web maps, web scenes and how to update them. During this process, the sample showed how to read a web feature layers, how to use geocoding to get co-ordinates of a point of interest, how to modify the map widget using code, how to make copy of an existing item into your account, how to look for basemaps and finally, how to update layer properties within a web scene.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.