ArcGIS Pro批量创建离线服务sd包

背景:

主要针对一个工程内有多个地图框项:

处理方法:通过Python脚本处理打包。

运行环境

在Pro的Python环境中去运行编写的Python脚本。

Python 脚本参考

python 复制代码
import arcpy
import os

# Set output file names
outdir = r"d:\data\out"
pth = r"C:\Users\Priva\Documents\GeoScene\Projects\MyProject23\MyProject23.aprx"
aprx = arcpy.mp.ArcGISProject(pth)

mapnames = []

for i, m in enumerate(aprx.listMaps()):
    print(f"{i} : {m.name}")
    #mapnames.append(m.name)
    service_name = m.name
    sddraft_filename = service_name + ".sddraft"
    sddraft_output_filename = os.path.join(outdir, sddraft_filename)
    sd_filename = service_name + ".sd"
    sd_output_filename = os.path.join(outdir, sd_filename)


    # Create MapServiceDraft and set metadata and server folder properties
    sddraft = arcpy.sharing.CreateSharingDraft("STANDALONE_SERVER", "MAP_SERVICE", service_name, m)
    #sddraft.credits = "These are credits"
    sddraft.description = "This is description"
    sddraft.summary = "This is summary"
    sddraft.tags = "tag1, tag2"
    #sddraft.useLimitations = "These are use limitations"
    #sddraft.serverFolder = "MyServerFolder"
    sddraft.offline = True
    sddraft.copyDataToServer = True

    # Create Service Definition Draft file
    sddraft.exportToSDDraft(sddraft_output_filename)

    # Stage Service
    print("Start Staging")
    arcpy.server.StageService(sddraft_output_filename, sd_output_filename)

print("finish")

这里代码是针对某个工程内的,如果多个工程,可以自己修改代码

官方帮助参考

其他相关参数等相关资料可参考官方帮助内容进行修改。

https://pro.arcgis.com/en/pro-app/latest/arcpy/sharing/mapservicedraft-class.htm

https://community.esri.com/t5/python-questions/why-does-calling-listmaps-return-multiples-of-the/td-p/1128506

相关推荐
码路飞1 天前
写了个 AI 聊天页面,被 5 种流式格式折腾了一整天 😭
javascript·python
曲幽1 天前
FastAPI压力测试实战:Locust模拟真实用户并发及优化建议
python·fastapi·web·locust·asyncio·test·uvicorn·workers
敏编程1 天前
一天一个Python库:jsonschema - JSON 数据验证利器
python
前端付豪1 天前
LangChain记忆:通过Memory记住上次的对话细节
人工智能·python·langchain
databook1 天前
ManimCE v0.20.1 发布:LaTeX 渲染修复与动画稳定性提升
python·动效
花酒锄作田2 天前
使用 pkgutil 实现动态插件系统
python
前端付豪2 天前
LangChain链 写一篇完美推文?用SequencialChain链接不同的组件
人工智能·python·langchain
曲幽2 天前
FastAPI实战:打造本地文生图接口,ollama+diffusers让AI绘画更听话
python·fastapi·web·cors·diffusers·lcm·ollama·dreamshaper8·txt2img
老赵全栈实战2 天前
Pydantic配置管理最佳实践(一)
python
阿尔的代码屋2 天前
[大模型实战 07] 基于 LlamaIndex ReAct 框架手搓全自动博客监控 Agent
人工智能·python