Label | Explanation | Data Type |
Layer | The feature or raster layer or layer file (.lyrx) to be converted to KML. | Feature Layer; Raster Layer; Mosaic Layer; Group Layer; Layer File |
Output File | The output KML file. 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) | 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. If your layer is a raster, you can choose either option for this parameter without any visual difference.
| Boolean |
Extent to Export (Optional) | The geographic extent of the area to be exported. Either define the extent box (in the WGS84 coordinate system) or choose a layer or dataset that defines an extent.
| Extent |
Size of returned image (pixels) (Optional) | The size of the tiles for raster layers if the Layer Output Scale parameter value is set to a value greater than or equal to 1. This parameter has no effect on layers that are not raster layers. | Long |
DPI of output image (Optional) | The device resolution for KML output when the Return single composite image parameter is checked. This parameter is used with the Size of returned image (pixels) parameter to control output image resolution. This parameter does not provide the ability to resample source rasters. Any input rasters will have a snapshot taken and included in the KML output as a simple .png image. | Long |
Clamped features to ground
(Optional) | Specifies whether to override the z-values of the input features.
| Boolean |
Summary
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 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.
-
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. 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 parameter.
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 such as images and PDF documents.
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 set to 1, each subimage will be 1000 by 1000 pixels. If the Layer Output Scale parameter value is set to 10, each subimage will be 100 by 100 pixels.
Parameters
arcpy.conversion.LayerToKML(layer, out_kmz_file, {layer_output_scale}, {is_composite}, {boundary_box_extent}, {image_size}, {dpi_of_client}, {ignore_zvalue})
Name | Explanation | Data Type |
layer | The feature or raster layer or layer file (.lyrx) to be converted to KML. | Feature Layer; Raster Layer; Mosaic Layer; Group Layer; Layer File |
out_kmz_file | The output KML file. 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) | 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. 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. Specify the extent rectangle bounds 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) | The size of the tiles for raster layers if the layer_output_scale parameter value is set to a value 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. This parameter is used with the image_size parameter to control output image resolution. This parameter does not provide the ability to resample source rasters. Any input rasters will have a snapshot taken and included in the KML output as a simple .png image. | Long |
ignore_zvalue (Optional) | Specifies whether to override the z-values of the input features.
| Boolean |
Code sample
The following Python window script demonstrates how to use the LayerToKML function in immediate mode.
import arcpy
# "buildings" represents a layer in your map
arcpy.LayerToKML_conversion("buildings", "c:/outputKMZs/bldg.kmz")
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):
# Execute LayerToKML
arcpy.LayerToKML_conversion(layer, outKML, scale, composite,
'', pixels, dpi, clamped)
else:
arcpy.AddMessage('There are no layer files in {}'.format(arcpy.env.workspace))
Environments
Licensing information
- Basic: Yes
- Standard: Yes
- Advanced: Yes