通过python上传场景包至portal并发布三维服务
程序员文章站
2022-04-28 09:40:22
...
本篇介绍下通过python脚本将multipatch多面体要素转成slpk上传并发布至portal的过程。
实现思路:
1、使用arcpy.management.Create3DObjectSceneLayerPackage()工具将数据转成slpk
2、使用arcpy.SignInToPortal()登录portal门户
3、使用arcpy.SharePackage_management() 共享包工具上传slpk
4、发布场景包。此过程需要导入ArcGIS API for Python中的arcgis.gis模块,该模块为ArcGIS Online或ArcGIS Enterprise中托管的gis提供了一个信息模型,它提供管理(创建、读取、更新和删除)GIS用户、组和内容的功能。
# -*- coding: utf-8 -*-
import arcpy
import os
import datetime
import arcgis
from arcgis.gis import GIS
wrks="D:/datastore0/slpk/"
outslpk="pro3d.slpk"
outputslpkpath= wrks+outslpk
# 将multipatch转成slpk
arcpy.management.Create3DObjectSceneLayerPackage(r'D:\myarcgispro\pro3d\dataToLayerFile.lyrx',outputslpkpath,
arcpy.SpatialReference(4326), None, 'DESKTOP')
print("打包成功")
# 发布三维服务
portalUrl = r"https://wl.arcgisonline.cn/portal"
portalUsername = "portaladmin"
portalpassword = "684985"
# 返回活动门户的 URL
arcpy.GetActivePortalURL()
print(arcpy.GetPortalInfo(portal_URL=arcpy.GetActivePortalURL()))
# 登录 portal
arcpy.SignInToPortal(portalUrl, portalUsername, portalpassword)
arcpy.SharePackage_management(outputslpkpath, portalUsername, portalpassword,
"summary", "test",
"Credits")
print("成功上传slpk")
gis = GIS(portalUrl, portalUsername, portalpassword, verify_cert=False)
slpkitem = gis.content.add({}, data=outputslpkpath, folder='wl')
slpkscenelayer = slpkitem.publish()
print("slpk publish success")
服务发布成功如下图: