2

I have created a code in Python that I will use for a custom tool in ArcGIS, the code will create a Eucledian Distance of 6000m around a point and Reclassify the distance from 0-2000, 2000-4000, 4000-6000. The code works but what I was wondering was, is there a bit of code I can add on to make the 0-2000 area red, the 2000-4000 area to be orange and the 4000-6000 area to be yellow. As the code stands the colours are random i guess (blue, green etc.). I have been looking through a few books but could not find a solution.

from arcpy import env
from arcpy.sa import *

# Set environment settings
arcpy.env.workspace = "Z:\\GIS TEST\\Select_by_Location"
arcpy.env.overwriteOutput=1

# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")


# Local variables:
Breakout_Location = "Breakout_Location.shp"
maxDistance = "6000"
Output_direction_raster = "Z:\\GIS TEST\\Codes\\Output"

# Set Extents
arcpy.env.extent = arcpy.Extent(31652.290929,28102.389486,269652.513962,212966.447186)

if arcpy.Exists(Output_direction_raster):
    arcpy.Delete_management(Output_direction_raster)
Euc_Dist1=EucDistance(Breakout_Location, 6000, 400, Output_direction_raster)


# Process: Reclassify
Reclass_Output_direction_raster = Reclassify(Euc_Dist1, "Value", RemapRange([[0,2000,1],[2000,4000,2],[4000,6000,3]]), "DATA")

arcpy.SetParameterAsText(0, Breakout_Location)


Reclass_Output_direction_raster.save("Z:\\GIS TEST\\Codes\\Output")
  • I've researched this before from what I have gathered ESRI didnt include this capability in arcpy.mapping because they didnt want to "bloat it" from what I understand they want to keep this as a ArcObjects functionality. I have wished on many occasions that there were more options for Symbology alterations within arcpy. refer to this post: forums.arcgis.com/threads/44502-Managing-Symbology-using-Python – landocalrissian Jan 8 '14 at 17:24
  • 1
    As a work around you could create a "template" layer with the symbology you desire and use it as a style referance with the applysymbologyfromlayer tool. I'm sure someone will post a more detailed explanation of this work around. – landocalrissian Jan 8 '14 at 17:30
4

I recently ran into this limitation when creating an esri addin toolbar. I was limited to the option that Chris R mentioned, creating and saving a template layer with my python code. It was fairly simple and works remarkably well.

To not hard code the path to the symbology layer, I used os.path to get the path of the layer saved with the python code...

import os
Temp_Symbology = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'Symbology_Template.lyr')

Add raster to TOC

mxd = arcpy.mapping.MapDocument('current')
df = arcpy.mapping.ListDataFrames(mxd)[0]
add_layer = arcpy.mapping.Layer(Output_direction_raster)
arcpy.mapping.AddLayer(df, add_layer, "TOP")
reclass_raster_lyr = arcpy.mapping.ListLayers(mxd)[0]

Then apply the symbology and refresh active view...

# Apply symbology from .lyr file
arcpy.ApplySymbologyFromLayer_management(reclass_raster_lyr, Temp_Symbology)
arcpy.RefreshActiveView()

I hope it helps.

3

One option would be to create a color map file (.clr) you can reference in your script. Then it is simply a matter of using Add Colormap (Data Management) to assign your color map to the raster layer:

arcpy.AddColormap_management (in_raster, {in_template_raster}, {input_CLR_file})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.