POST
|
Thank you rzufelt,From your complete and accurate replys I learned a lot! Not all operations require a mxd.save(). If you were exporting an output image in each iteration or something, the changes should be represented in the output. However, without a mxd.save(), the changes made by the script would not show in the mxd the next time you open it. In example 2, the mxd was set to "current" ( mxd = arcpy.mapping.MapDocument("current") ) which mean to apply the code to the currently open mxd. This would be run from the python window within ArcMap, so, you would already have the mxd open and would see the changes take place. you would then be warned if you tried to close without saving and could save if needed. Need to be carefull performing such an operation as too many mxd.save(s) within an iteration will crash python (in my case, error = 'PageLayoutObject: Error in executing ExportToJPEG' ). Often will make somewhere between 47 and 112 iterations, then crash for no reason. I had this happen in multiple scripts, once I removed the mxd.save(s), it will finish all 1800+ outputs. R_
... View more
08-22-2013
06:39 PM
|
0
|
0
|
882
|
POST
|
Can symbology.classLabels property read/write? Or there is a bug in ESRI Products? I try the sample data and there was not any change in mxd at all. Thank you Jeff! I use sample data you provide to update mxd again,but ''lyr.symbology.classLabels=upt_Labels''cannot affect at all,there was not any change in mxd,All my code as follows:
# -*- coding: utf-8 -*-
import arcpy, os
import arcpy.mapping
#Pre-defined �??code�?name�?? key-value pair
code_name={'A':'Apples','B':'Bananas','C':'Cherries'}
#Get mxd
mxd=arcpy.mapping.MapDocument(r"E:\Test_Symbology\Test_Symbology.mxd")
#According mxd&layername �??code�?name�?? key-value pair to modify lyr.symbology.classLabels
def EditLyrSymInfo(mxd,lyrName):
lyr = arcpy.mapping.ListLayers(mxd, lyrName)[0]
if lyr.symbologyType == "UNIQUE_VALUES":
Labels=lyr.symbology.classLabels
Values=lyr.symbology.classValues
upt_Labels=[]
print "Layer Symbology Info to be Edit:"+lyrName
for value in Values:
upt_label=code_name[value]
upt_Labels.append(upt_label)
print u'Labels:{0}, Values:{1};'.format(upt_label,value)
lyr.symbology.classLabels=upt_Labels
lyr.symbology.showOtherValues = False
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
def main():
#Print Pre-defined �??code�?name�?? key-value pair
print u'##Print Pre-defined �??code�?name�?? key-value pair##'
for key,value in code_name.iteritems():
print key,value
lyrName="PlanPolygonSelectR"
#After modify lyr.symbology.classLabels(Labels:Values)key-value pair:
print u'##After modify lyr.symbology.classLabels(Labels:Values)key-value pair:##'
EditLyrSymInfo(mxd,lyrName)
if __name__=="__main__":
main()
The sample data and mxd are in attatchment,Any help will be appreciated !
... View more
08-19-2013
02:20 AM
|
0
|
0
|
882
|
POST
|
I follow your way to update mxd,but ''sym.classLabels = labelList''cannot affect after i check the labelList in ArcMap10.1,in fact,there was not any change in mxd,what's wrong?Any help will be appreciated ! I just did something similar for a colleague. Here is the complete code snippet. Just like you suggest, I build two empty lists and append the unique values to them. Note, I'm using the new da.SearchCursor at 10.1.
import arcpy
def int_if_you_can(x):
return int(x) if x % 1.0 == 0 else x
#Reference layer and update to Unique Value renderer using layer file
mxd = arcpy.mapping.MapDocument("current")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
lyr100 = arcpy.mapping.ListLayers(mxd, "interval_100")[0]
lyrFile = arcpy.mapping.Layer(r"C:\Active\ArcPY\Users\SteveLynch\interval_100.lyr")
arcpy.mapping.UpdateLayer(df,lyr100,lyrFile)
#Apply source data to layer
sym = lyr100.symbology
sym.addAllValues()
#Generate unique list of lables
classList = []
labelList = []
with arcpy.da.SearchCursor(lyr100, ("mean_cont", "low_cont", "high_cont"), sql_clause=(None,"ORDER BY mean_cont")) as rows:
for row in rows:
lowCont = str(int_if_you_can(row[1]))
highCont = str(int_if_you_can(row[2]))
if not lowCont + " - " + highCont in labelList:
classValue = in_if_you_can(row[0])
classList.append(classValue)
label = lowCont + " - " + highCont
labelList.append(label)
#Update layer with new label classes
sym.classValues = classList
sym.classLabels = labelList
arcpy.RefreshActiveView()
Jeff
... View more
08-11-2013
12:05 AM
|
0
|
0
|
390
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|