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.
In [1]:
from arcgis.gis import GIS
from IPython.display import display

gis = GIS("", "arcgis_python", "amazing_arcgis_123")

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.

In [2]:
search_result ="title:Ebola treatment locations", item_type = "Web Map")
[<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

In [3]:
wm_item = search_result[1]

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

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.

In [5]:
   "id": "layer1",
   "layerType": "ArcGISFeatureLayer",
   "url": "",
   "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.

In [7]:
search_result ='title:Ebola_Facilities', item_type = 'Feature Service')

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

In [9]:
search_result ='title:Ebola', item_type='Feature Layer')
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

In [10]:
ebola = search_result[0]
[<FeatureLayer url:"">,
 <FeatureLayer url:"">]

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.

In [11]:
# remove the old layer from the web map
In [12]:
# 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'})

Check the layers on the web map

In [14]:
for lyr in web_map_obj.layers:
    print(lyr.title + " " + lyr.url)
Ebola_Treatment_Units - Ebola_Treatment_Units_Classed

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.

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

Query the web map object to visualize it in the notebook

In [20]:

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.

In [ ]:
search_result ='title:Western Pacific Typhoons (2005)', 
                                   item_type = 'Web Scene', outside_org = True)
Out[ ]:
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.

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

# display web scene in the notebook