Create and Publish TPK for Offline Use

Blog Post created by r3weber on Oct 21, 2019

We create tile packages for field workers fairly frequently so they can have additional maps available to them when they go offline in the field.  Typically this process has involved several different tools depending on the particular map or imagery that is needing to be tiled.  Generally, I have found the ManageTileCache and ExportTileCache GP tools to be most reliable.  So recently I started thinking about combining them along with the Python API so we could have one tool to use for publishing TPK's to our AGOL Org. Any feedback or suggestions would be greatly appreciated.


Basic outline of what the tool does:

  1. Make connection and get a token from your portal with whatever credentials are being used in Pro
  2. Take an input raster dataset
  3. Create a new folder for outputs in the same directory as the input dataset
  4. Allow user to name output dataset
  5. Run ManageTileCache tool to create a local tile cache ( by default the entire extent of the input dataset is used and LOD's are created based off of the input data source pixel information)
  6. Run ExportTileCache tool to create local tpk file
  7. Report file size info back via arcpy Messages
  8. Add tpk item to portal
  9. Attempt to publish the tpk as hosted tile layer
    • Publishing a tpk item seemed to need the additional step of making a POST via the REST api to actually unpack and publish the tiles using '/updateTiles' contained in the tpk  this is done using requests.post just simply using publish() with the python api tended to fail at going beyond creating the hosted tile layer.
  10. Uses urllib to get additional info about the hosted tile layer and LOD's being published.


This tool has been handy in certain situations for us and I hope it is for someone else too.  Still I am always interested if someone has a better way of doing this.