Can't figure out how to do it with specified layers. Current code:
from arcgis.gis import GIS import getpass password=getpass.getpass() gis = GIS(url="https://xxxx.vic-metria.nu/arcgis/", username="xxxx", password=password) sp={ 'title':'testJola1', 'description':'Test', 'tags':'Test', 'type':'WMS', 'url':'https://xxx.vic-metria.nu/WmsProxy/testmaps.metria.se/geoserver/wms', }item = gis.content.add(item_properties=sp)print("success!")
I tried your example, just change the url to national railway, it works fine.
item={
'title':'National railway',
'description':'Test',
'tags':'railway, national, wms',
'type':'WMS',
'url':'https://maps.geogratis.gc.ca/wms/railway_en?service=WMS&version=1.3.0&request=GetCapabilities&layers=railway&legend_format=image%2Fpng&feature_info_type=text%2Fhtml', }
items_wms = gis.content.add(item_properties=item)
print("items_wms: ", items_wms)
Thanks! I figure it out some time ago. I figure out how to use the property layers to register a service and work with a LIST OF LAYERS as:
from arcgis.gis import GIS
gis = GIS(portalUrl, portalUserName, portalPassword)
spatialReferences = [2400, 3006, 3007, 3008, 3009, 3010, 3011, 3012, 3013, 3014, 3015, 3016, 3017, 3018, 3021, 3031, 3032, 3033, 3035, 3785, 3857, 4326, 30061, 30062, 900913, 3152, 30063, 30064]
layers= [
{
"name": "railway.track",
"title": "Railway Track",
"queryable": True
},
{
"name": "railway.ferry",
"title": "Railway Ferry Route",
"queryable": True
}
]
text_json = {
"title": "National railway",
"url": "https://maps.geogratis.gc.ca/wms/railway_en",
"version": "1.3.0",
"layers": layers,
"maxHeight": 5000,
"maxWidth": 5000,
"spatialReferences": spatialReferences ,
"format": None,
"featureInfoFormat": "text/html"
}
item={
'title':'National railway',
'description':'Test',
'tags':'railway, national, wms',
'type':'WMS',
'url':'https://maps.geogratis.gc.ca/wms/railway_en',
'text': json.dumps(text_json)
}
items_wms = gis.content.add(item_properties=item)
print("items_wms: ", items_wms)
display(items_wms)
Thanks for sharing,
Bill
Hello everyone and thanks for the code which was very useful to me.
I have tested the code with a different url and different layer.name.
The code proposed by JohnLandeborg works fine with my url, but unfortunately it doesn't load the legend.
The BillXu code that loads the legend doesn't work on my url.
Any help is very much appreciated.
Thanks
Sabina
My code is the following:
import arcgis
from owslib.wms import WebMapService
import json
def carica_2_multi_wms(country, category,tag,title, urlWMS, i, layerTitolo):
# in input url e layer title
gis = arcgis.GIS(url='xxxx', username='xxxxx', password='xxxxxxxx', verify_cert=False)
wms = WebMapService(urlWMS, version='1.1.1')
print(str(wms.identification.title))
# find layer.name and verify Spatial reference
listalayers = [wms[layer] for layer in wms.contents]
layerN = "non buono"
for layer in listalayers:
if str(layer.title) == layerTitolo:
layerN = layer
print('Find ' + layerTitolo)
break
if "EPSG:3857" in layer.crsOptions:
print (" layer trovato con EPGS:3857")
break
else:
print('layer trovato ma SENZA EPGS:3857')
if layerN == "non buono":
print (layerTitolo + ' non trovato')
return layerN
EPGS = layerN.crsOptions
spatialReferences = layerN.crsOptions
#modify Spatial refence format
lista_SP = []
for un_sp in spatialReferences:
un_sp1 = un_sp.replace("EPSG:", ' ')
un_sp2 = int(un_sp1)
lista_SP.append(un_sp2)
layers= [
{
"name": layerN.name,
"title": layerN.title,
"queryable": True
}
]
text_json = {
"title": title,
"url": urlWMS,
"version": "1.3.0",
"layers": layers,
"maxHeight": 5000,
"maxWidth": 5000,
"spatialReferences": lista_SP,
#"format": None,
"featureInfoFormat": "text/html"
}
item = {
'title': str(i + 1) + " - " + country + " - " + title,
'description': 'test 1',
'tags': country + ' ' + tag,
'type': 'WMS',
'url': urlWMS,
'text': json.dumps(text_json),
'categories': category,
}
items_wms = gis.content.add(item_properties=item, folder='test_monitoring')
print("items_wms: ", items_wms)
urlWMS = 'http://wms.ign.gob.ar/geoserver/ows?service=wms&version=1.3.0&request=GetCapabilities'
carica_2_multi_wms('Paese', 'test', 'Teste', 'Test_26', urlWMS, 26, 'Establecimiento educativo')
maybe use 2 functions to do it, one is update the content, one is for update the popup link.
thanks for your answer. The problem was not in the code but in the portal proxy.