Neste vídeo demonstramos como você pode utilizar um script Python para automatizar as rotinas de overwrite de camadas do ArcGIS Online ou ArcGIS Enterprise.

 

Segue abaixo o script Python utilizado no vídeo:

import arcpy
import os, sys
from arcgis.gis import GIS

prjPath = r”D:/Projetos ArcGIS Pro/overwrite_featurelayer/overwrite_featurelayer.aprx”

sd_fs_name = “poligono”
portal = “http://www.arcgis.com” # Can also reference a local portal
user = “seu_usuario”
password = “sua_senha”

shrOrg = True
shrEveryone = False
shrGroups = “”

relPath = r’D:/Projetos ArcGIS Pro/overwrite_featurelayer’
sddraft = os.path.join(relPath, “temporary service name.sddraft”)
sd = os.path.join(relPath, “temporary service name.sd”)

print(“Creating SD file”)
arcpy.env.overwriteOutput = True
prj = arcpy.mp.ArcGISProject(prjPath)
mp = prj.listMaps()[0]

sharing_draft = mp.getWebLayerSharingDraft(“HOSTING_SERVER”, “FEATURE”, sd_fs_name)
sharing_draft.summary = “My Summary”
sharing_draft.tags = “My Tags”
sharing_draft.description = “My Description”
sharing_draft.credits = “My Credits”
sharing_draft.useLimitations = “My Use Limitations”

sharing_draft.exportToSDDraft(“temporary service name.sddraft”)
arcpy.StageService_server(sddraft, sd)

print(“Connecting to {}”.format(portal))
gis = GIS(portal, user, password)

# Find the SD, update it, publish /w overwrite and set sharing and metadata
print(“Search for original SD on portal…”)
print(f”Query: {sd_fs_name}”)
sdItem = gis.content.search(query=sd_fs_name, item_type=”Service Definition”)
i=0
while sdItem[i].title != sd_fs_name:
i += 1
print(‘Item Found’)
print(f’item[i].title = {sdItem[i].title}, sd_fs_name = {sd_fs_name}’)
item = sdItem[i]
item.update(data=sd)

print(“Overwriting existing feature service…”)
fs = item.publish(overwrite=True)

if shrOrg or shrEveryone or shrGroups:
print(“Setting sharing options…”)
fs.share(org=shrOrg, everyone=shrEveryone, groups=shrGroups)

print(“Finished updating: {} – ID: {}”.format(fs.title, fs.id))