Summary
This tool converts a 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 Earth, ArcGlobe, and Google Earth.
Usage
You can control the appearance of KML in two ways:
- If layer properties such as the HTML PopUp setting, display expression, and the alias for KMLSnippet are used, they will be used in the creation of the KML.
- When the layer properties are not set and the feature class contains certain attributes (fields), the field properties will be used in creating the KML. Layers that were originally created using the KML To Layer tool have attributes that define how KML will be created.
-
You can reduce the size of the output KMZ document if your layer has scale-dependent display properties and you choose an appropriate map output scale.
All KML and KMZ files are created in the WGS84 coordinate system. You need to be sure your layers will properly project if they aren't already in WGS84. You can use the Project tool to reproject your data prior to KML conversion if your projection requires a transformation.
To output a single raster image draped over topography, use the Return single composite image option.
Input features with attachments will be included in the output .kmz file. Be aware of the following conditions for attachments inside .kmz files.
- Attachments can dramatically increase the output file size.
- When consuming the KML file in a KML client, attachments are available from the KML pop-up.
- Attachments can be excluded by disabling the Maintain Attachments environment setting prior to running the tool.
- Not all KML clients support displaying attachments equally. Some KML client applications have better support for attachments like images and PDFs.
Syntax
LayerToKML(layer, out_kmz_file, {layer_output_scale}, {is_composite}, {boundary_box_extent}, {image_size}, {dpi_of_client}, {ignore_zvalue})
Parameter | Explanation | Data Type |
layer | The feature or raster layer or layer file (.lyr) to be converted to KML. | 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 Earth, ArcGlobe, and Google Earth. | File |
layer_output_scale (Optional) | The scale at which to export the layer. This parameter is used with any scale dependency, such as layer visibility or scale-dependent rendering. If the layer is not visible at the export scale, it will not be included in the created KML file. Any value, such as 0, can be used if there are no scale dependencies. If exporting a layer that is to be displayed as 3D vectors and the is_composite parameter is set to NO_COMPOSITE, you can set this parameter to any value, as long as your features do not have any scale-dependent rendering. Only numeric characters should be entered; for example, enter 20000 as the scale, not 1:20000 or 20,000. | Double |
is_composite (Optional) |
| 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 lower left and upper right (xmin, ymin, xmax, ymax). | Extent |
image_size (Optional) | Defines the vertical and horizontal resolution when the Return single composite image parameter is used. Use this parameter with the DPI parameter to control output image resolution. | Long |
dpi_of_client (Optional) | Defines the device resolution for KML output when the Return single composite image parameter is used. Use this parameter with the image_size parameter to control output image resolution. | Long |
ignore_zvalue (Optional) |
| Boolean |
Code sample
LayerToKML example 1 (Python window)
The following Python window script demonstrates how to use the LayerToKML function in immediate mode.
import arcpy
arcpy.env.workspace = "C:/data"
arcpy.LayerToKML_conversion("bldg.lyr", "bldg.kmz")
LayerToKML example 2 (stand-alone script)
The following Python script demonstrates how to use the LayerToKML function in a stand-alone script.
# Name: LayerToKML Example
# Description: The following stand-alone 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 arcpy
# Set environment settings
arcpy.env.workspace = "C:/data"
# 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 = 96
clamped = 'CLAMPED_TO_GROUND'
for scale in range(10000, 30001, 10000):
# Strips the '.lyr' and adds scale + _.kmz
outKML = layer[:4] + str(scale) + "_.kmz"
#Execute LayerToKML
arcpy.LayerToKML_conversion(layer, outKML, scale, composite,
'', pixels, dpi, clamped)
else:
arcpy.AddMessage('There are no layer files in '+arcpy.env.workspace+'.')
Environments
Licensing information
- Basic: Yes
- Standard: Yes
- Advanced: Yes