Map to KML (Conversion)

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 and will have a .kmz extension and can be read by any KML client including ArcGIS Explorer, ArcGlobe, and Google Earth.

LegacyLegacy:

This tool was previously available in the 3D Analyst toolbox.

Usage

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})
ParameterExplanationData Type
in_map_document

The map document to convert to KML.

Feature layer
data_frame

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

Data frame
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.

KML file
map_output_scale

The scale at which to export the map document. Any scale-dependent rendering will be observed, so layers that are not visible at the export scale will not be included in the created KML file. The symbology for the map will be driven by this scale, so if the map has a reference scale defined, it should be considered when setting this parameter.

Only numerical characters should be entered. For example, enter the scale as "20000", not 1:20,000 or 20,000.

Furthermore, if you are exporting a map containing only layers that will be displayed as 3D vectors and there is no scale-dependent rendering defined, this parameter is not required for the export process and can be set to any numeric value, such as 1.

Double
is_composite
(Optional)
  • COMPOSITEDirects 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_COMPOSITELayers 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_RASTERConverts 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_VECTORPreserves 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".

Extent
image_size
(Optional)

Size of returned image in pixels (optional): Defines the vertical and horizontal resolution of any rasters in the output KML document.

Long
dpi_of_client
(Optional)

Defines the device resolution for any rasters in the output KML document.

Long

Code Sample

Map To KML Example 1 (Python window)

The following Python Window script demonstrates how to use the Map To KML function in immediate mode.

import arcpy
from arcpy import env

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

The following Python script demonstrates how to use the Map To KML function 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
from arcpy import env

# Set environment settings
env.workspace = "C:/data"

try:
    # 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 = 192
            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)
    else:
        arcpy.AddMessage('There are no map documents (*.mxd) in '+env.workspace)

except Exception as e:
    print e.message
    

Environments

Related Topics

Licensing Information

ArcView: Yes
ArcEditor: Yes
ArcInfo: Yes

11/14/2011