Skip to content

Instantly share code, notes, and snippets.

@nommuna2
Last active April 26, 2019 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nommuna2/211856c1182bdc9855307d5ab7cd2d24 to your computer and use it in GitHub Desktop.
Save nommuna2/211856c1182bdc9855307d5ab7cd2d24 to your computer and use it in GitHub Desktop.
(ArcGIS API for Python) Copying metadata from an existing service to a new item through a REST endpoint using the Python API
#Using a feature layer
import arcgis
from arcgis.gis import GIS
from arcgis.features import FeatureLayer
gis = GIS()
# Use the FeatureLayer class to get item from an service endpoint
url = 'https://idpgis.ncep.noaa.gov/arcgis/rest/services/NWS_Climate_Outlooks/cpc_6_10_day_outlk/MapServer'
layer = FeatureLayer(url)
#Set the metadata from the service to variables.
itemTags = layer.properties.documentInfo.Keywords
itemDescription = layer.properties.serviceDescription
itemSnippet = layer.properties.documentInfo.Subject
itemTitle = layer.properties.documentInfo.Title
# Make a new item in your AGOL with the information from the other service.
wmsUrl = 'https://walrus.wr.usgs.gov/namss/wms'
props = {'title': itemTitle, 'type': 'Feature Service', 'url': 'https://walrus.wr.usgs.gov/namss/wms', 'tags': itemTags, 'description': itemDescription, 'snippet': itemSnippet}
wmsItem = gis.content.add(item_properties=props, data=wmsUrl)
import arcgis
from arcgis.gis import GIS
from arcgis.mapping import MapImageLayer
gis = GIS()
# Use the MapImageLayer class to get item from an service endpoint
url = 'https://idpgis.ncep.noaa.gov/arcgis/rest/services/NWS_Climate_Outlooks/cpc_6_10_day_outlk/MapServer'
layer = MapImageLayer(url)
#Set the metadata from the service to variables.
itemTags = layer.item_info['tags']
itemDescription = layer.item_info['description']
itemSnippet = layer.item_info['summary']
itemTitle = layer.item_info['title']
itemTumbnail = layer.thumbnail()
# Make a new item in your AGOL with the information from the other service.
wmsUrl = 'https://walrus.wr.usgs.gov/namss/wms'
props = {'title': itemTitle, 'type': 'Map Service', 'url': 'https://walrus.wr.usgs.gov/namss/wms', 'tags': itemTags, 'description': itemDescription, 'snippet': itemSnippet}
wmsItem = gis.content.add(item_properties=props, data=wmsUrl, thumbnail= itemTumbnail)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment