Skip To Content ArcGIS for Developers Sign In Dashboard

Accessing and creating content

Your GIS can host a variety of maps, web layers, analytical tools, apps and individual files. Using the gis module, you can search for, access and manage all your folders, contents and automate such maintenance workflows as scripts.

In this page, we are going to observe how the following can be accomplished:

In [45]:
import os
import shutil
import datetime as dt

import pandas 

from arcgis.gis import GIS

Searching for content

Accessing the content property of your gis object returns you an instance of ContentManager class. You can use the search() method of the ContentManager object to search for items on your GIS. You can use the search() even if you are connected as an anonymous user, in which case you get to search for public content on ArcGIS Online.

The first step is to import the API and connect to your GIS

In [2]:
from arcgis.gis import GIS
gis = GIS(profile="your_enterprise_profile")

Lets see what you get when you access content property

In [3]:
type(gis.content)
Out[3]:
arcgis.gis.ContentManager

As explained earlier, we don't recommend creating an instance of the ContentManager directly, but instead recommed accessing it through the content property of your GIS object as shown below:

In [4]:
search_result = gis.content.search(query="title:Ports along US West Coast", item_type="Feature Layer")
search_result
Out[4]:
[<Item title:"Ports in the Western US" type:Feature Layer Collection owner:api_data_owner>]

The search() method returned us a list of Item objects that matched the search criteria and that the logged in user had permissions to access. The query parameter supports a variety of inputs, refer to the search reference for more ideas on what is supported. Some typical examples are shown below:

In [5]:
# search and list all feature layers in my contents
search_result = gis.content.search(query="", item_type="Feature Layer")
search_result
Out[5]:
[<Item title:"Ports in the Western US" type:Feature Layer Collection owner:api_data_owner>,
 <Item title:"TargetPools_JoinParcels_Within" type:Feature Layer Collection owner:rohitgeo>,
 <Item title:"Copy_to_Data_Store_for_PoolsInRedlands" type:Feature Layer Collection owner:rohitgeo>,
 <Item title:"TargetParcels_JoinTargetPools_Intersects" type:Feature Layer Collection owner:rohitgeo>,
 <Item title:"ParcelsWithPools" type:Feature Layer Collection owner:rohitgeo>,
 <Item title:"PoolsCompletelyWithinRedlandsSFRParcels" type:Feature Layer Collection owner:rohitgeo>,
 <Item title:"Chennai_precipitation_FS" type:Feature Layer Collection owner:api_data_owner>,
 <Item title:"Join_Features_to_Parcels_for_San_Bernardino_County" type:Feature Layer Collection owner:rohitgeo>,
 <Item title:"ParcelsWithNeglectedPoolsInRedlands" type:Feature Layer Collection owner:rohitgeo>,
 <Item title:"Parcels_with_Pools_in_Redlands" type:Feature Layer Collection owner:rohitgeo>]

Notice how the search result includes items owned by other users that are shared across the organization. You can limit the search to only your content by specifying that in the query string as shown below:

In [6]:
search_my_contents = gis.content.search(query="owner:arcgis_python", 
                                        item_type="Feature *")
search_my_contents
Out[6]:
[]

Search supports usage of wild cards. You can use one asterisk * for multiple character wild card search and one question mark ? for single character.

In [7]:
search_result_USA = gis.content.search(query="title:USA*")                  
search_result_USA
Out[7]:
[<Item title:"USA West Region" type:Mobile Map Package owner:esri_nav>,
 <Item title:"USA Midwest Region" type:Mobile Map Package owner:esri_nav>,
 <Item title:"USA South Region" type:Mobile Map Package owner:esri_nav>,
 <Item title:"USA MD-OH-PA-WV Region" type:Mobile Map Package owner:esri_nav>,
 <Item title:"USA Northeast Region" type:Mobile Map Package owner:esri_nav>]

Searching for content outside your portal

So far, we searched for content that belonged to the logged in user, as well as items shared within the portal and published by built-in accounts and other named users in the same portal. When connected to ArcGIS Online or connected to ArcGIS Enterprise configured to access ArcGIS Online, you can also search for content published and shared publicly even if the named users are in other portals. You can do so by turning the outside_org flag to True.

In [8]:
# search for content that begin with a prefix - say 'USA'
search_result_USA = gis.content.search(query="title:USA*", outside_org=True)                  
search_result_USA
Out[8]:
[<Item title:"USA Historic Sites" type:Feature Layer Collection owner:esri_livingatlas>,
 <Item title:"USA Federal Lands" type:Feature Layer Collection owner:esri_livingatlas>,
 <Item title:"USA Wilderness" type:Feature Layer Collection owner:esri_livingatlas>,
 <Item title:"USA Protected Areas" type:Feature Layer Collection owner:esri_livingatlas>,
 <Item title:"USA Native Lands" type:Feature Layer Collection owner:esri_livingatlas>,
 <Item title:"USA Critical Habitat" type:Feature Layer Collection owner:esri_livingatlas>,
 <Item title:"USA Topo Maps" type:Map Image Layer owner:esri_livingatlas>,
 <Item title:"USA Bureau of Reclamation Lands" type:Feature Layer Collection owner:esri_livingatlas>,
 <Item title:"USA Department of Defense Lands" type:Feature Layer Collection owner:esri_livingatlas>,
 <Item title:"USA Forest Service Lands" type:Feature Layer Collection owner:esri_livingatlas>]

Notice the Living Atlas content returned in the results. The portal administrator configured the portal to access Living Atlas centent.

When using the Jupyter notebook environment, you can utilize the rich representation of items for your query results.

In [9]:
from IPython.display import display
for item in search_result_USA:
    display(item)
USA Historic Sites
Historic Sites from the Protected Areas Database of the United States.Feature Layer Collection by esri_livingatlas
Last Modified: January 14, 2019
0 comments, 0 views
USA Federal Lands
This layer displays lands in the United States managed by six federal agencies.Feature Layer Collection by esri_livingatlas
Last Modified: January 14, 2019
0 comments, 0 views
USA Wilderness
This layer displays lands protected by the National Wilderness Preservation System of the United States.Feature Layer Collection by esri_livingatlas
Last Modified: January 14, 2019
0 comments, 0 views
USA Protected Areas
This layer displays all lands contained in the Protected Areas Database of the United States.Feature Layer Collection by esri_livingatlas
Last Modified: January 14, 2019
0 comments, 0 views
USA Native Lands
This layer displays lands owned or managed by Native American Tribes and other native people of the United States.Feature Layer Collection by esri_livingatlas
Last Modified: January 14, 2019
0 comments, 0 views
USA Critical Habitat
Proposed and Final Critical Habitat designated under the U.S. Endangered Species Act.Feature Layer Collection by esri_livingatlas
Last Modified: January 14, 2019
0 comments, 0 views
USA Topo Maps
This layer presents detailed USGS topographic maps for the United States at multiple scales. Map Image Layer by esri_livingatlas
Last Modified: January 14, 2019
0 comments, 0 views
USA Bureau of Reclamation Lands
This layer displays lands managed by the U.S. Bureau of Reclamation.Feature Layer Collection by esri_livingatlas
Last Modified: January 14, 2019
0 comments, 0 views
USA Department of Defense Lands
This layer displays lands managed by the U.S. Department of Defense.Feature Layer Collection by esri_livingatlas
Last Modified: January 14, 2019
0 comments, 0 views
USA Forest Service Lands
Lands managed by the United States Forest Service including National Forests and National Grasslands.Feature Layer Collection by esri_livingatlas
Last Modified: January 14, 2019
0 comments, 0 views

Once you know an item's id (called itemId), you can access it using the get() method instead of searching for it.

In [10]:
# lets get the itemid of first item from previous query
first_item = search_result_USA[0]
known_item_id = first_item.id
print(known_item_id)
d530f9ac148f45ddbcfa6f479931aebc
In [11]:
# lets use the get() to access this item
online_historic_item = gis.content.get(known_item_id)
online_historic_item
Out[11]:
USA Historic Sites
Historic Sites from the Protected Areas Database of the United States.Feature Layer Collection by esri_livingatlas
Last Modified: January 14, 2019
0 comments, 0 views

Searching for content in ArcGIS Online

So far, we searched for content accessible to a user logged into ArcGIS Enterprise. Let's connect directly to an ArcGIS Online Organization and futher explore ways to search for web GIS content.

In [12]:
# connect to ArcGIS Online
gis2 = GIS(profile="your_online_profile")

Let us search for public web scenes visualizing 3D cities.

Note: , Use the sort_field parameter to order the content that is returned. In this case, the results are ordered with most larger number of views returned first. The max_items parameter can restrict the number of results returned, which can help with slow queries or queries with many possible results.

In [13]:
public_3d_city_scenes = gis2.content.search(query="3d cities", item_type = "web scene",
                                           sort_field="numViews" ,sort_order="asc",
                                           max_items = 15, outside_org=True)
for item in public_3d_city_scenes:
    display(item)
3D Cities - Nederland
Deze webscene bevat 3D-gebouwen van een aantal gemeenten. De gebouwen van deze gemeenten hebben het LOD2 detailniveau. Dit wil zeggen dat het gebouwen zijn met dakvorm.Web Scene by Esri_NL_Content
Last Modified: May 28, 2019
0 comments, 5,061 views
3D Gebouwhoogte NL
Deze web scene bevat een global scene layer die gebaseerd is op de 3D Gebouwhoogte NL van het Kadaster, waarin de hoogte uit het AHN2 aan de gebouwen van de TOP10NL is gekoppeld.Web Scene by Esri_NL_Content
Last Modified: May 28, 2019
0 comments, 1,707 views
BAG 3D - Nederland
Deze scene bevat de BAG-gebouwen in 3D in Nederland. Via de dia's onderin is het mogelijk om naar een andere provincie te navigeren.Web Scene by Esri_NL_Content
Last Modified: May 28, 2019
0 comments, 5,831 views
Visualize New Developments
Understand proposed changes in the context of your 3D City. Communicate changes with stakeholders and solicit public feedback.Web Scene by esri_3d
Last Modified: April 30, 2018
7 comments, 177,579 views
Berlin Alexanderplatz in 3D
Demo WebScene for the public transportation at Alexanderplatz, Berlin.Web Scene by O.Ertac4org
Last Modified: May 23, 2018
1 comments, 1,168 views
Linz, Austria Scene
This scene highlights layers for Linz, Austria available in ArcGIS to support your work in 3D. Use these layers in conjunction with your own layers to create new scenes focused on a specific topic or area of interest to you.Web Scene by esri_3d
Last Modified: April 30, 2018
1 comments, 11,417 views
Berlin, Germany Scene
This scene highlights layers for Berlin, Germany available in ArcGIS to support your work in 3D. Use these layers in conjunction with your own layers to create new scenes focused on a specific topic or area of interest to you.Web Scene by esri_3d
Last Modified: April 30, 2018
0 comments, 37,762 views
Brest, France Scene
This scene highlights layers for Brest, France available in ArcGIS to support your work in 3D. Use these layers in conjunction with your own layers to create new scenes focused on a specific topic or area of interest to you.Web Scene by esri_3d
Last Modified: April 30, 2018
0 comments, 2,657 views
Auckland, New Zealand Scene
This scene highlights layers for Auckland, New Zealand available in ArcGIS to support your work in 3D. Use these layers in conjunction with your own layers to create new scenes focused on a specific topic or area of interest to you.Web Scene by esri_3d
Last Modified: October 30, 2018
0 comments, 12,258 views
Vancouver, Canada Scene
This scene highlights layers for Vancouver, Canada available in ArcGIS to support your work in 3D. Use these layers in conjunction with your own layers to create new scenes focused on a specific topic or area of interest to you.Web Scene by esri_3d
Last Modified: June 08, 2017
0 comments, 5,843 views
Basel, Switzerland Scene
This scene highlights layers for Basel, Switzerland available in ArcGIS to support your work in 3D. Use these layers in conjunction with your own layers to create new scenes focused on a specific topic or area of interest to you.Web Scene by esri_3d
Last Modified: May 02, 2018
0 comments, 4,893 views
Rotterdam, the Netherlands Scene
This scene highlights layers for Rotterdam, The Netherlands available in ArcGIS to support your work in 3D. Use these layers in conjunction with your own layers to create new scenes focused on a specific topic or area of interest to you.Web Scene by esri_3d
Last Modified: April 30, 2018
0 comments, 37,129 views
Portland, Oregon USA Scene
This scene highlights layers for Portland, Oregon available in ArcGIS to support your work in 3D. Use these layers in conjunction with your own layers to create new scenes focused on a specific topic or area of interest to you.Web Scene by esri_3d
Last Modified: April 30, 2018
0 comments, 16,180 views