Layer to KML (3D Analyst)

Summary

This tool converts an in-memory or file-based feature or raster layer into a KML file containing a translation of ESRI geometries and symbology. This file is compressed using ZIP compression, has a .kmz extension, and can be read by any KML client including ArcGIS Explorer, ArcGlobe, and Google Earth.

LegacyLegacy:

This tool was previously available in the 3D Analyst toolbox.

Usage

Syntax

LayerToKML_3d (layer, out_kmz_file, layer_output_scale, {is_composite}, {boundary_box_extent}, {image_size}, {dpi_of_client})
ParameterExplanationData Type
layer

The in-memory layer or layer file stored on disk that is to be converted to KML.

Feature layer
out_kmz_file

The KML file to write. This file is compressed and has a .kmz extension. It can be read by any KML client including ArcGIS Explorer, ArcGlobe, and Google Earth.

KML file
layer_output_scale

The scale at which to export the layer. Any scale-dependent rendering is observed, so if the layer is not visible at the export scale, it will not be included in the created KML file. The symbology for the layer is driven by this scale.

Only numeric characters should be entered. For example, enter "20000" as the scale, not 1:20000 or 20,000.

Furthermore, if you are exporting a layer that is to be displayed as 3D vectors—such as a point layer with the Return single composite image option disabled—and there is no scale-dependent rendering defined for the layer, then this parameter is not required for the export process and can be set to any numeric value, such as 1.

Double
is_composite
(Optional)
  • COMPOSITEThe output KML file will be a single composite image representing the raster or vector features in the source layer. The raster is draped over the terrain as a KML GroundOverlay. Select this option to reduce the size of the output KMZ file. When you check this box, individual features and layers in the KML are not selectable.
  • NO_COMPOSITEIf your layer has vector features, they are preserved as KML vectors. (If your layer is a raster, you can choose either option for this parameter without any visual difference.)
Boolean
boundary_box_extent
(Optional)

The geographic extent of the area to be exported. The extent rectangle bounds should be specified as a space-delimited string of WGS84 geographic coordinates in the form "left lower right upper".

Extent
image_size
(Optional)

Defines the vertical and horizontal resolution of any rasters in the output KML document.

Long
dpi_of_client
(Optional)

Define the device resolution for any rasters in the output KML document.

Long

Code Sample

Layer to KML Example 1 (Python window)

The following Python Window script demonstrates how to use the Layer to KML function in immediate mode.

import arcpy
from arcpy import env

env.workspace = "C:/data"
arcpy.LayerToKML_3d("bldg.lyr", "bldg.kmz", "1")
Layer to KML Example 2 (stand-alone script)

The following Python script demonstrates how to use the Layer to KML function in a stand-alone script.

'''*********************************************************************
Name: LayerToKML Example
Description: This script demonstrates how to find 
             all layer files in a given workspace and export each to 
             a KML at the 1:10,000, 1:20,000, and 1:30,000 scale using
             the LayerToKML tool.
**********************************************************************'''

# Import system modules
import arcpy
from arcpy import env

# Obtain a license for the ArcGIS 3D Analyst extension
arcpy.CheckOutExtension("3D")

# Set environment settings
env.workspace = "C:/data"

try:
    # Use the ListFiles method to identify all layer files in workspace
    if len(arcpy.ListFiles("*.lyr")) > 0:
        for layer in arcpy.ListFiles("*.lyr"):
            # Set Local Variables
            composite = 'NO_COMPOSITE'
            pixels = 2048
            dpi = 192
            # Strips the '.lyr' part of the name and appends '.kmz'
            outKML = file[:4] + ".kmz"
            for scale in range(10000, 30001, 10000):
               #Execute LayerToKML
               arcpy.LayerToKML_conversion(layer, outKML, scale, composite, 
                                         '', pixels, dpi)
    else:
        arcpy.AddMessage('There are no layer files in '+env.workspace+'.')

except Exception as e:
    print e.message

Environments

Licensing Information

ArcView: Requires 3D Analyst
ArcEditor: Requires 3D Analyst
ArcInfo: Requires 3D Analyst

6/10/2013