Exporting Feature to KMZ in the batch mode

7166
4
03-24-2015 12:27 PM
AhmedAbdelnasser1
New Contributor III

Hi,

am facing a problem exporting features to KMZ please if any one could help .

well  i am exporting a huge number  of features  almost  "1800"  so am using  export layer to kml  in the batch mode .

so here's the problems  the tool just truncated the names of the features  but if i entered the full name by typing , it exports it pretty will !

so how can i export the features  with there names  there must be a way to do it beside typing name for each !  . right ?

0 Kudos
4 Replies
DarrenWiens2
MVP Honored Contributor

See this help page for how to use the Check Values button to generate output file names, based on inputs:

GUID-9803A4E7-CA14-4BE7-BA15-E1FA8C2B9BAD-web.png

0 Kudos
AhmedAbdelnasser1
New Contributor III

thank you  Darren ,


i see  the link you sent  but it doesn't  work  for my case here .

the out buts are  based in the inputs but its not the exact same  , in my case when i Check Values button to validate the output ,

the names truncated to a smaller names !

i need it to be the same as the input without the need to do it one by one .

i need the arc to automatically  generates output but with the exact names given in the input .

is that possible ?!

thank you .

0 Kudos
DarrenWiens2
MVP Honored Contributor

Probably not possible in batch processing. Possibly possible in model builder using an iterator. Definitely possible using python.

MatthewRusso
New Contributor II

Ahmed,

I have a python script that searches through a directory/geodatabase and creates KMZ files.

What it does is create an replica of the input workspace(folder/geodatabase) and produce .kmz files.

Not sure how familiar you are with python but I will copy my code here:

def export_to_kml(input_workspace, output_workspace):
    """
    This function extracts the feature classes from a geodatabase
    and converts them to .kmz files directory structure is maintained
    by folders being created based on the feature dataset.
    input_workspace ==> Path to a: Geodatabase, Folder which contains
    Feature Classes or Shapefiles.  (EX: 'H:\GIS DATA\Counties.gdb')
    output_workspace ==> Path to the location you want the .kmz files
    to go.  (EX: 'H:\GIS DATA')
    """
    # Searches through all sub-directories within the input workspace
    import os
    for dirpath, dirnames, filenames in arcpy.da.Walk(input_workspace):
        for dirname in dirnames:
            # vars
            dir_path = os.path.join(dirpath, dirname)
            arcpy.env.workspace = dir_path
            fcs = arcpy.ListFeatureClasses()
            print("Processing Feature Dataset/Folder:{0}\nFeature Classes/Shapefiles:{1}\n".format(dir_path, fcs))
            arcpy.CreateFolder_management(output_workspace, dirname)
            suboutput = os.path.join(output_workspace, dirname)
            count = 0
            for fc in fcs:
                print("Converting: {0}".format(fc))
                count = count + 1
                layer = 'layer' + fc
                out_kmz_file = os.path.join(suboutput, fc + '.kmz')
                layer_output_scale = 0
                is_composite = 'false'
                boundary_box_extent = '#'
                image_size = 1024
                dpi = 300
                zvalue = 'CLAMPED_TO_GROUND'
                arcpy.MakeFeatureLayer_management(fc, layer) # Creates a layer to convert to the .kmz
                arcpy.LayerToKML_conversion(layer, out_kmz_file, layer_output_scale, is_composite,
                                            boundary_box_extent, image_size, dpi, zvalue)
                print("{0} complete\n".format(count))

The way that you can run this is by opening the python window and copy and pasting this script(attched a .txt to make it easy) into the command line.

from there you can type out:

>>>export_to_kml('H:\input\geodatabase.gdb', 'C:\Users\XXXXX\Desktop\kmz')
 # first value is your input folder/gdb second value is your output location

Let me know if you need any help with it

Also this will create the kmz file with the orginal name of your shapefile/feature class