Select to view content in your preferred language

Seeking Assistance with Class Labels for My Portal - NaturalBreaks

1084
8
06-02-2020 09:11 AM
JuliaBrodsky
Emerging Contributor

Hello,

I am trying to publish a few layers from an .aprx to My Portal.  I have a graduated color renderer classified by Natural Breaks.  I'd like the symbology for lyr3 listed below to display on My Portal as currency format, and I am unsure of how to change the format from the integer value here to currency.  I'd like to have it published as currency as an automated task and not have to reset values in the Portal web map each time the .aprx is shared to Portal.  Please see my sample code here.  Any assistance would be greatly appreciated!

Here is how the layer appears in my Web Map in Portal, and I'd like this format to change to currency with no decminals:

import arcpy
import os
import locale
from arcpy import env
import xml.dom.minidom as DOM
arcpy.env.overwriteOutput = True

p = arcpy.mp.ArcGISProject(r"C:\Data\test_pro_projects\Commercial_Analytics_0527\Commercial_Analytics_0527.aprx")

m = p.listMaps ("Map") [0]
##lyt = p.listLayouts("Layout")[0]
lyr = m.listLayers("Pct_Req_Change")[0]
sym = lyr.symbology
sym.updateRenderer('GraduatedColorsRenderer')
sym.renderer.classificationField = 'Pct_Req_Change'
sym.renderer.breakCount = 5
sym.renderer.classificationMethod = "NaturalBreaks"
sym.renderer.colorRamp = p.listColorRamps('Aspect')[0]
lyr.symbology = sym
for lyr in m.listLayers("Pct_Req_Change"):
lyr.visible = True
lyr1 = m.listLayers("Delta_Req_Change")[0]
sym1 = lyr1.symbology
sym1.updateRenderer('GraduatedColorsRenderer')
sym1.renderer.classificationField = 'Delta_Req_Change'
sym.renderer.classificationMethod = "NaturalBreaks"
sym1.renderer.breakCount = 5
sym1.renderer.colorRamp = p.listColorRamps('Aspect')[0]
lyr1.symbology = sym1
for lyr1 in m.listLayers("Delta_Req_Change"):
lyr1.visible = True
lyr2 = m.listLayers("Rev_Pct_Change")[0]
sym2 = lyr2.symbology
sym2.updateRenderer('GraduatedColorsRenderer')
sym2.renderer.classificationField = 'Rev_Pct_Change'
sym.renderer.classificationMethod = "NaturalBreaks"
sym2.renderer.breakCount = 5
sym2.renderer.colorRamp = p.listColorRamps('Aspect')[0]
lyr2.symbology = sym2
for lyr2 in m.listLayers("Rev_Pct_Change"):
lyr2.visible = True
lyr3 = m.listLayers("Revenue_Change")[0]
sym3 = lyr3.symbology
sym3.updateRenderer('GraduatedColorsRenderer')
sym3.renderer.classificationField = 'Revenue_Change'
sym.renderer.classificationMethod = "NaturalBreaks"
sym3.renderer.breakCount = 5
sym3.renderer.colorRamp = p.listColorRamps('Aspect')[0]
lyr3.symbology = sym3
for lyr3 in m.listLayers("Revenue_Change"):
lyr3.visible = True
p.save()

# Set output file names
outdir = r"C:\Data\test_pro_projects\Commercial_Analytics_0527"
service = "CommPerf_0527_MIL1"
sddraft_filename = service + ".sddraft"
sddraft_output_filename = os.path.join(outdir, sddraft_filename)

# Reference map to publish
m = p.listMaps("Map")[0]
lyrs = []
lyrs.append(m.listLayers('Pct_Req_Change')[0])
lyrs.append(m.listLayers('Delta_Req_Change')[0])
lyrs.append(m.listLayers('Rev_Pct_Change')[0])
lyrs.append(m.listLayers('Revenue_Change')[0])
# Create TileSharingDraft and set service properties
sharing_draft = m.getWebLayerSharingDraft("FEDERATED_SERVER", "MAP_IMAGE", service, lyrs)
sharing_draft.federatedServerUrl = "https://esri.foo.com/arcgis"
sharing_draft.summary = "My Summary"
sharing_draft.tags = "My Tags"
sharing_draft.description = "My Description"

# Create Service Definition Draft file
sharing_draft.exportToSDDraft(sddraft_output_filename)


# set service type to esriServiceDefinitionType_Replacement
newType = 'esriServiceDefinitionType_Replacement'
xml = r"C:\Data\test_pro_projects\Commercial_Analytics_0527\CommPerf_0527_MIL1.sddraft"
doc = DOM.parse(xml)
descriptions = doc.getElementsByTagName('Type')
for desc in descriptions:
if desc.parentNode.tagName == 'SVCManifest':
if desc.hasChildNodes():
desc.firstChild.data = newType
outXml = xml
f = open(outXml, 'w')
doc.writexml( f )
f.close()

# Stage Service
arcpy.server.StageService(r"C:\Data\test_pro_projects\Commercial_Analytics_0527\CommPerf_0527_MIL1.sddraft", r"C:\Data\test_pro_projects\Commercial_Analytics_0527\CommPerf_0527_MIL1.sd", None)

# Share to portal
print("Uploading Service Definition...")
arcpy.UploadServiceDefinition_server(r"C:\Data\test_pro_projects\Commercial_Analytics_0527\CommPerf_0527_MIL1.sd", "arcgis on esri.foo.com.ags")

print("Successfully Uploaded service.")

del p, lyr

0 Kudos
8 Replies
DanPatterson
MVP Esteemed Contributor

Julia Brodsky‌ perhaps you could format your code so that people could refer to line numbers

/blogs/dan_patterson/2016/08/14/script-formatting 


... sort of retired...
0 Kudos
JuliaBrodsky
Emerging Contributor
#Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:19:22) [MSC v.1500 32 bit (Intel)] on win32
#Type "copyright", "credits" or "license()" for more information.
import arcpy
import os
import locale
from arcpy import env
import xml.dom.minidom as DOM
arcpy.env.overwriteOutput = True

p = arcpy.mp.ArcGISProject(r"C:\Data\test_pro_projects\Commercial_Analytics_0527\Commercial_Analytics_0527.aprx")

m = p.listMaps ("Map") [0]
##lyt = p.listLayouts("Layout")[0]
lyr = m.listLayers("Pct_Req_Change")[0]
sym = lyr.symbology
sym.updateRenderer('GraduatedColorsRenderer')
sym.renderer.classificationField = 'Pct_Req_Change'
sym.renderer.breakCount = 5
sym.renderer.classificationMethod = "NaturalBreaks"
sym.renderer.colorRamp = p.listColorRamps('Aspect')[0]
lyr.symbology = sym
for lyr in m.listLayers("Pct_Req_Change"):
          lyr.visible = True
lyr1 = m.listLayers("Delta_Req_Change")[0]
sym1 = lyr1.symbology
sym1.updateRenderer('GraduatedColorsRenderer')
sym1.renderer.classificationField = 'Delta_Req_Change'
sym.renderer.classificationMethod = "NaturalBreaks"
sym1.renderer.breakCount = 5
sym1.renderer.colorRamp = p.listColorRamps('Aspect')[0]
lyr1.symbology = sym1
for lyr1 in m.listLayers("Delta_Req_Change"):
          lyr.visible = True
lyr2 = m.listLayers("Rev_Pct_Change")[0]
sym2 = lyr2.symbology
sym2.updateRenderer('GraduatedColorsRenderer')
sym2.renderer.classificationField = 'Rev_Pct_Change'
sym.renderer.classificationMethod = "NaturalBreaks"
sym2.renderer.breakCount = 5
sym2.renderer.colorRamp = p.listColorRamps('Aspect')[0]
lyr2.symbology = sym2
for lyr2 in m.listLayers("Rev_Pct_Change"):
          lyr.visible = True
lyr3 = m.listLayers("Revenue_Change")[0]
sym3 = lyr3.symbology
sym3.updateRenderer('GraduatedColorsRenderer')
sym3.renderer.classificationField = 'Revenue_Change'
sym.renderer.classificationMethod = "NaturalBreaks"
sym3.renderer.breakCount = 5
sym3.renderer.colorRamp = p.listColorRamps('Aspect')[0]
lyr3.symbology = sym3
for lyr3 in m.listLayers("Revenue_Change"):
          lyr.visible = True
p.save()

# Set output file names
outdir = r"C:\Data\test_pro_projects\Commercial_Analytics_0527"
service = "CommPerf_0527_MIL1"
sddraft_filename = service + ".sddraft"
sddraft_output_filename = os.path.join(outdir, sddraft_filename)

# Reference map to publish
m = p.listMaps("Map")[0]
lyrs = []
lyrs.append(m.listLayers('Pct_Req_Change')[0])
lyrs.append(m.listLayers('Delta_Req_Change')[0])
lyrs.append(m.listLayers('Rev_Pct_Change')[0])
lyrs.append(m.listLayers('Revenue_Change')[0])
# Create TileSharingDraft and set service properties
sharing_draft = m.getWebLayerSharingDraft("FEDERATED_SERVER", "MAP_IMAGE", service, lyrs)
sharing_draft.federatedServerUrl = "https://esri.foo.com/arcgis"
sharing_draft.summary = "My Summary"
sharing_draft.tags = "My Tags"
sharing_draft.description = "My Description"

# Create Service Definition Draft file
sharing_draft.exportToSDDraft(sddraft_output_filename)


# set service type to esriServiceDefinitionType_Replacement
newType = 'esriServiceDefinitionType_Replacement'
xml = r"C:\Data\test_pro_projects\Commercial_Analytics_0527\CommPerf_0527_MIL1.sddraft"
doc = DOM.parse(xml)
descriptions = doc.getElementsByTagName('Type')
for desc in descriptions:
    if desc.parentNode.tagName == 'SVCManifest':
        if desc.hasChildNodes():
            desc.firstChild.data = newType
outXml = xml
f = open(outXml, 'w')
doc.writexml( f )
f.close()

# Stage Service
arcpy.server.StageService(r"C:\Data\test_pro_projects\Commercial_Analytics_0527\CommPerf_0527_MIL1.sddraft", r"C:\Data\test_pro_projects\Commercial_Analytics_0527\CommPerf_0527_MIL1.sd", None)

# Share to portal
print("Uploading Service Definition...")
arcpy.UploadServiceDefinition_server(r"C:\Data\test_pro_projects\Commercial_Analytics_0527\CommPerf_0527_MIL1.sd", "arcgis on esri.foo.com.ags")

print("Successfully Uploaded service.")

del p, lyr


0 Kudos
JuliaBrodsky
Emerging Contributor

Sorry, this was my first Python related posting on GeoNet and I was unaware of the formatting options.  I just re-pasted the code using the requested formatting structure.  Any info you can share is appreciated!

0 Kudos
DanPatterson
MVP Esteemed Contributor

Julia Brodsky‌ before I go much further in the script

for lyr2 in m.listLayers("Rev_Pct_Change"):
          lyr.visible = True

Do you mean lyr2.visible = True or are you actually trying to set lyr visible?


... sort of retired...
0 Kudos
JuliaBrodsky
Emerging Contributor

What this part of the script is intending to do is to set the renderer as graduated colors with natural breaks.  Since the source revenue data can differ each time it's refreshed, I need to have it refresh the rendering and be visible.  

I took a Python class with ESRI about 4 years ago and have been dabbling in it to automate some internal processes, but I am not a developer, so the script may not be written the most elegantly.

0 Kudos
DanPatterson
MVP Esteemed Contributor

Julia Brodsky‌ lines 32-33 and in my last post.  You are setting "lyr" visible multiple times potentially (lyr2 in m.list... )

My question was... do you mean to set lyr2 visible?  in other words, did you drop the 2 


... sort of retired...
0 Kudos
JuliaBrodsky
Emerging Contributor

Yes, you are correct.  Thanks for catching that. The same logic would apply to lines 43 and 53 as well.

0 Kudos
JuliaBrodsky
Emerging Contributor

Good morning.  Just following up - would you have any ideas on this question?

0 Kudos