Using ExportTileCache_management to create tiled packages dynamically

Discussion created by akajanus-esristaff Employee on May 20, 2013
Latest reply on May 27, 2013 by akajanus-esristaff

I have tried to create a service that takes polygon / envelope as a parameter and returns string that contains URL to TiledPackage that is created by the python script but I cant get even prototype working. This is my first touch to python and ArcGIS Geoprosessing.

I have created python script that takes polygon to extract and package name as a parameters. Then I have default values hard coded and then I call arcpy.ExportTileCache_management with those values. As a result, I get TiledPackage that is about size 164 kb regardless what polygon I give.

I have cache stored on a external USB drive.

Any pointers?

# -*- coding: utf-8 -*-
import arcpy
import os
import sys
import traceback

arcpy.env.overwriteOutput = True

# Get parameters for the script
polygonToExtract = arcpy.GetParameterAsText(0)
packageName = arcpy.GetParameterAsText(1)

# Set default values for extract tool
cacheSource = r"L:\Taustakartta\Cache_taustakartta\Taustakartta\Taustakartta" 
cacheTarget = r"T:\TilePackages" 
cacheName = packageName 
cacheType = "TILE_PACKAGE" 
storageFormat = "COMPACT" 
scales = "8000000;4000000;2000000;800000;300000;160000;80000;50000;25000;10000" 
areaofinterest = polygonToExtract

    arcpy.ExportTileCache_management(cacheSource, cacheTarget, cacheName, cacheType, storageFormat, scales, polygonToExtract)
except arcpy.ExecuteError: 
    # Get the tool error messages 
    msgs = arcpy.GetMessages(2) 

    # Return tool error messages for use with a script tool 

    # Print tool error messages for use in Python/PythonWin 
    print msgs

    # Get the traceback object
    tb = sys.exc_info()[2]
    tbinfo = traceback.format_tb(tb)[0]

    # Concatenate information together concerning the error into a message string
    pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
    msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages(2) + "\n"

    # Return python error messages for use in script tool or Python Window

    # Print Python error messages for use in Python / Python Window
    print pymsg + "\n"
    print msgs

print "-- Script completed --"