Select to view content in your preferred language

add WMTS-Service as basemap to web map with Python

772
2
08-30-2023 05:58 AM
Labels (2)
MichaelNüßlein
New Contributor III

Hi, trying to add a service as basemap to a web map with Python (ArcGIS Pro 3.1) (manually i can do this in Portal 11.1 analogue screenshot  below).  

MichaelNlein_1-1693399979113.png

 

Unfortunately i don't find any example how to do this. 

thanks for any help.

0 Kudos
2 Replies
PeterHodkinson
Esri Contributor

Hi @MichaelNüßlein 

I found documentation on adding WMTS layers here: https://developers.arcgis.com/python/samples/publish-ogc-services/

For instance the following worked for me

from arcgis.gis import GIS
from arcgis.mapping.ogc import WMTSLayer
from arcgis.mapping import WebMap

gis = GIS("home")

wmts_url = "https://wayback.maptiles.arcgis.com/arcgis/rest/services/world_imagery/wmts"

m = gis.map()
m.add_layer(WMTSLayer(url=wmts_url))
m

 

I hope this is helpful!

MichaelNüßlein
New Contributor III

It works with Portal 10.9.1 but not with Portal 11.1. Perhaps because the WMTS-Url "https://wayback.maptiles.arcgis.com/arcgis/rest/services/world_imagery/wmts" is not valid

The error message with Portal 11.1 is:

Traceback (most recent call last):
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\urllib3\connection.py", line 174, in _new_conn
conn = connection.create_connection(
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\urllib3\util\connection.py", line 72, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\socket.py", line 954, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\urllib3\connectionpool.py", line 386, in _make_request
self._validate_conn(conn)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\urllib3\connectionpool.py", line 1042, in _validate_conn
conn.connect()
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\urllib3\connection.py", line 358, in connect
self.sock = conn = self._new_conn()
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\urllib3\connection.py", line 186, in _new_conn
raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x0000022DB91FF160>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\requests\adapters.py", line 489, in send
resp = conn.urlopen(
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\urllib3\connectionpool.py", line 815, in urlopen
return self.urlopen(
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\urllib3\connectionpool.py", line 815, in urlopen
return self.urlopen(
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\urllib3\connectionpool.py", line 787, in urlopen
retries = retries.increment(
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\urllib3\util\retry.py", line 592, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='wayback.maptiles.arcgis.com', port=443): Max retries exceeded with url: /arcgis/rest/services/world_imagery/wmts?service=WMTS&request=GetCapabilities&version=1.0.0&token=ZoYz_-geL4L5e2Pbj6cQkz1sN-2ZMH9zIgLtN5cOHGXBEJx_2eCFVTjrm94O2zoTzAkNGCisuk1LEZ09m16O9-xhZvFi5s9Pc_GaOAmqs4E5xtn_EaKamfVZBgQV1nhNUETn2aZH2HneAZIg_-vMjc1UGKeSkbUpnKTtjDeuw3ruFeJ_GQGdEVvz5PqEBm3Lr0BIQFlVyoYPAnCWzvGr1ekm3p_tYft0_mMtCDTPQVynabc617qqOWW_K-KmxxVY (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x0000022DB91FF160>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 829, in get
resp = self._session.get(
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\auth\api.py", line 437, in get
return self._session.get(
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\requests\sessions.py", line 600, in get
return self.request("GET", url, **kwargs)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\requests\sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\requests\sessions.py", line 701, in send
r = adapter.send(request, **kwargs)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\requests\adapters.py", line 565, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='wayback.maptiles.arcgis.com', port=443): Max retries exceeded with url: /arcgis/rest/services/world_imagery/wmts?service=WMTS&request=GetCapabilities&version=1.0.0&token=ZoYz_-geL4L5e2Pbj6cQkz1sN-2ZMH9zIgLtN5cOHGXBEJx_2eCFVTjrm94O2zoTzAkNGCisuk1LEZ09m16O9-xhZvFi5s9Pc_GaOAmqs4E5xtn_EaKamfVZBgQV1nhNUETn2aZH2HneAZIg_-vMjc1UGKeSkbUpnKTtjDeuw3ruFeJ_GQGdEVvz5PqEBm3Lr0BIQFlVyoYPAnCWzvGr1ekm3p_tYft0_mMtCDTPQVynabc617qqOWW_K-KmxxVY (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x0000022DB91FF160>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "\\N5006021\Benutzer\MuellerA345\Eigene Dateien\PortalForArcGIS\Automatisierung\script_datenbereitstellung\publishgeodata.py", line 667, in <module>
runForServer(server_url, p)
File "\\N5006021\Benutzer\MuellerA345\Eigene Dateien\PortalForArcGIS\Automatisierung\script_datenbereitstellung\publishgeodata.py", line 521, in runForServer
publishBasemaps(gis, item_category_json, license_text)
File "\\N5006021\Benutzer\MuellerA345\Eigene Dateien\PortalForArcGIS\Automatisierung\script_datenbereitstellung\publishgeodata.py", line 343, in publishBasemaps
m.add_layer(WMTSLayer(url=wmts_url))
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\widgets\_mapview\_mapview.py", line 1505, in add_layer
self._add_layer_to_widget(item, options)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\widgets\_mapview\_mapview.py", line 1597, in _add_layer_to_widget
self._add_layer_to_webmap(item, options)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\widgets\_mapview\_mapview.py", line 1510, in _add_layer_to_webmap
self.webmap.add_layer(item, webmap_options)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\mapping\_types.py", line 515, in add_layer
new_layer = self._create_layer_definition(layer, options)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\mapping\_types.py", line 924, in _create_layer_definition
new_layer = {**new_layer, **layer._operational_layer_json}
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\mapping\ogc\wmts.py", line 275, in _operational_layer_json
return self.__text__
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\mapping\ogc\wmts.py", line 204, in __text__
if isinstance(self.properties.Capabilities.Contents.Layer, (list, tuple)):
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\mapping\ogc\wmts.py", line 87, in properties
text = self._con.get(url, {}, try_json=False, add_token=False)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 843, in get
raise requests.exceptions.ConnectionError(
requests.exceptions.ConnectionError: A connection error has occurred: HTTPSConnectionPool(host='wayback.maptiles.arcgis.com', port=443): Max retries exceeded with url: /arcgis/rest/services/world_imagery/wmts?service=WMTS&request=GetCapabilities&version=1.0.0&token=ZoYz_-geL4L5e2Pbj6cQkz1sN-2ZMH9zIgLtN5cOHGXBEJx_2eCFVTjrm94O2zoTzAkNGCisuk1LEZ09m16O9-xhZvFi5s9Pc_GaOAmqs4E5xtn_EaKamfVZBgQV1nhNUETn2aZH2HneAZIg_-vMjc1UGKeSkbUpnKTtjDeuw3ruFeJ_GQGdEVvz5PqEBm3Lr0BIQFlVyoYPAnCWzvGr1ekm3p_tYft0_mMtCDTPQVynabc617qqOWW_K-KmxxVY (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x0000022DB91FF160>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))

0 Kudos