Summary
Generates tiles from a map or basemap and packages the tiles to create a single compressed .tpk file.
Usage
The input map document must have a description and tags for the tool to execute. To add a description and tags, choose File > Map Document Properties from the main menu and enter a description and tags.
By choosing PNG for the Tiling Format parameter, the tool will automatically select the correct format (PNG8, PNG24, or PNG32) based on the specified Level of Display.
To unpack a map tile package, either drag the .tpk file into ArcMap or right-click the .tpk file in the Catalog window and select Unpack. Alternatively, you can use the Extract Package tool and specify an output folder.
By default, Unpack will always extract the package into your user profile under one of the following:
- XP—C:\Documents and Settings\<username>\My Documents\ArcGIS\Packages
- Vista and Windows 7—C:\Users\<username>\Documents\ArcGIS\Packages
To change the default location of where your packages will be unpacked, open ArcMap Options from the Customize menu. On the Sharing tab, in the Packaging section, check Use user specified location, and browse to the new folder location.
Syntax
arcpy.management.CreateMapTilePackage(in_map, service_type, output_file, format_type, level_of_detail, {service_file}, {summary}, {tags}, {extent}, {compression_quality}, {package_type}, {min_level_of_detail})
Parameter | Explanation | Data Type |
in_map | The map document from which tiles will be generated and packaged. | ArcMap Document |
service_type | Specifies whether the tiling scheme will be generated from an existing map service or whether map tiles will be generated for ArcGIS Online, Bing Maps, and Google Maps.
| Boolean |
output_file | The output map tile package. | File |
format_type | Specifies the format of the generated tiles.
| String |
level_of_detail | The maximum scale at which tiles will be generated for the package. The default is 1. Possible values are 1 through 24. Larger values reflect larger scales that show more detail but take more storage space, while smaller values reflect smaller scales that show less detail and take less storage space. This value must be greater than or equal to min_level_of_detail. | Long |
service_file (Optional) | The name of the map service or the XML files to use for the tiling scheme. This parameter is required only when the service_type parameter is EXISTING. | MapServer; File |
summary (Optional) | Adds summary information to the properties of the package. | String |
tags (Optional) | Adds tag information to the properties of the package. Multiple tags can be added, separated by a comma or semicolon. | String |
extent (Optional) | Specifies the extent by manually entering the coordinates in the extent parameter using the format X-Min Y-Min X-Max Y-Max. To use the extent of a specific layer, specify the layer name.
| Extent |
compression_quality (Optional) | A value between 1 and 100 for the JPEG compression quality. The default value is 75 for JPEG tile format and zero for other formats. Compression is supported only for JPEG and MIXED format. Choosing a higher value will result in a larger file size with a higher-quality image. Choosing a lower value will result in a smaller file size with a lower-quality image. | Long |
package_type (Optional) | Specifies the type of tile package that will be created.
| String |
min_level_of_detail (Optional) | The minimum scale at which tiles will be generated for the package. The default is 1. Possible values are 1 through 24. Larger values reflect larger scales that show more detail but take more storage space, while smaller values reflect smaller scales that show less detail and take less storage space. This value must be less than or equal to level_of_detail. | Long |
Code sample
CreateMapTilePackage example 1 (Python window)
The following Python script demonstrates how to use the CreateMapTilePackage tool from the Python window.
import arcpy
arcpy.env.workspace = "C:/TilePackageExample"
arcpy.CreateMapTilePackage_management("Example.mxd", "ONLINE", "Example.tpk", "PNG8", "10")
CreateMapTilePackage example 2 (stand-alone script)
Find and create map tile packages for all map documents that reside in a specified folder.
# Name: CreateMapTilePackage.py
# Description: Find all the map documents that reside in a specified folder and create tile packages for each map document.
# import system modules
import os
import arcpy
# Set environment settings
arcpy.env.overwriteOutput = True
arcpy.env.workspace = "C:/Tilepackages/"
# Loop through the workspace, find all the mxds and create a tile package using the same name as the mxd
for mxd in arcpy.ListFiles("*.mxd"):
print("Packaging " + mxd)
arcpy.CreateMapTilePackage_management(mxd, "ONLINE", os.path.splitext(mxd)[0] + ".tpk" "PNG8", "10")
Environments
Licensing information
- Basic: Yes
- Standard: Yes
- Advanced: Yes