HOW TO

Download markup layers from ArcGIS Online using ArcGIS API for Python

Last Published: March 15, 2021

Summary

It is not possible to export markup layers (feature collection layer) directly using the export() function in ArcGIS API for Python, because it only supports exporting feature services, vector tile services, and scene service layers. As an alternative, the markup layers can be exported by extracting the data into a file geodatabase using the extract_data() function and locally downloading the file.

Procedure

This method describes how to extract markup layers data into a file geodatabase with ArcGIS API for Python.

  1. Import the necessary modules.
import traceback
from arcgis.gis import GIS, Group
from arcgis.features.analysis import extract_data
Note:
Esri recommends running the following steps in a 'try...except' logic statement block to manage unsuccessful data extraction.
  1. Specify the URL and the credentials for the account.
# For ArcGIS Online
gis = GIS("https://www.arcgis.com", username="Username", password="password")

# For Portal for ArcGIS
gis = GIS("https://<gisserver>.<domain>.com/portal", "Username", "Password")

print(gis.users.me.role) 
gID = gis.groups.search('title: "Group_Name"')[0].id
grp = Group(gis, gID)
print(grp.userMembership['memberType'])
content = grp.content()
  1. Start a loop to identify markup layers, extract the data as a file geodatabase, and download the file into the desired folder.
for item in content:
    if "Markup" in item.title:
        if item.owner == 'owner':
            markup = item
            Extract_GDB = extract_data(markup.layers, data_format='FileGeodatabase', output_name="Mark_up")
            Extract_GDB.download(r'<folder_location>')
            break                
print("Exported successfully")

Below is the full code with the 'try...except' logic statement block:

import traceback
from arcgis.gis import GIS, Group
from arcgis.features.analysis import extract_data

try:
    gis = GIS("https://www.arcgis.com", username="Username", password="password")
    print(gis.users.me.role)
    gID = gis.groups.search('title: "Group_Name"')[0].id
    grp = Group(gis, gID)
    print(grp.userMembership['memberType'])
    content = grp.content()
    for item in content:
        if "Markup" in item.title:
            if item.owner == 'owner':
                markup = item
                Extract_GDB = extract_data(markup.layers, data_format='FileGeodatabase', output_name="Mark_up")
                Extract_GDB.download(r'D:\Users\user\Downloads')
                break                
    print("Exported successfully")
except:
    print(traceback.format_exc())

Article ID: 000024668

Software:
  • ArcGIS Online
  • Portal for ArcGIS

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options