Open or add WMS using arcpy

396
4
Jump to solution
11-17-2021 03:25 AM
Labels (1)
ToyotaT18
New Contributor III

I'm trying to work out how to open or add a wms layer to a map using arcpy.

I have the service url, the image name etc. I can open it manually, but I need to do this using arcpy. (Without saving a lyrx file etc)

Appreciate any assistance, thanks

0 Kudos
1 Solution

Accepted Solutions
ToyotaT18
New Contributor III

Ok I came up with a hack solution, I opened one wms layer manually then created a layer file (.lyrx) for this. I then use this as a 'template', my python code replaces the image name text with the new image name, then I open that .lyrx file. Seems to work ok. It also requires the wms connection file (.wms) to be placed in the project folder, if the connection doesn't already exist for the project.

View solution in original post

0 Kudos
4 Replies
ABishop
Regular Contributor III

Hello,

What do you need to do with the WMS layer after open it?  I possibly can help you download it to a location on your PC using arcpy.

Amanda Bishop, GISP
0 Kudos
ToyotaT18
New Contributor III

Hi, I just want to add the image to the current map.

Same as if I opened it manually: https://pro.arcgis.com/en/pro-app/latest/help/data/services/add-wms-services.htm

ToyotaT18
New Contributor III

Ok I came up with a hack solution, I opened one wms layer manually then created a layer file (.lyrx) for this. I then use this as a 'template', my python code replaces the image name text with the new image name, then I open that .lyrx file. Seems to work ok. It also requires the wms connection file (.wms) to be placed in the project folder, if the connection doesn't already exist for the project.

0 Kudos
ABishop
Regular Contributor III

I was going to suggest something similar.  Glad you got it worked out.

Amanda Bishop, GISP
0 Kudos