Select to view content in your preferred language

Using ArcPY to Overwrite AGOL Feature Service, ArcGIS Pro Symbology not being Applied

194
1
2 weeks ago
Labels (1)
DJB
by
New Contributor III

I have a python script that overwrites a feature service on a nightly basis.  Up until this weekend the script was running great.  Now when my script runs, it does finish without any errors or warnings but the symbology in my ArcGIS Pro project is not being applied.

The symbology that I use in ArcGIS Pro...

DJB_0-1716824571647.png

My feature service symbology, in AGOL, before my python script is run...

DJB_1-1716824642083.png

My feature service symbology after I run my script...

DJB_2-1716825108415.png

And when I manually overwrite the service in ArcGIS Pro, the symbology is then applied properly again.

I'm not sure what has changed that my python script no longer applies the appropriate symbology.

 

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

prjPath = r"C:\GIS_Workspace\Projects\Berry_Disease_Mapping\Berry_Disease_Modelling\Berry_Risk_Prediction.aprx"

print("Berry_Disease_Risk_Ratings Service Creation")
sd_fs_name = "Berry_Disease_Risk_Modelling"
item_id = "ae23b9349c9942a0b34cb919be434919"
portal = "http://www.arcgis.com" 
user = "LOGIN"
password = "XXXXXXX"

# Local paths to create temporary content
sddraft = r"C:\GIS_Workspace\Projects\Berry_Disease_Mapping\Berry_Disease_Risk_Modelling.sddraft"
sd = r"C:\GIS_Workspace\Projects\Berry_Disease_Mapping\Berry_Disease_Risk_Modelling.sd" 

# Create a new SDDraft and stage to SD
print("Creating SD file")
arcpy.env.overwriteOutput = True
prj = arcpy.mp.ArcGISProject(prjPath)
mp = prj.listMaps('For_Mapping_Service')[0]
arcpy.mp.CreateWebLayerSDDraft(mp, sddraft, sd_fs_name, "MY_HOSTED_SERVICES", "FEATURE_ACCESS","", True, True)
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…")
sdItem = gis.content.get(item_id)
print("Found SD: {}, ID: {} n Uploading and overwriting…".format(sdItem.title, sdItem.id))
sdItem.update(data=sd)
print("Overwriting existing feature service…")
fs = sdItem.publish(overwrite=True)

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

 

I should note that I recently upgraded my Pro to 3.3 earlier and ever since then my script has not been behaving the way that it use to.  Not sure if one has anything to do with the other.

I also have another thread that outlines how item.share has been deprecated as well.  Also started after my upgrade.

Overwrite ArcGIS Online Feature Service using ArcG... - Esri Community

0 Kudos
1 Reply
jcarlson
MVP Esteemed Contributor

I don't have any answer for why arcpy is dropping your symbology settings, but I'd encourage you to move your process to a truncate/append method rather than simply overwriting. This would refresh the data, but would not touch any layer configuration or symbology settings.

- Josh Carlson
Kendall County GIS