Layer To KML

Title  Layer To KML

Summary

Geoprocessing tool that converts a feature or raster layer into a Keyhole Markup Language (KML) file.


Usage


Syntax

Parameter Explanation
layer

The feature or raster layer or layer file (.lyr) to be converted to KML.

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.

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.

A scale value of 0 is an override switch to ignore scale dependencies set on the layer. Any actual scale value will produce a KML with the layers visible at the given input.

If exporting a layer that is to be displayed as 3D vectors and the Return single composite image parameter is unchecked, 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.

This parameter does not control the output resolution of a raster.

is_composite (Optional)
  • Checked—The 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.
  • Unchecked—If 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.
boundary_box_extent (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.

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.

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.

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.

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.

ignore_zvalue (Optional)
  • Checked—You can override the Z-values inside your features or force them to be clamped to the ground. You should use this setting if you are not working with 3D features or have features with Z-values that might not honor values relative to sea level. This is the default.
  • Unchecked—The output KML file will be created, which respects the Z-values of features. Your output KML features will be set to the absolute value, which could place features below the earth's surface in some KML clients. Most KML clients allow you to set the display mode for features when viewing the KML file.

    Most KML viewers set absolute as sea level and draw features with elevation (Z-values) based on that value.

Code Samples

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+'.')


                    

Tags

Credits

Use limitations