Extracting attributes from KML descriptions

16581
3
03-03-2017 09:50 AM
Highlighted
Esri Regular Contributor

Hello All

I am regularly asked how to extract the tabular data visible in KML description balloons in ArcGIS Earth into properly typed attributes that can be written to a Geodatabase feature class.

While KML does support a schema object that Data Interoperabilty's Quick Import geoprocessing tool would see and honour, often KML files are received that contain only HTML data in description objects, and the data is frustratingly close but inaccessible.

Data Interoperability is still the answer, but you need to author a Spatial ETL tool tailored to your data.  First, inspect the KML features in Earth and decide what attributes you want and what data type they are.  Unfortunately there is no magic wand to wave to help with this, the data is untyped in the KML description and you need to do this clerical review.

Usually only one Placemark geometry type is of interest, but if you need to convert multiple Placemark geometry types repeat the review for each one.

Then author a Spatial ETL tool with KML Reader and Geodatabase Writer, manually specifying each output feature class' geometry and attributes.

The data workflow between the Reader and Writer is this:

How to expose feature attributes from KML tag - FME Knowledge Center 

You may need a GeometryFilter transformer after the Reader to filter Placemarks of interest, and if handling date fields, a DateFormatter to make the values writable to Geodatabase (say %x input, FME date output).

The attributes you expose will then be written as properly typed fields in a Geodatabase.

There is a related workflow to extract attributes from extended data - if anyone needs this message me in GeoNet.

Tags (4)
Reply
0 Kudos
3 Replies
Highlighted
New Contributor

I've been able to make this work using cursors and lists to split the PopupInfo xml field into useful values

 

1. use the arcpy KML to layer tool and Project tools to get into to the desired coordinate system (i ran into problems adding fields to the original conversion output, which may be due to the layer file associated with it)

 

2. Use .da.SearchCursor to get the PopupInfo string from the first row. Then split it into a list based on '<', delete the first two values (the label field from Google Earth) and put remaining values that have the 'td>' tag but not the 'td>' closing tag into a new list of field names (even indexes) and field values (odd indexes)

 

3. Loop through field names list with arcpy.AddField_management to add all fields (skip if they already exist)

 

4. Use .da.UpdateCursor to get PopupInfo's for all rows, then split and create new lists just like with search cursor

 

5. this time, use all the odd index values to update rows ( if i%2 <> 0: row[(i-1)/2] = list ) and then cursor.updateRow(row)

 

Dylan

Highlighted
Regular Contributor

Dylan, This is an extremely helpful script! Thank you for sharing with everyone else.

Reply
0 Kudos
Highlighted
New Contributor II

One of the easiest way, I have discovered and prepared a video (link below);

All Attributes Conversion, Google Earth (KML or KMZ) to Shapefile

https://youtu.be/_e_besxeAlY

Regards.

Khalid Mahmood

GIS Expert since 2008

kmc786pak@gmail.com