In [1]:
from arcgis.gis import GIS
from getpass import getpass
from IPython.display import display
In [2]:
# Get username and password
username = input('Username: ')
password = getpass(prompt='Password: ')
In [3]:
# Connect to portal
gis = GIS("https://arcgis.com/", username, password)
In [4]:
user = gis.users.get(username)
user
Out[4]:
Portals allows users to store and share a variety of items. Each item has a type, such as Web Map or Feature Service, and a set of type keywords that provide additional information on the characteristics of the type.
See Items and item types for more information.
In [5]:
title = input("Feature class to search for: ")
In [6]:
items = gis.content.search(query="title:'" + title + "' AND owner:" + username, item_type="Feature Service")
print(type(items), len(items))
print(type(items[0]))
In [7]:
item = items[0]
item
Out[7]:
In [8]:
item.tags
Out[8]:
In [9]:
# First set up some variables for input ot the *update* method.
thumbnail_path = "c:/temp/Hospitals.JPG"
tags = list(item.tags)
tags.append("health")
item_properties = {"snippet": "Location of Cambridge hospitals.",
"title": "Cambridge Hospitals",
"tags": ','.join(tags),
"accessinformation": "City of Cambridge GIS",
"licenseInfo": "License Info"
}
In [10]:
# Then perform the update
item.update(item_properties, thumbnail=thumbnail_path)
item
Out[10]:
In [11]:
# Get the updated *item*
items[0].tags
Out[11]:
Removing the display code and reducing the above to just what's needed to update the metadata shows that the Python API requires very little code to update an item's metadata. Error handling would need to be added for production, but that is required whether you use the Python API or interact with the REST API directly.
# ##### Import the GIS module and other needed Python modules
from arcgis.gis import GIS
from getpass import getpass
# ##### Create the GIS object and point it to AGOL
# Get username and password
username = input('Username: ')
password = getpass(prompt='Password: ')
# Connect to portal
gis = GIS("https://arcgis.com/", username, password)
# ##### Get the item that you want to update
title = input("Feature class to search for: ")
items = gis.content.search(query="title:'" + title + "' AND owner:" + username, item_type="Feature Service")
item = items[0]
# ##### Update the metadata
# First set up some variables for input ot the *update* method.
thumbnail_path = "c:/temp/Hospitals.JPG"
tags = list(item.tags)
tags.append("health")
item_properties = {"snippet": "Location of Cambridge hospitals.",
"title": "Cambridge Hospitals",
"tags": ','.join(tags),
"accessinformation": "City of Cambridge GIS",
"licenseInfo": "License Info"
}
# Then perform the update
item.update(item_properties, thumbnail=thumbnail_path)