Wednesday, 22 August 2018

arcgis desktop - Managing symbology in Feature Classes


I'm using an enterprise db to store my data and I'm writing a python tool that allows me to interact with that data in ArcMap. However, all my layers someone have "OTHER" for the symbologyType (not sure why).


What I need to do is to change the symbol type for points in each FC. It is fine for now to just use a single feature symbol type, but of course I can't do that when I've got the unsupported symbology type.


How can I create my own layer symbology? Once I've got something I know I can apply it using ApplySymbologyFromLayer_management()


I'm probably missing something obvious here, but if someone could help point it out I'd appreciate it!



Edit (just to be clear, I know I can change the symbology from the layer properties, but I want to be able to script it and control it from a python tool):


Here are the features


point features


Here is the symobology reference


symbologyType check


Here is the layer properties


layer properties



Answer



As to my knowledge, unfortunately, there isn't a way to update a layer in the TOC that has "OTHER" symbology type directly. If your symbologyType = "OTHER", as you have noticed, it means that you are not able to alter symbology properties for those symbology classes that are supported in 10.2. This is because only a limited number of symbology classes and properties are exposed to arcpy.mapping module right now. From the Esri Help:




If a value of OTHER is returned, then the layer's symbology can't be modified.



The only way to change this symbology type by using arcpy is to update layer first (UpdateLayer). It was like this since 10.0 and nothing has changed in 10.1/10.2 regarding the situation when you have "OTHER" symbology type.



import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "County Maps")[0]
updateLayer = arcpy.mapping.ListLayers(mxd, "Rivers", df)[0]
sourceLayer = arcpy.mapping.Layer(r"C:\Project\Data\Rivers.lyr")
arcpy.mapping.UpdateLayer(df, updateLayer, sourceLayer, True)


After you've done updating the layer from Single symbol (as you have now) with some dummy .lyr file that would change it to, say, Graduated colors, you should be able to start changing individual properties of the symbology (see the sample four in Layer).



if lyr.symbologyType == "GRADUATED_COLORS":
lyr.symbology.valueField = "POP2000"
lyr.symbology.numClasses = 4
lyr.symbology.classBreakValues = [250000, 999999, 4999999, 9999999, 35000000]
lyr.symbology.classBreakLabels = ["250,000 to 999,999", "1,000,000 to 4,999,999",

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...