When I upload a layer to ArcGIS Online, the marker symbol sizes change randomly. How can I fix this, or how can I change the symbol sizes In AGOL using python script?

76
0
08-07-2020 09:09 AM
NathanRyan
New Contributor

import arcpy
from arcpy import env
import os
from os import path
import sys
import arcgis
from arcgis.gis import GIS

arcpy.env.overwriteOutput = True
arcpy.env.outputMFlag = "Disabled"
arcpy.env.outputZFlag = "Disabled"
arcpy.env.extent = "MAXOF"

workspace = r"<workspace>"
completed = workspace + "\\Completed"
upload = workspace + "\\Upload"
aprxPath = upload + "\\CPE.aprx"

aprxBlank = upload + "\\CPEBlank.aprx"

#delete old aprx
try:
   os.remove(aprxPath)
except:
   print ("No File to Delete!")

#hardcode target layers
symbologyLayer = upload + r"\CPEfiltered.lyr"

aprx = arcpy.mp.ArcGISProject(aprxBlank)
m = aprx.listMaps("Map")[0]
# for lyr in symLyrList:
file = arcpy.mp.LayerFile(symbologyLayer)
m.addLayer(file)

lyr = m.listLayers()[0]
sym = lyr.symbology

aprx.saveACopy(aprxPath)

#cleanup
del aprx

print ("Creation finished!!")
prjPath = aprxPath

sd_fs_name = "CPEfilter"
portal = "http://www.arcgis.com" 
user = os.environ.get('NATE1')
password = os.environ.get('NATE2')
# Set sharing options
shrOrg = False
shrEveryone = False
shrGroups = "Ispops"

### End setting variables
try:
   # Local paths to create temporary content
   relPath = upload
   sddraft = os.path.join(relPath, "CPE.sddraft")
   sd = os.path.join(relPath, "CPE.sd")

   # Create a new SDDraft and stage to SD
   print("Creating SD file")
   arcpy.env.overwriteOutput = True
   prj = arcpy.mp.ArcGISProject(prjPath)
   m = prj.listMaps()[0]
   arcpy.mp.CreateWebLayerSDDraft(m, 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)
   ## token = gis._con.token

   # Find the SD, update it, publish /w overwrite and set sharing and metadata
   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))
sdItem.update(data=sd)
print("Overwriting existing feature service")
fs = sdItem.publish(overwrite=True)

for grp in sym.renderer.groups:
   for itm in grp.items:
      print(itm.label, itm.symbol.size)

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

except Exception as err:
   print(str(err))
   sys.exit(1)

   print("Upload Failed")

0 Kudos
0 Replies