Arcpy发布追踪网络服务
分享
前提:
首先有加载追踪网络图层的GeoScene Pro工程文件。
注册数据存储:向server或者portal注册追踪网络数据所在sde
然后通过发布关联要素的地图影像图层的形式,修改sddraft文件启用要素图层,启用版本管理的方式发布追踪网络服务。
首先有加载追踪网络图层的GeoScene Pro工程文件。
注册数据存储:向server或者portal注册追踪网络数据所在sde
然后通过发布关联要素的地图影像图层的形式,修改sddraft文件启用要素图层,启用版本管理的方式发布追踪网络服务。
import arcpy
import os
import xml.dom.minidom as DOM
def configure_featureserver_capabilities(sddraftPath, capabilities):
"""Function to configure FeatureServer properties"""
# Read the .sddraft file
doc = DOM.parse(sddraftPath)
# Find all elements named TypeName
# This is where the additional layers and capabilities are defined
typeNames = doc.getElementsByTagName('TypeName')
for typeName in typeNames:
# Get the TypeName to enable
if typeName.firstChild.data == "FeatureServer":
extension = typeName.parentNode
for extElement in extension.childNodes:
if extElement.tagName == 'Info':
for propSet in extElement.childNodes:
for prop in propSet.childNodes:
for prop1 in prop.childNodes:
if prop1.tagName == "Key":
if prop1.firstChild.data == 'WebCapabilities':
if prop1.nextSibling.hasChildNodes():
prop1.nextSibling.firstChild.data = capabilities
else:
txt = doc.createTextNode(capabilities)
prop1.nextSibling.appendChild(txt)
# Write to the .sddraft file
f = open(sddraftPath, 'w')
doc.writexml(f)
f.close()
def configure_mapserver_capabilities(sddraftPath, capabilities):
"""Function to configure MapServer properties"""
# Read the .sddraft file
doc = DOM.parse(sddraftPath)
# Find all elements named TypeName
# This is where the additional layers and capabilities are defined
typeNames = doc.getElementsByTagName('TypeName')
for typeName in typeNames:
# Get the TypeName to enable
if typeName.firstChild.data == "MapServer":
extension = typeName.parentNode
for extElement in extension.childNodes:
if extElement.tagName == 'Definition':
for propArray in extElement.childNodes:
if propArray.tagName == 'Info':
for propSet in propArray.childNodes:
for prop in propSet.childNodes:
for prop1 in prop.childNodes:
if prop1.tagName == "Key":
if prop1.firstChild.data == 'WebCapabilities':
if prop1.nextSibling.hasChildNodes():
prop1.nextSibling.firstChild.data = capabilities
else:
txt = doc.createTextNode(capabilities)
prop1.nextSibling.appendChild(txt)
# Write to the .sddraft file
f = open(sddraftPath, 'w')
doc.writexml(f)
f.close()
if __name__ == "__main__":
# Sign in to portal
arcpy.SignInToPortal("https://geo41.geoscene.cn/geoscene", "username", "password")
# Set output file names
outdir = r"E:\ArcGISproj\tracenetwork\Output"
service_name = "MapImageSharingDraftExample1"
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)
# Reference map to publish
aprx = arcpy.mp.ArcGISProject(r"E:\ArcGISproj\tracenetwork\tracenetwork.aprx")
m = aprx.listMaps('world')[0]
# Create MapImageSharingDraft, set copyDataToServer property to False to reference registered data, and set CIM symbols
server_type = "FEDERATED_SERVER"
federated_server_url = "https://geo41.geoscene.cn/server"
sddraft = m.getWebLayerSharingDraft(server_type, "MAP_IMAGE", service_name)
sddraft.federatedServerUrl = federated_server_url
sddraft.copyDataToServer = False
sddraft.useCIMSymbols = True
# Create Service Definition Draft file
sddraft.exportToSDDraft(sddraft_output_filename)
"""Modify the .sddraft file to include a feature layer and set map image layer and feature layer properties"""
# Modify the .sddraft file to change map image layer properties
# Defaults are Map,Query,Data
# Comment out the line below if you do not want to modify map image layer properties
configure_mapserver_capabilities(sddraft_output_filename, "Map,Data")
# Modify the .sddraft file to include a feature layer
# Read the file
doc = DOM.parse(sddraft_output_filename)
# Find all elements named TypeName
# This is where the extensions are defined
typeNames = doc.getElementsByTagName('TypeName')
for typeName in typeNames:
# Get the TypeName to enable
if typeName.firstChild.data == "FeatureServer":
extension = typeName.parentNode
for extElement in extension.childNodes:
# Include a feature layer
if extElement.tagName == 'Enabled':
extElement.firstChild.data = 'true'
if typeName.firstChild.data == "VersionManagementServer":
extension = typeName.parentNode
for extElement in extension.childNodes:
# Include a feature layer
if extElement.tagName == 'Enabled':
extElement.firstChild.data = 'true'
# Write to new .sddraft file
sddraft_mod_xml = service_name + '_mod_xml' + '.sddraft'
sddraft_mod_xml_file = os.path.join(outdir, sddraft_mod_xml)
f = open(sddraft_mod_xml_file, 'w')
doc.writexml(f)
f.close()
# Modify the .sddraft file to change feature layer properties
# Defaults are Query,Create,Update,Delete,Uploads,Editing
# Comment out the line below if you don't want to modify feature layer properties
configure_featureserver_capabilities(sddraft_mod_xml_file, "Create,Sync,Query")
# Stage Service
print("Start Staging")
arcpy.server.StageService(sddraft_mod_xml_file, sd_output_filename)
# Share to portal
print("Start Uploading")
arcpy.server.UploadServiceDefinition(sd_output_filename, federated_server_url)
print("Finish Publishing")
0 个评论
相关问题
- 在windows server2008 R2 64位中安装了portal 10.5 设置好托管arcgis server站点,并用data store为托管数据库,发布数据出错
- 如何利用ArcPY操作图层的“symbol”?
- 网站用arcgis API for JavaScript写好,发布网站之后,别人访问无法加载地图?
- ArcEngine10.1 如何发布地图服务
- 访问arcgisserver发布的服务,提示要输入用户名密码,验证登录
- 地图服务发布成功,但无法启动服务
- 我已经设置背景了,发布后背景却为白色?
- SOE如何发布Arcgis的python脚本
- 在arcgispro里面创建并共享场景图层包,在online里面发布查看报一下错误,求原因
- portal for arcgis 1031使用管理员角色创建的3d场景怎么没有发布功能?
- 用js调用portal中用户所发布的webmap并在该地图上添加点如何用代码实现,我的总是报错。。。。