Missing credits/copyright when publishing feature layer using ArcPy

482
1
02-07-2023 08:13 AM
JohnFannon
Occasional Contributor III

We have developed arcpy scripts to automate layer publishing that follow the examples at:

https://pro.arcgis.com/en/pro-app/latest/arcpy/sharing/mapimagesharingdraft-class.htm

We have a requirement for the correct copyright/attribution/credits to be populated on both the resulting feature service and feature layer within the feature service, so that these are displayed correctly in the OOB attribution on maps and apps.

The documentation states:

JohnFannon_0-1675783390914.png

However, when we publish layers using arcpy, the credits/copyright is not populated on the resulting feature service or feature layer (within the service):

JohnFannon_1-1675784841961.png

JohnFannon_2-1675785075234.png

If we override the credits after generating the sddraft (using sddraft.credits = "Some text"), the copyright is populated at the feature service level, but not at the feature layer level.

For the credits to appear correctly in map viewer and apps, they need to be populated at the feature layer level.

Note that it works when manually publishing from ArcGIS Pro, but we need to publish in an automated way as part of a CI/CD pipeline, so this is not an option.

We have raised with Esri support and they have created an enhancement request, but has anyone else found a work around for this issue? Is there a way to update the copyright on the feature layer after the service has been published (e.g. with the rest api).

We are using ArcGIS Enterprise 10.9 (Server & Portal) and not ArcGIS Online and these are standard feature layers and not hosted feature layers.

Any thoughts much appreciated. Sample python code for generating an SD file below (which can then be published in server manager).

John

import arcpy
import os
import sys
import xml.dom.minidom as DOM

#params
if len(sys.argv) != 8:
    print("Incorrect arguments. Usage: creditstest.py <portal url> <server url> <portal user> <portal password> <pro project path> <out directory path> <override credits (Y/N)>")
    sys.exit(1)

portalUrl = sys.argv[1]
serverUrl = sys.argv[2]
portalUser = sys.argv[3]
portalPassword = sys.argv[4]
arcgisProProjectPath = sys.argv[5]
outDirPath = sys.argv[6]
overrideCredits = sys.argv[7]

# layer from project
print("Opening Pro project...")
proj = arcpy.mp.ArcGISProject(arcgisProProjectPath)
map = proj.listMaps('Map')[0]
layer = map.listLayers()[0]

# Set output file paths
print("Building output file paths...")
sddraftFilename = "{0}.sddraft".format(layer.name)
sddraftPath = os.path.join(outDirPath, sddraftFilename)
sdPath = sddraftPath.replace(".sddraft",".sd")

#If any old service definitions exist, remove them
for filePath in [sddraftPath,sdPath]:
    if os.path.exists(filePath):
        os.remove(filePath)

# Sign in to portal
print("Signing in to Portal...")
arcpy.SignInToPortal(portalUrl, portalUser, portalPassword)

#Create map image sharing draft
print("Generating SD draft...")
sddraft = map.getWebLayerSharingDraft("FEDERATED_SERVER", "MAP_IMAGE", layer.name, [layer])

#Set draft properties
sddraft.federatedServerUrl= serverUrl
sddraft.copyDataToServer = False
#sddraft.overwriteExistingService = True
#sddraft.description = ""
#sddraft.summary = ""
 
# Set the credits/attribution/copyright based on the credits in the layer metadata
# Note this ONLY sets the credits at the service level and NOT at the layer level 
# (which is required for copyright to display in map viewer for feature layers)
if overrideCredits.upper() == "Y":
    print("Overriding credits with layer credits...")
    layerCredits = layer.metadata.credits
    if layerCredits != None and len(layerCredits.strip()) > 0:
        sddraft.credits = layerCredits

#Export service definition draft
print("Exporting SD draft...")
sddraft.exportToSDDraft(sddraftPath) 

# Modify sddraft to enable feature access
# Read the file
print("Add feature server to SD draft...")
doc = DOM.parse(sddraftPath)

# Find all elements named TypeName
# This is where the addition layers and capabilities are defined
typeNames = doc.getElementsByTagName('TypeName')
for typeName in typeNames:
# Get the TypeName to enable
    if typeName.firstChild.data == "FeatureServer":
        extension = typeName.parentNode
        for extElement in extension.childNodes:
            # Enable feature access
            if extElement.tagName == 'Enabled':
                extElement.firstChild.data = 'true'

# Write to a new .sddraft file
sddraftMod = layer.name + '_mod_xml' + '.sddraft'
sddraftModPath = os.path.join(outDirPath, sddraftMod)
with open(sddraftModPath, 'w') as f:
    doc.writexml(f)

# Stage service
print("Generating SD file...")
arcpy.StageService_server(sddraftModPath, sdPath)

print("Successfully generated SD file.")

 

1 Reply
JenniferSmits
New Contributor III

Following: "Is there a way to update the copyright [and description] on the feature layer REST service after the service has been published" thank you!!

0 Kudos