Select to view content in your preferred language

Add VTPK To Map via 'arcpy'

1682
2
Jump to solution
02-16-2021 02:42 PM
Labels (1)
WilliamCraft
MVP Regular Contributor

Does anyone know how to add a vector tile package (VTPK) to a map using 'arcpy'?  I have tried a variety of different syntaxes but my Python code always errors out whether I use the 'addLayer' method or 'addDataFromPath' method.  

I have about 500+ VTPK files that I need to 'merge' together and what I'm thinking of doing is creating a mobile map package (MMPK) once I can get them added to a map in an automated way.  

Thanks in advance for your help.

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
WilliamCraft
MVP Regular Contributor

Thank you for responding.  After playing with the code some more, this ended up working for me:

import arcpy, os

outputLocation = r"C:\TEMP"

aprx = arcpy.mp.ArcGISProject(outputLocation + "/VTPK.aprx")

m = aprx.listMaps("VTPK")[0]

basemap = m.listLayers("Basemap")[0]

for filename in os.listdir(outputLocation):
    if filename.endswith(".vtpk"):
        lyr = m.addDataFromPath(outputLocation + "/" + filename)
        m.addLayerToGroup(basemap, lyr)
        aprx.save()
        continue
    else:
        continue

 

View solution in original post

2 Replies
JoshuaBixby
MVP Esteemed Contributor

It helps to provide both code and errors.  I thought I had used addDataFromPath with VTPK in the past, so I tested it again and it works fine for me.

WilliamCraft
MVP Regular Contributor

Thank you for responding.  After playing with the code some more, this ended up working for me:

import arcpy, os

outputLocation = r"C:\TEMP"

aprx = arcpy.mp.ArcGISProject(outputLocation + "/VTPK.aprx")

m = aprx.listMaps("VTPK")[0]

basemap = m.listLayers("Basemap")[0]

for filename in os.listdir(outputLocation):
    if filename.endswith(".vtpk"):
        lyr = m.addDataFromPath(outputLocation + "/" + filename)
        m.addLayerToGroup(basemap, lyr)
        aprx.save()
        continue
    else:
        continue