HOW TO
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.
This method describes how to extract markup layers data into a file geodatabase with ArcGIS API for Python.
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.
# 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()
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
Get help from ArcGIS experts
Start chatting now