操作方法
将要素图层从 ArcGIS Pro 发布到 ArcGIS Online 或 Portal for ArcGIS 时,可以启用或禁用现有编辑者信息。 但是,在 ArcGIS Pro 2.5 及更低版本中,如果使用现有编辑者追踪字段在 ArcGIS Pro 中进行发布,则将覆盖该信息并将其替换为发布者的信息以及图层的发布日期或时间。 这是有意设计的。 但是,可以使用 ArcGIS API for Python 保留先前存在的编辑者追踪信息。
请按照以下说明,使用 ArcGIS API for Python,在不覆盖编辑者追踪信息的情况下发布要素图层。
注: 在继续执行这些步骤之前,请从 ArcGIS Pro 发布所需要素服务。
请插入以下脚本以覆盖现有要素图层,并保留编辑者追踪信息的原始值:
pub_params = {"editorTrackingInfo" : {"enableEditorTracking":'true', "preserveEditUsersAndTimestamps":'true'}} sdItem.update(data=sd) print('Overwriting existing feature service…') fs = sdItem.publish(publish_parameters=pub_params,overwrite=True)
import arcpy import os, sys from arcgis.gis import GIS
prjPath = r'C:\Users\pathwayToYour.aprx' sd_fs_name = 'name of item in the portal' portal = 'https://PortalURL/portal/home' #or https://arcgis.com user = 'username' password = 'password'
shrOrg = True shrEveryone = False shrGroups = '' relPath = sys.path[0] sddraft = os.path.join(relPath, 'WebUpdate.sddraft') sd = os.path.join(relPath, 'WebUpdate.sd') print('Creating SD file') arcpy.env.overwriteOutput = True prj = arcpy.mp.ArcGISProject(prjPath) mp = prj.listMaps()[0] arcpy.mp.CreateWebLayerSDDraft(mp, sddraft, sd_fs_name, "MY_HOSTED_SERVICES", "FEATURE_ACCESS", None, True, True, True) arcpy.StageService_server(sddraft, sd)
print('Connecting to {}'.format(portal)) gis = GIS(portal, user, password) #if single sign on, edit line above be gis = GIS(portal)
print('Search for original SD on portal…') sdItem = gis.content.search('{} AND owner:{}'.format(sd_fs_name, user), item_type='Service Definition')[0] print('Found SD: {}, ID: {} n Uploading and overwriting…'.format(sdItem.title, sdItem.id)) pub_params = {"editorTrackingInfo" : {"enableEditorTracking":'true', "preserveEditUsersAndTimestamps":'true'}} sdItem.update(data=sd) print('Overwriting existing feature service…') fs = sdItem.publish(publish_parameters=pub_params,overwrite=True) fs.share(org=shrOrg, everyone=shrEveryone, groups=shrGroups) print('Finished updating: {} – ID: {}'.format(fs.title, fs.id))
从 ArcGIS 专家处获得帮助
下载 Esri 支持应用程序