ArcGIS for Desktop

  • Documentation
  • Pricing
  • Support

  • My Profile
  • Help
  • Sign Out
ArcGIS for Desktop

ArcGIS Online

The mapping platform for your organization

ArcGIS for Desktop

A complete professional GIS

ArcGIS for Server

GIS in your enterprise

ArcGIS for Developers

Tools to build location-aware apps

ArcGIS Solutions

Free template maps and apps for your industry

ArcGIS Marketplace

Get apps and data for your organization

  • Documentation
  • Pricing
  • Support
Esri
  • Sign In
user
  • My Profile
  • Sign Out

Help

  • Home
  • Get Started
  • Map
  • Analyze
  • Manage Data
  • Tools
  • More...

Map To KML

Available with 3D Analyst license.

  • Summary
  • Usage
  • Syntax
  • Code sample
  • Environments
  • Licensing information

Summary

This tool converts a map document into a KML file containing a translation of Esri geometries and symbology. This file is compressed using ZIP compression, will have a .kmz extension, and can be read by any KML client including ArcGIS Explorer, ArcGlobe, and Google Earth.

Learn more about KML support in ArcGIS

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.

    Learn more about creating KML in ArcGIS for Desktop

  • You can reduce the size of the output KMZ document if your map has scale-dependent layer display properties and you choose an appropriate map output scale.

  • All KML/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.

  • To output every layer as a separate raster image, use the Convert Vector to Raster option.

Syntax

MapToKML_conversion (in_map_document, data_frame, out_kmz_file, {map_output_scale}, {is_composite}, {is_vector_to_raster}, {extent_to_export}, {image_size}, {dpi_of_client}, {ignore_zvalue})
ParameterExplanationData Type
in_map_document

The map document to convert to KML.

ArcMap Document
data_frame

The data frame of the map document to convert to KML.

String
out_kmz_file

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

File
map_output_scale
(Optional)

The scale at which to export each layer in the map. This parameter is important 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 1, 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)
  • COMPOSITE —Directs the output KML file to contain only a single image that composites all the features in this map into a single raster image. 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. Also, the next parameter, is_vector_to_raster, is ignored.
  • NO_COMPOSITE —Layers are returned separately in the KML. Whether the layers are returned all as rasters or as a mix of vectors and rasters is determined by the next parameter, is_vector_to_raster.
Boolean
is_vector_to_raster
(Optional)
  • VECTOR_TO_RASTER —Converts each vector layer in the map into a separate raster image in the KML output. Normal raster layers are also added to the KML output. Each output KML raster layer is selectable, and its transparency can be adjusted in certain KML clients.
  • VECTOR_TO_VECTOR —Preserves vector layers in the map as KML vectors.
Boolean
extent_to_export
(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 (xmin, ymin, xmax, ymax).

Extent
image_size
(Optional)

Size of returned image in pixels. Defines the vertical and horizontal resolution of any rasters in the output KML document. Use this parameter with the DPI parameter to control output image resolution.

Long
dpi_of_client
(Optional)

Defines the device resolution for any rasters in the output KML document. Typical screen resolution is 96 dpi. If the data inside your map supports a high resolution and your KML requires it, consider increasing the value. Use this parameter with the Image Size parameter to control output image resolution.

Long
ignore_zvalue
(Optional)
  • ABSOLUTE —Use the Z-values of features when creating KML. The features will be drawn inside KML clients relative to sea level.
  • CLAMPED_TO_GROUND —Override Z-values in your features and create KML with the features clamped to the ground. The features will be draped over the terrain. This setting is used for features that do not have Z-values. This is the default.
Boolean

Code sample

MapToKML example 1 (Python window)

The following Python window script demonstrates how to use the MapToKMLfunction in immediate mode.

import arcpy
from arcpy import env

env.workspace = "C:/data"
arcpy.MapToKML_3d("city.mxd", "Layers", "city.kmz", "1")
MapToKML example 2 (stand-alone script)

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

'''*********************************************************************
Name: MapToKML Example
Description: This script demonstrates how to find 
             all map documents 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 MapToKML tool.
'''

# Import system modules
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('*.mxd')) > 0:
    for mxd in arcpy.ListFiles('*.mxd'):
        # Set Local Variables
        dataFrame = 'Layers'
        composite = 'NO_COMPOSITE'
        vector = 'VECTOR_TO_VECTOR'
        pixels = 2048
        dpi = 96
        clamped = 'ABSOLUTE'
        for scale in range(10000, 30001, 10000):
           # Strips the '.mxd' part of the name and appends '.kmz'
           outKML = mxd[:-4]+'.kmz'
           #Execute MapToKML
           arcpy.MapToKML_conversion(mxd, dataFrame, outKML, scale, 
                                   composite, vector, '', pixels, dpi, clamped)
else:
    arcpy.AddMessage('There are no map documents (*.mxd) in '+env.workspace)

Environments

  • Current Workspace
  • Extent
  • Scratch Workspace

Licensing information

  • ArcGIS for Desktop Basic: Yes
  • ArcGIS for Desktop Standard: Yes
  • ArcGIS for Desktop Advanced: Yes

Related topics

  • An overview of the To KML toolset
  • What is KML?
  • A quick tour of KML in ArcGIS
  • Essential KML vocabulary
  • Creating KML in ArcGIS for Desktop

ArcGIS for Desktop

  • Home
  • Documentation
  • Pricing
  • Support

ArcGIS Platform

  • ArcGIS Online
  • ArcGIS for Desktop
  • ArcGIS for Server
  • ArcGIS for Developers
  • ArcGIS Solutions
  • ArcGIS Marketplace

About Esri

  • About Us
  • Careers
  • Insiders Blog
  • User Conference
  • Developer Summit
Esri
Tell us what you think.
© Copyright 2016 Environmental Systems Research Institute, Inc. | Privacy | Legal