[GIS] Use Display Expression for KML Popup, SHP to KML ArcGIS

arcgis-10.1arcgis-desktoparcmapkml

In Arcmap I've created a complex label expression in the Display expression for my layer. I'd like to have that expression displayed when I convert the layer to .kmz file for display in Google Earth. I'm using the ESRI Layer TO KML conversion tool.

What happens in the popup right now is the display expression jammed, without the correct formatting, into the feature name box and also the feature description box, followed by the complete list of fields.

I've been looking at the HTML popup tab, but don't see any way to use the Display Expression I already have in that tab. Is it possible for this to happen? It looks like otherwise I'll have to write a XSL template.

EDIT: Thanks to @KHibma for the comment. What I've ended up doing is

  1. removing all of the fields from display in the shapefile properties in ArcMap before the export so they are not included in the kml popup
  2. Labeling the features in arcmap with one field so that field value is the "title" of the feature in the popup.
  3. adding HTML formatting tags to the Display Expression (which I was writing in Python). this expression appeared, formatted, in the blue box below the feature title.

I can't add a screenshot of the result right now, but will be able add it later.

This worked fine on a small scale, but when trying to export an entire parcel fabric for a county I would get a C++ runtime error.

One interesting thing I found was that, even before the export, if there was an error in the FindLabel function and it was not able to create a label, it would come back as empty. So I added a try/except statement within the function like:

def FindLabel([field1],[field2]):
    try:
        #code for function
    except:
        return "there was a problem creating this display"

which worked great. However, when I tried to import sys or traceback in the function and set the error handling message as the return in the except statement, it still returned blank (i.e. didn't return the text of the error handling message). In the end, I fixed all the problems with the expression, but still got the runtime error when making the big export.

Best Answer

You seem to be encountering NIM099128:

Converting a Map or Layer to Key Markup Language (KML) when a layer has a formatted label expression; the expression displayed in the KML is not what is labeled.

The only workaround listed is to:

Format the labels through the standard label symbology, and not by using an expression.

The problem seems to have first been reported at ArcGIS 10.2.1, and appears to be assigned to a developer to address, but if you need a solution sooner rather than later, then it looks like you may need to develop your own workaround, because I do not think the above will meet your requirements.