HOW TO

Add a WMTS to ArcGIS Online or Portal for ArcGIS with ArcGIS API for Python

Last Published: January 27, 2023

Summary

The process of adding a Web Map Tile Service (WMTS) to ArcGIS Online and Portal for ArcGIS using ArcGIS API for Python differs from the process of adding other item types. When using the 'arcgis.gis.ContentManager.add' method, the most important property to consider is the 'text' property.

A sample script to add a WMTS to ArcGIS Online and Portal for ArcGIS is shown below:

from arcgis import GIS

gis = GIS("https://machine.domain.com", "user", "password")

item_prop = {'title':'Test_WMTS',
             'url':'https://sampleURL/WMTS',
             'description': 'Test Add',
             'tags': 'ogc',
             'type': 'WMTS',
             'text': {"templateUrl":"https://sampleURL/WMTS/tile/1.0.0/sampleLayer/default/default028mm/{level}/{row}/{col}.png",
                      "copyright":"","fullExtent":{"xmin":-19840230.38989966,"ymin":2144435.340699963,"xmax":-7452840.465199874,"ymax":11536810.662599582,"spatialReference":{"wkid":102100}},"tileInfo":{"rows":256,"cols":256,"dpi":96,
                      "origin":{"x":-20037508.342787,"y":20037508.342787,"spatialReference":{"wkid":102100}},"spatialReference":{"wkid":102100},"lods":[{"level":0,"levelValue":"0","resolution":156543.03392798046,"scale":591658710.9089025},
                      {"level":1,"levelValue":"1","resolution":78271.5169639901,"scale":295829355.4544507},{"level":2,"levelValue":"2","resolution":39135.75848199517,"scale":147914677.72722584},{"level":3,"levelValue":"3",
                      "resolution":19567.879240997456,"scale":73957338.86361243},{"level":4,"levelValue":"4","resolution":9783.939620498726,"scale":36978669.43180621},{"level":5,"levelValue":"5","resolution":4891.969810249364,
                      "scale":18489334.715903107},{"level":6,"levelValue":"6","resolution":2445.984905124682,"scale":9244667.357951554},{"level":7,"levelValue":"7","resolution":1222.992452562341,"scale":4622333.678975777},
                      {"level":8,"levelValue":"8","resolution":611.4962262813027,"scale":2311166.8394883885},{"level":9,"levelValue":"9","resolution":305.74811314051914,"scale":1155583.4197436941},{"level":10,"levelValue":"10",
                      "resolution":152.87405657039182,"scale":577791.7098723471},{"level":11,"levelValue":"11","resolution":76.43702828506362,"scale":288895.85493567353},{"level":12,"levelValue":"12","resolution":38.21851414253181,"scale":144447.92746783677},
                      {"level":13,"levelValue":"13","resolution":19.109257071265905,"scale":72223.96373391838}]},"wmtsInfo":{"url":"https://sampleURL/WMTS",
                      "layerIdentifier":"sampleLayer","tileMatrixSet":"default028mm"}},
             'extent': '-178.2278219969978,18.910787002877576,-66.95000499993604,71.38957425051252'
            }

add_wmts = gis.content.add(item_properties=item_prop)

The 'text' property determines how the WMTS is displayed, and proper definition of this property is essential for the service to display correctly.

Procedure

Follow the instructions below to add a WMTS to ArcGIS Online or Portal for ArcGIS using ArcGIS API for Python.

  1. Open the browser developer tools, and enable the Persist Logs/Preserve log option.
  2. Add the WMTS to the ArcGIS Online or Portal for ArcGIS Content page.
Add the WMTS to the ArcGIS Online or Portal for ArcGIS Content page
  1. Search for the addItem request. The 'arcgis.gis.ContentManager.add' method calls this REST operation to add items to the Content page.
  2. Copy the contents of the text property, and paste it into the script. The service displays as expected.
Copy the contents of the text property, and paste it into the script

Article ID:000021946

Software:
  • ArcGIS API for Python

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic