Layer To KML (Conversion)

Summary

Converts a feature or raster layer to KML format (.kmz or .kml file). The output KML will contain a translation of Esri feature geometries, raster cells, layer symbology, and other properties.

Learn more about KML support in ArcGIS

Usage

  • The default output of the tool has the .kmz extension, which is an archive or .zip file containing a .kml file and other supplemental files. A .kmz file can be read by many applications including ArcGIS Earth and Google Earth.

  • You can control the appearance of KML in the following two ways:

    • By default, the pop-up display is composed of all visible fields from the layer. Pop-up displays can also be set using the layer's customized pop-ups. If the layer pop-ups have not been customized, the values in the feature layer's PopupInfo field are shown in the pop-up when a KML feature is clicked. These values can be numeric or text attributes as well as HTML code stored in a text field.
    • When the layer properties are not set and the feature class contains certain attributes (fields), the field properties are used in creating the KML layers that were originally created using the KML To Layer tool including attributes that define how KML is created. See KML conversion for more information about creating KML from attributes.

  • If the input has scale-dependent display properties, reduce the size of the output .kmz file by providing an appropriate Layer Output Scale parameter value.

  • The input layer will be projected to WGS84, as all .kml and .kmz files must use that coordinate system. To ensure that the projection locates features and raster cells accurately, you may need to specify the geographic transformation environment. Alternatively, use the Project tool to re-project the input layer to WGS84 with a valid transformation before converting to KML.

  • Input features with attachments will be included in the output .kmz file. Be aware of the following conditions for attachments in .kmz files:

    • Attachments can significantly increase the output file size.
    • When using 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 before running the tool.
    • Not all KML clients support displaying attachments equally. Some KML client applications have better support for attachments such as images and PDFs.

    Attachments will not be included if the output is a .kml file.

  • The Layer Output Scale and Size of Returned Image (Pixels) parameters are used together to create tiled output. For example, for an image with a size of 7000 by 5000 pixels, and a Size of Returned Image (Pixels) parameter value of 1000 pixels, the output image will be composed of 7 x 5, or 35, subimages. If the Layer Output Scale parameter value is 1, each subimage will be 1000 by 1000 pixels. If the Layer Output Scale parameter value is 10, each subimage will be 100 by 100 pixels.

  • Domain descriptions will be transferred to the output when the Transfer field domain descriptions environment is checked.

Parameters

LabelExplanationData Type
Input Layer

The feature or raster layer or group layer that will be converted to KML format.

Feature Layer; Raster Layer; Mosaic Layer; Group Layer; Layer File
Output File (KML or KMZ)

The output .kml or .kmz file. The output file can use the .kmz extension to produce an archive or zipped file, or the .kml extension to produce a basic KML format file. An output .kmz file is the default.

Output .kmz files support raster layers, symbology and other layer properties, attachments, and other advanced features. Output .kml files will use basic KML symbols and properties.

File; Workspace; KML Layer
Layer Output Scale
(Optional)

The scale of the output file. For raster layers, a value of 0 can be used to create one untiled output image. If a value greater than or equal to 1 is used, it will determine the output resolution of the raster. This parameter has no effect on layers that are not raster layers.

Double
Return single composite image
(Optional)

Specifies whether the output will be a single composite image. This parameter only applies if you specify the output KML as a .kmz file, as output .kml files do not support ground overlay images or rasters.

  • Checked—The output 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 GroundOverlay. Use this option to reduce the size of the output file. When this option is used, individual features and layers in the .kml file cannot be selected. Only output .kmz files support images.
  • Unchecked—If the input layer has vector features, they will be preserved as KML vectors.
Boolean
Extent
(Optional)

The geographic extent of the layer to be converted. Only features or raster cells in this extent will be included in the output KML.

  • Current Display Extent Map View—The extent will be based on the active map or scene. This option is only available when there is an active map.
  • Draw Extent Square and Finish—The extent will be based on a rectangle drawn on the map or scene. This option will create a feature class in the project geodatabase and add a layer to the map. The feature class will have the same coordinate system as the map.
    Note:

    This option is not available in the Environments dialog box. It is only available from a tool parameter with an extent data type or from the Environments tab on a tool dialog box.

    Note:

    When the Enable and disable editing from the Edit tab editing option is checked, you must enable editing on the Edit ribbon tab to draw the extent.

  • Extent of a Layer Layer—The extent will be based on an active map layer. Use the drop-down list to choose an available layer or use the Extent of data in all layers option to get the combined extent of all active map layers, excluding the basemap. This option is only available when there is an active map with layers.

    Each map layer has the following options:

    • All Features Select All—The extent of all features in the layer.
    • Selected Features Area from Selected Features—The extent of the selected features in the layer.
    • Visible Features Extent Indicator—The extent of the visible features in the layer.
      Note:

      The extents from the Selected Features Area from Selected Features and Visible Features Extent Indicator options are only available for feature layers.

  • Browse Browse—The extent will be based on an existing dataset.
  • Clipboard Paste—The extent can be copied to and pasted from the clipboard.
    • Copy Extent Copy—Copies the extent coordinates and coordinate system to the clipboard.
    • Use Paste Extent Paste—Pastes the extent coordinates and, optionally, the coordinate system from the clipboard. If the clipboard values do not include a coordinate system, the extent will use the map’s coordinate system.
    Note:

    The extent coordinates are copied to and pasted from the clipboard using the same formatting and order as the ArcPy Extent object: x-min, y-min, x-max, y-max, and the spatial reference.

  • Reset Extent Reset—The extent will be reset to the default value.
  • Manually entered coordinates—The coordinates must be numeric values and in the active map's coordinate system.
    Caution:

    The map may use different display units than the entered coordinates. The use of a cardinal direction (N, S, E, W) is not supported. Use a negative value sign for south and west coordinates.

Extent
Size of Returned Image (Pixels)
(Optional)

The size of the tiles for raster layers if the Layer Output Scale parameter value is greater than or equal to 1. This parameter has no effect on layers that are not raster layers.

Long
Output Image DPI
(Optional)

The device resolution for KML output when the Return single composite image parameter is checked. Use this parameter with the Size of Returned Image (Pixels) parameter to control output image resolution.

This parameter does not resample source rasters. Input rasters will have a snapshot taken and included in the KML output as a simple .png image.

Long
Clamp features to ground
(Optional)

Specifies whether the z-values of the input features will be ignored and all features will be located, or clamped, at the ground elevation.

  • Checked—The z-values of the input features will be ignored and all features will be located, or clamped, at the ground elevation. If the input features do not have z-values, they will always be clamped to the ground. This is the default.
  • Unchecked—The z-values of the features will be maintained in the output KML. The features will be drawn in KML clients relative to sea level.
Boolean

arcpy.conversion.LayerToKML(layer, out_kmz_file, {layer_output_scale}, {is_composite}, {boundary_box_extent}, {image_size}, {dpi_of_client}, {ignore_zvalue})
NameExplanationData Type
layer

The feature or raster layer or group layer that will be converted to KML format.

Feature Layer; Raster Layer; Mosaic Layer; Group Layer; Layer File
out_kmz_file

The output .kml or .kmz file. The output file can use the .kmz extension to produce an archive or zipped file, or the .kml extension to produce a basic KML format file. An output .kmz file is the default.

Output .kmz files support raster layers, symbology and other layer properties, attachments, and other advanced features. Output .kml files will use basic KML symbols and properties.

File; Workspace; KML Layer
layer_output_scale
(Optional)

The scale of the output file. For raster layers, a value of 0 can be used to create one untiled output image. If a value greater than or equal to 1 is used, it will determine the output resolution of the raster. This parameter has no effect on layers that are not raster layers.

Double
is_composite
(Optional)

Specifies whether the output will be a single composite image. This parameter only applies if you specify the output KML as a .kmz file, as output .kml files do not support ground overlay images or rasters.

  • COMPOSITEThe output 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 GroundOverlay. Use this option to reduce the size of the output file. When this option is used, individual features and layers in the .kml file cannot be selected. Only output .kmz files support images.
  • NO_COMPOSITEIf the input has vector features, they will be preserved as KML vectors.
Boolean
boundary_box_extent
(Optional)

The geographic extent of the layer to be converted. Only features or raster cells in this extent will be included in the output KML. The extent can be specified using the following options:

  • MAXOF—The maximum extent of all inputs will be used.
  • MINOF—The minimum area common to all inputs will be used.
  • DISPLAY—The extent is equal to the visible display.
  • Layer name—The extent of the specified layer will be used.
  • Extent object—The extent of the specified object will be used.
  • Space delimited string of coordinates—The extent of the specified string will be used. Coordinates are expressed in the order of x-min, y-min, x-max, y-max.
Extent
image_size
(Optional)

The size of the tiles for raster layers if the layer_output_scale parameter value is greater than or equal to 1. This parameter has no effect on layers that are not raster layers.

Long
dpi_of_client
(Optional)

The device resolution for KML output when the is_composite parameter is set to COMPOSITE. Use this parameter with the image_size parameter to control output image resolution.

This parameter does not resample source rasters. Input rasters will have a snapshot taken and included in the KML output as a simple .png image.

Long
ignore_zvalue
(Optional)

Specifies whether the z-values of the input features will be ignored and all features will be located, or clamped, at the ground elevation.

  • ABSOLUTEThe z-values of the features will be maintained in the output KML. The features will be drawn in KML clients relative to sea level.
  • CLAMPED_TO_GROUNDThe z-values of the input features will be ignored and all features will be located, or clamped, at the ground elevation. If the input features do not have z-values, they will always be clamped to the ground. This is the default.
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.conversion.LayerToKML("buildings", "c:/outputKMZs/bldg.kmz")
LayerToKML example 2 (stand-alone script)

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

# 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

arcpy.env.workspace = "C:/data"

# Set Local Variables
composite = 'NO_COMPOSITE'
pixels = 2048
dpi = 96
clamped = 'CLAMPED_TO_GROUND'

# Use the ListFiles method to identify all lyr and lyrx files in workspace
layers = arcpy.ListFiles("*.lyr*") 

if len(layers) > 0:
    for layer in layers:        
        # Strips the '.lyr(x)' part of the name and appends '.kmz'
        outKML = os.path.join(os.path.splitext(layer), ".kmz")
        for scale in range(10000, 30001, 10000):
            # Run LayerToKML
            arcpy.conversion.LayerToKML(layer, outKML, scale, composite, 
                                        '', pixels, dpi, clamped)
else:
    arcpy.AddMessage('There are no layer files in {}'.format(arcpy.env.workspace))

Licensing information

  • Basic: Yes
  • Standard: Yes
  • Advanced: Yes

Related topics