HOW TO
An existing service metadata can be copied to a new item in ArcGIS Online or ArcGIS Enterprise using the ArcGIS API for Python. This can be particularly helpful to maintain uniformity throughout the whole organization in when multiple data is involved.
The following procedure describes how to copy the metadata from an existing service. There are two ways to copy the metadata, from a feature layer, and from a map service.
Using Feature layer
import arcgis from arcgis.gis import GIS from arcgis.features import FeatureLayer
gis = GIS("https://arcgis.com", "Username", "Password") url = '<Feature Layer Service URL>' layer = FeatureLayer(url)
itemTags = layer.properties.documentInfo.Keywords itemDescription = layer.properties.serviceDescription itemSnippet = layer.properties.documentInfo.Subject itemTitle = layer.properties.documentInfo.Title
wmsUrl = '<URL to the service>' props = {'title': itemTitle, 'type': 'Feature Service', 'url': '<URL to the service>', 'tags': itemTags, 'description': itemDescription, 'snippet': itemSnippet} wmsItem = gis.content.add(item_properties=props, data=wmsUrl)The following shows a sample of the full script:
import arcgis from arcgis.gis import GIS from arcgis.features import FeatureLayer gis = GIS("https://arcgis.com", "Username", "Password") url = 'https://services.arcgis.com/Wl7Y1m92PbjtJs5n/arcgis/rest/services/workers_dec6d6e11b564e338fb3254626cee2f0/FeatureServer' layer = FeatureLayer(url) itemTags = layer.properties.documentInfo.Keywords itemDescription = layer.properties.serviceDescription itemSnippet = layer.properties.documentInfo.Subject itemTitle = layer.properties.documentInfo.Title wmsUrl = 'https://domain.esri.com:6443/arcgis/rest/services' props = {'title': itemTitle, 'type': 'Feature Service', 'url': 'https://domain.esri.com:6443/arcgis/rest/services', 'tags': itemTags, 'description': itemDescription, 'snippet': itemSnippet} wmsItem = gis.content.add(item_properties=props, data=wmsUrl)Using Map Service
import arcgis from arcgis.gis import GIS from arcgis.mapping import MapImageLayer
gis = GIS("https://arcgis.com", "Username", "Password") url = '<Map Service URL>' layer = MapImageLayer(url)
itemTags = layer.item_info['tags'] itemDescription = layer.item_info['description'] itemSnippet = layer.item_info['summary'] itemTitle = layer.item_info['title'] itemTumbnail = layer.thumbnail()
wmsUrl = '<URL to the service>' props = {'title': itemTitle, 'type': 'Map Service', 'url': '<Url to the service>', 'tags': itemTags, 'description': itemDescription, 'snippet': itemSnippet} wmsItem = gis.content.add(item_properties=props, data=wmsUrl, thumbnail= itemTumbnail)The following shows a sample of the full script:
import arcgis from arcgis.gis import GIS from arcgis.mapping import MapImageLayer gis = GIS("https://arcgis.com", "Username", "Password") url = 'https://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/MapServer' layer = MapImageLayer(url) itemTags = layer.item_info['tags'] itemDescription = layer.item_info['description'] itemSnippet = layer.item_info['summary'] itemTitle = layer.item_info['title'] itemTumbnail = layer.thumbnail() wmsUrl = 'https://domain.esri.com:6443/arcgis/rest/services' props = {'title': itemTitle, 'type': 'Map Service', 'url': 'https://domain.esri.com:6443/arcgis/rest/services', 'tags': itemTags, 'description': itemDescription, 'snippet': itemSnippet} wmsItem = gis.content.add(item_properties=props, data=wmsUrl, thumbnail= itemTumbnail)
Get help from ArcGIS experts
Download the Esri Support App