Pro 2.0 Bug "Apply Symbology From Layer" GeoProcessing Tool

4972
22
Jump to solution
07-18-2017 02:52 PM
ThomasCox
Occasional Contributor

Applying symbology from a .lyr or .lyrx file has been an on-going battle for me.  I had an earlier post describing a problem with 1.4.  I was able to get past that, but now find a different problem at 2.0.

I am in the process of upgrading a couple of applications from 1.4 to 2.0  I have encountered a problem when I attempt to apply the symbology of a .lyr or .lyrx file to a layer brought into the session by the application.  This had been working in 1.4

I wanted to see how Pro itself handled this by running the GeoProcessing Tool "Apply Symbology From Layer" interactively through native Pro.  I manually brought in a non symbolized grid layer into Pro.  I ran the tool and entered the grid layer as the input layer.  For the Symbology layer, I navigated to a .lyrx file that is built from a different but identically structured grid.  As soon as I finished browsing to this file and selected it, the "ApplySymbology From Layer" tool 'seized up'.

Regarding the .lyrx file.  I am able to add it directly to a pro-session with no problems and proper symbolization.  If I do this, I am able to run the Apply Symboloby From Layer tool interactively, using the just added grid (from the .lyrx) file as the symbol layer and the tool works. It appears the version 2.0 tool only works with fully qualified layers that have been added to the session and not with providing it .lyr or .lyrx files that point to and are symbolized the same way. 

I have a series of screen captures illustrating this experience with using the tool with a .lyrx file and then with a layer already added to Pro.

This image shows a non symbolized grid file added to Pro

non symbolized raster

This image shows trying to run the tool using a .lyrx file as the symbology layer source.  This image also shows the output screen from Visual Studio that captures how it behaved after adding the .lyrx file to the Symbology Layer input:

It simply seizes up.

As a test to make sure the .lyrx file I was using was healthy, I added it to the Pro session through the Add Data button. This image shows it successfully added:

The following image shows running the Apply Symboloby From Layer tool using the just added GRID from the .lyrx file. When I populate the Symbology Layer input, the tool does not misbehave:

The final image shows the initial non-symbolized grid now with the proper symbology.

This seems to confirm that the tool is not properly handling .lyrx files when provided as a the symbology source.

Any assistance is appreciated.  I will be unable to reply to any responses for a few days.

Thanks again.

0 Kudos
1 Solution

Accepted Solutions
GKmieliauskas
Esri Regular Contributor

Hi Thomas,

I have a good news for you. I have found workaround for featureclasses but it works with rasters too.

Change your workflow upside down and it will work:

1. Create layer from lyrx ( LayerFactory.Instance.CreateLayer(new Uri(uri), map); ).

2. Change created layer datasource to your raster datasource ( rasterLayer.SetDataConnection(updatedDataConnection); ).

3. Clear cache ( rasterLayer.ClearDisplayCache(); )

There is ArcGIS Pro sample how to change datasource. I hope it will help you.

View solution in original post

22 Replies
GKmieliauskas
Esri Regular Contributor

Hi Thomas,

There are many problems with the GeoProcessing Tool "Apply Symbology From Layer" especially from API. Some problems are related to display cache. I reported them to Esri support and they marked them as bugs. That tool in 1.4.1 worked better than in 2.0 (I mean from API). To check if problem related to cache make following workflow:

1. After applying lyrx from API open layer properties

2. Goto Cache tab.

3. Clear cache

4. Set "Don't cache any data locally".

5. Press OK and close layer proeprties

ThomasCox
Occasional Contributor

Thanks for your helpful reply.  I apologize for not responding sooner but have been away.  I have been working with your suggestion with some success. 

I was successful implementing your workflow interactively in Pro. If I follow your suggested workflow, for my application I will need to programmatically go to the layer's properties and set the "Don't cache any data locally" property to achieve the desired effect.

It sounds like you have passed along a number of issues to ESRI, who have identified them as bugs.  Do you have any sense from ESRI that they will be resolved in the .1 or .2 releases?

Thanks again for your assistance.

GKmieliauskas
Esri Regular Contributor

Hi Thomas,

I am not alone  Worst thing is that I have tried to make the same workflow from code but without success. That's why I reported bug, sent peace of code and etc. They agreed that it does not work.

I have reported many issues before 2.0 release (1.4.1  and 2.0 Beta) and thought that they will be fixed, because solution must be one line of code or something like that. But ...  One bug they closed with explanation that it was fixed in 2.0. I have checked and it is not.

Geonet is not the right place to report problems. I think the fastest way to have solution is to report the same bug from different users. Please contact your Esri distributer or your company GIS administrator and you will get access to create cases  for Esri software issues. This way is not very simple. You must document each case, workflow, data... This way is our chance to solve our problems. 

GKmieliauskas
Esri Regular Contributor

Hi Thomas,

I have a good news for you. I have found workaround for featureclasses but it works with rasters too.

Change your workflow upside down and it will work:

1. Create layer from lyrx ( LayerFactory.Instance.CreateLayer(new Uri(uri), map); ).

2. Change created layer datasource to your raster datasource ( rasterLayer.SetDataConnection(updatedDataConnection); ).

3. Clear cache ( rasterLayer.ClearDisplayCache(); )

There is ArcGIS Pro sample how to change datasource. I hope it will help you.

ThomasCox
Occasional Contributor

Thanks so much for the information.  Presently, we are upgrading some servers to a new flavor of SQL and I have not been able to get back to this.  I'll let you know how I fare.  I appreciate your follow up.

0 Kudos
JustinReynolds
Occasional Contributor III

For anyone still struggling with this in ArcGIS Pro, this worked for me.

# ArcPro 2.0+
# ApplySymbologyFromLayer_management Bug Work Around

import arcpy

# Set the workspace if desired
# arcpy.env.workspace = 'C:\data'

# Set layer to apply symbology to
inputLayer = "FDT_02171592"  # in the current workspace

# Set layer that output symbology will be based on
symbologyLayer = 'N:\ArcGIS - Materials\Project Template\Layer Files\FDT_v1_5.lyrx'

# Symbolize the input by Test_Status field
symbologyFields = [["VALUE_FIELD", "Test_Status", "Test_Status"]]

# Apply the symbology from the symbology layer to the input layer
arcpy.ApplySymbologyFromLayer_management(inputLayer, symbologyLayer, symbologyFields)

# It would appear that the layer properties (sym, labeling, etc.) are not being applied from the layer file
# when in fact they are.  The bug seems to revolve around the layer display cache.  Apply sym from layer via arcpy, no
# change appears, but if you then go into the layer's properties and clear the cache and change the cache setting
# to do not cache the sym from the layer file all of the sudden appear.  Many of the layer properties are not exposed
# via arcpy, however, we can "artificially" update the layer's connection properties by setting the new connection
# info equal to the current connection info. By doing this we are essentially "refreshing" the connection.  This
# produces the desired effect with applySymbologyFromLayer through arcpy.

aprx = arcpy.mp.ArcGISProject("CURRENT"# Reference the open project
myMap = aprx.listMaps()[0# Get the map that contains the input layer
myLayers = myMap.listLayers()  # either get the input layer and refresh or get a list of layers and iterate and refresh

for layer in myLayers:
    if layer.name == inputLayer:
        # "Refresh" the layer connection properties by setting the new connection = current connection
        layer.updateConnectionProperties(inputLayer, inputLayer)

- Justin Reynolds, PE
0 Kudos
JustinFuto1
New Contributor II

I tried this code and it worked from the python window, but every time I run it from my script, it errors out saying the fields I used couldn't be found from the source or input layer.  Any ideas?

0 Kudos
CharlesFried
New Contributor III

This did not work for me. So this bug with ApplySymbologyFromLayer is still not fixed in Pro v 2.2 sad to say.

0 Kudos
GKmieliauskas
Esri Regular Contributor

Hi all,

I have tested ArcGIS Pro 2.2 beta and found that ApplySymbologyFromLayer still not works. My workaround does not work on ArcGIS Pro 2.2 too. So I registered Case number: 02133585. It is registered as bug. When it will be fixed I do not know. I think it depends how many developers have problems with it. So we need to increase importance of that functionality by registering your own cases.