【02】获取portal中服务地址的列表信息

场景1:获取portal门户中三维服务的地址列表

python 复制代码
#参考资料如下
#item type:https://developers.arcgis.com/rest/users-groups-and-items/items-and-item-types.htm
#https://developers.arcgis.com/python/guide/managing-your-content/

from arcgis.gis import GIS

##访问portal
# gis = GIS("portal门户地址", "portal账户", "portal密码", verify_cert=False)
gis = GIS("portal门户地址", "portal账户", "portal密码", verify_cert=False)


#
print("三维服务列表如下......")
# 访问portal中的三维服务
sceneService_result = gis.content.search(query="*", item_type="Scene Service", max_items=1000)
for item3 in sceneService_result:
    print(item3.title)  # 服务的名称
    print(item3.tags)#服务标签
    print(item3.description)#服务描述
    print(item3.title+": "+item3.url) #服务的名称和url
    for lyr in item3.layers:
        print(lyr.properties.name + "=" + lyr.url)

场景2:获取portal门户中常见服务的地址列表

python 复制代码
# 参考资料如下
# item type:https://developers.arcgis.com/rest/users-groups-and-items/items-and-item-types.htm
# https://developers.arcgis.com/python/guide/managing-your-content/

from arcgis.gis import GIS
import json
##访问portal
# gis = GIS("https://***你的portal门户地址***/portal", "portal门户账号", "portal门户密码", verify_cert=False)
gis = GIS("portal门户地址", "portal账户", "portal密码", verify_cert=False)

print("要素服务列表如下......")
# 访问portal中的要素服务
featureService_result = gis.content.search(query="*", item_type="Feature Service", max_items=1000)
for item1 in featureService_result:
    print(item1)
    print(item1.title + "=" + item1.url)  # 服务的名称和url
    print(item1.spatialReference)
    for lyr in item1.layers:
        print(lyr.properties.name + "=" + lyr.url)
        # print(lyr.properties.fields)
        # print(lyr.properties.fields)
        # print(json.dumps(lyr.properties.fields, ensure_ascii=False))
        for f in lyr.properties.fields:
            # print(f['name'],f['type'],f['length'])
            print(json.dumps(f['name'], ensure_ascii=False))


print("地图服务列表如下......")
# 访问portal中的地图服务
mapService_result = gis.content.search(query="*", item_type="Map Service", max_items=1000)
for item2 in mapService_result:
    print(item2)
    print(item2.title + "=" + item2.url)  # 服务的名称和url
    print(item2.spatialReference)
    for lyr in item2.layers:
        print(lyr.properties.name + "=" + lyr.url)
        print(lyr.properties.fields)
        # for f in lyr.properties.fields:
        # print(f['name'],f['type'],f['length'])

print("三维服务列表如下......")
# 访问portal中的三维服务
SceneService_result = gis.content.search(query="*", item_type="Scene Service", max_items=1000)
for item3 in SceneService_result:
    print(item3)
    print(item3.title + "=" + item3.url)  # 服务的名称和url
    print(item3.spatialReference)
    for lyr in item3.layers:
        print(lyr.properties.name + "=" + lyr.url)
        print(lyr.properties.fields)
        # for f in lyr.properties.fields:
        # print(f['name'],f['type'],f['length'])

print("影像服务列表如下......")
# 访问portal中的地图服务
mapService_result = gis.content.search(query="*", item_type="Image Service", max_items=1000)
for item4 in mapService_result:
    print(item4)
    print(item4.title + "=" + item4.url)  # 服务的名称和url
    print(item4.spatialReference)
    for lyr in item4.layers:
        print(lyr.properties.name + "=" + lyr.url)

场景3:获取portal门户中webmap的信息

python 复制代码
# 参考资料如下
# item type:https://developers.arcgis.com/rest/users-groups-and-items/items-and-item-types.htm
# https://developers.arcgis.com/python/guide/managing-your-content/

from arcgis.gis import GIS
from arcgis.mapping import WebMap
import json
##访问portal
gis = GIS("portal门户地址", "portal账号", "portal密码", verify_cert=False)
# 遍历webmap
map_result = gis.content.search(query="*", item_type="Web Map", max_items=1000)
for item1 in map_result:
    print(".........")
    print(item1)
    print(item1.title)
    web_map_obj = WebMap(item1)
    # print(web_map_obj.layers)
    for lyr in web_map_obj.layers:
        print( "layerUrl:"+lyr.url)
        print( "layerId:"+lyr.itemId)
相关推荐
爱学习的爬虫1 分钟前
Python实现Jenkins实现自动化执行Job
python·自动化·jenkins
一晌小贪欢24 分钟前
Python爬虫第9课:验证码识别与自动化处理
爬虫·python·自动化·网络爬虫·python爬虫·python3
bin915326 分钟前
AI工具赋能Python开发者:项目开发中的创意守护与效率革命
开发语言·人工智能·python·工具·ai工具
被放养的研究生29 分钟前
Python常用的一些语句
开发语言·python
Run Freely93732 分钟前
Python_封装案例
python
程序员爱钓鱼2 小时前
Python编程实战 · 基础入门篇 | 条件判断 if...else
后端·python
程序员爱钓鱼2 小时前
Python编程实战 · 基础入门篇 | 循环语句 for / while
后端·python
飞翔的佩奇8 小时前
【完整源码+数据集+部署教程】【天线&水】舰船战舰检测与分类图像分割系统源码&数据集全套:改进yolo11-repvit
前端·python·yolo·计算机视觉·数据集·yolo11·舰船战舰检测与分类图像分割系统
木头左9 小时前
最大回撤约束下ETF多因子动态止盈参数校准方案
python
汤姆yu9 小时前
2026版基于python的协同过滤音乐推荐系统
开发语言·python