4

I'm pretty new at ArcGIS python toolboxes. Here is one problem I've been fighting with for a while.

I want to create an output layer (GPFeatureLayer) with a specific symbology (GRADUATED_COLORS) and then modify the parameters of the symbology to "light up" features with a given value in a specific field.

First I create a layer in ArcGIS, selected a datasource (shapefile), applied the GRADUATED_COLORS symbology, and save it as layer file.

In my toolbox, within the def getParameterInfo(self): method, I define the output parameter as:

out_layer = arcpy.Parameter(displayName="Output layer showing the results",
                            name="out_layer",
                            datatype="GPFeatureLayer",
                            parameterType="Required",
                            direction="Output")
GV_LYR = os.path.join(os.path.dirname(__file__), "graduated_colors_point.lyr")
out_layer.symbology = GV_LYR

Later on, within the def execute(self, parameters, messages): method,

  • I first create the out_layer using arcpy.management.MakeFeatureLayer(in_layer, out_layer) (where out_layer = parameters[2].valueAsText and in_layer = parameters[0].valueAsText),
  • then I extract the output layer object using out_layer_obj = parameters[2].value

Following this step, I would like to modify the parameters of the symbology (valueField, classBreakValues, classBreakLabels) to fit my needs but when I check for the symbology type (out_layer_obj.symbologyType) I get OTHER instead of GRADUATED_COLORS. At the same time, within the ArcGIS map, a new layer is created with GRADUATED_COLORS symbology, and relative parameters, copied from the graduated_colors_point.lyr.

I've also tried a different approach when I created a plain out_layer without specifying the type of symbology in the parameter definition and then use the following:

GV_LYR = os.path.join(os.path.dirname(__file__), "graduated_colors_point.lyr")
sym_layer_obj = arcpy.mapping.Layer(GV_LYR)
arcpy.management.ApplySymbologyFromLayer(out_layer, sym_layer_obj)
out_layer_obj = arcpy.mapping.Layer(out_layer)

In which case it seems to work properly only on my computer while, anybody else who tried it (on same and different version of ArcGIS) gets the following error: ERROR 000968: The symbol layer does not match the input layer when running the ApplySymbologyFromLayer function.

Any suggestion or comment?

ADDENDUM

In the process of trying to figure out what's happening while the toolbox executes, I've noticed the following. While the out_layer parameter is defined as described above, there is also an in_layer parameter that is defined as follows:

in_layer = arcpy.Parameter(displayName="Layer containing selected SqueeSAR data",
                           name="in_layer",
                           datatype="GPFeatureLayer",
                           parameterType="Required",
                           direction="Input")

When, right at the beginning of the def execute(self, parameters, messages): method, I look at the object types of the parameters values:

in_layer = parameters[0].value
arcpy.AddMessage("Input layer: {0}".format(type(in_layer)))

out_layer = parameters[2].value
arcpy.AddMessage("Output layer: {0}".format(type(out_layer)))

I would expect for both of them to register as geoprocessing Layer object but this is true only for in_layer whereas out_layer is registered as geoprocessing value object. (My updateParameters(self, parameters): and updateMessages(self, parameters): methods are empty).

closed as off-topic by PolyGeo Jun 28 '16 at 7:57

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking help to debug/write/improve code must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Providing a clear problem statement and evidence of a code attempt will help others to help you. See: How to create a Minimal, Complete, and Verifiable example." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • At the moment your question seems to have bits and pieces of code interspersed with comments about it rather than a single code snippet which works up to where you are stuck. I think you should either try to work towards providing that, or try a different approach. To "light up" (or highlight) features an approach you may want to consider is to forget about changing the symbology of that layer and instead use a copy of that layer with a definition query set on it to match the features you want "lit up". – PolyGeo Jun 28 '16 at 7:57