1

Looked online and found the two links below on preserving attributes when doing a kml2shp conversion.

Thinking there might be a newer better way of accomplishing this using ArcGIS 10.1 for Desktop?

If you convert a complex kml/kmz in ArcMap using ET Geowizard's "Import from Google Earth" tool (or any other kml2shp tool) you will notice many of the informative attributes displayed in Google Earth no longer exist in the resultant Feature Class

Screen shot example

  • Would you be able to edit your question to describe the ArcGIS for Desktop technique that you have used to try and convert KML to shapefile and what problem you encountered when trying to do so, please? Otherwise this question appears to be more or less link-only. – PolyGeo Mar 4 '15 at 21:59
  • Rather than "specifying" any given "Import from Google Earth" tool can you please tell us which tool from ArcGIS for Desktop you used and the precise procedure, please? – PolyGeo Mar 6 '15 at 2:41
  • @PolyGeo, edited again. ET Geowizard's tool and other kml2shp are pretty basic tools, but I can spell it out further if needed. – sirgeo Mar 6 '15 at 18:31
  • 1
    The Data Interop extension will honor the ExtendedData elements of a KML – KHibma Mar 6 '15 at 18:46
2

This tool, Export to KML developed by Kevin Martin does the work.

There are some issues with the styles but at least colours and attributes are correct, and there are plenty of options to play with the attributes, labels, etc...

EDIT: From tool's documentation Note that because Google Earth does not currently support hatching and other complex symbology, only the colors and line widths of symbols are used by the output KML

  • Could you expand on the style issues? – John Powell Dec 9 '15 at 16:32
  • From tool's documentation Note that because Google Earth does not currently support hatching and other complex symbology, only the colors and line widths of symbols are used by the output KML – Pedraz Dec 10 '15 at 8:34
  • 1
    OK, I meant to edit the answer, but I did it for you. +1 for a useful answer. – John Powell Dec 10 '15 at 8:37
1

Here is a script that does this in python.

  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[i] ) and then cursor.updateRow(row)

    import arcpy, os

    #this line is for using a script tool in arcmap input_parameter = arcpy.GetParameterAsText(0) #alternatively use input_parameter = 'C:......\file.kmz' to run as stand alone script

    direct = os.path.dirname(input_parameter) arcpy.conversion.KMLToLayer(input_parameter, direct) arcpy.env.overwriteOutput = True

    database = input_parameter[:-3] + 'gdb' dataset = database + '\Placemarks'

    arcpy.env.workspace = dataset GCS_List = arcpy.ListFeatureClasses()

    coord_sys = arcpy.GetParameter(1) #in stand-alone script use arcpy.SpatialReferece('desired Coord Sys name')

    e_count = 0

    for FC in GCS_List:

     arcpy.Project_management(FC, database + '\\' + FC + '_Proj', coord_sys)
    

    arcpy.env.workspace = database UTM_List = arcpy.ListFeatureClasses()

    mxd = arcpy.mapping.MapDocument('CURRENT') df = arcpy.mapping.ListDataFrames(mxd)[0]

    keep_fields = ['OID', 'Shape', 'SHAPE', 'PopupInfo', 'Shape_Length', 'Shape_Area', 'SHAPE_Length', 'SHAPE_Area']

    for FC in UTM_List:

     update_layer = arcpy.mapping.Layer(database + '\\' + FC)
     arcpy.mapping.AddLayer(df, update_layer)
    

    # first add the fields

     SC = arcpy.SearchCursor(FC)
     for row in SC:
    
        pop_string = row.getValue("PopupInfo")
        pop_array = pop_string.split("<")
        fields_array = []
        names_array = []
    
        for tag in pop_array:
           if "td>" in tag and "/td>" not in tag:
              fields_array.append(tag)
        break
    
     for fields in arcpy.ListFields(FC):
    
        if fields.name not in keep_fields:
           arcpy.DeleteField_management(FC,fields.name)
    

    #this will list the field names and field values #even indexes are field names (starts at 0)
    #and odd indexes are field values del fields_array[:2]

     for x in range(0,len(fields_array)):
        fields_array[x]=fields_array[x].replace("td>","")
        if x%2 == 0 and fields_array[x] not in keep_fields:
           names_array.append(fields_array[x])
           arcpy.AddField_management(FC, fields_array[x], "TEXT")
    

    # default is all TEXT fields but I could change this later to reference the values #now we update the values names_array.append("PopupInfo")

     with arcpy.da.UpdateCursor(FC,names_array) as UC:
    
        for row in UC:
    
           pop_string = row[-1]
           pop_array = pop_string.split("<")
           fields_array = []
           values_array = []
    
           for segment in pop_array:
              if "td>" in segment and "/td>" not in segment:
                 fields_array.append(segment)
    
           del fields_array[:2]
    
           for x in range(0,len(fields_array)):
              if x%2<>0:
                 if fields_array[x-1] not in keep_fields:
                    fields_array[x]=fields_array[x].replace("td>","")
                    values_array.append(fields_array[x])
    
           for y in range(0,len(values_array)):
              try:
                 row[y] = values_array[y]
                 UC.updateRow(row)
              except IndexError:
                 e_count = e_count + 1
    
  • Insert your Code in the answer. – BBG_GIS Nov 9 '17 at 23:11
0

If you are an ArcGIS user, don't want to use scripts, and just have a couple fields you want to preserve, you can do it manually using the field calculator and a VB script to extract the field(s) you want. I posted detailed steps in this thread: From .shp to .kml to .shp Without Losing Attributes

-3

As others have mentioned (including the horse's mouth), apparently ESRI excluded code to translate the Attributes, so to use ArcMap the user has to go through extra steps to split the data then rejoin it in ArcMap. Other GIS display/edit tools can be used to avoid these arduous extra steps.

  • I am not aware of a Linux version of ArcMap and am always sceptical of unreferenced bug reports for any software. Can you edit your answer to provide links to where to find either, please? – PolyGeo Mar 6 '15 at 2:38
  • 2
    As the 'owner' of the KML tool at Esri I can say: The ExtendedData elements inside a KML will not translate into field attributes when using the KML to Layer tool with ArcGIS at any version (9.3-10.3). This includes ArcMap on Windows, or ArcGIS Server on Linux. There is an enhancement request in to support this which we're considering for a future release. – KHibma Mar 6 '15 at 18:44
  • @KHibma have you seen the word doc in the OP ? link here: students.clarku.edu/~jdolansky/… – sirgeo Mar 6 '15 at 19:20
  • @sirgeo thats a nice little work around. – KHibma Mar 6 '15 at 19:44
  • @KHibma It looks nice on paper but it has some issues with execution. Will the Data Interop Extension you mentioned translate ExtendedData elements in a KML into a shp? If so, how much does it cost? – sirgeo Mar 6 '15 at 19:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.