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", "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.
search_result = gis.content.search("title:Ebola treatment locations", item_type = "Web Map")
display(search_result)
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
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]
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
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'})
Check the layers on the web map
for lyr in web_map_obj.layers:
print(lyr.title + " " + lyr.url)
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")
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]
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