POST
|
Hello ESRI community! 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. Related 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). Any suggestions or comment? Thanks!
... View more
04-10-2015
10:15 AM
|
0
|
0
|
3694
|
POST
|
Hi Bryce, something that I found really helps in troubleshooting python when it runs embedded in other application, such as in the case of the ArcGIS environment, is winpdb (http://winpdb.org). It might be a little overkill in your situation, but it will allow you to follow step by step what is happening within arcpy as it gets executed. I've used it to debug add-ins as they run and it helped me immensely. Cheers, A
... View more
10-23-2014
01:22 PM
|
0
|
0
|
564
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|