Python 上传服务并覆盖同名服务
来源:互联网 发布:启动mysql服务 编辑:程序博客网 时间:2024/05/29 02:45
import
arcpy, os, sys
import
xml.dom.minidom as DOM
arcpy.env.overwriteOutput
=
True
# Update these variables
# The tempPath variable is a relative path which is the same directory
# this script is saved to. You can modify this value to a path on your
# system to hold the temporary files.
serviceName
=
"importantPoints"
tempPath
=
sys.path[
0
]
path2MXD
=
r
"C:\path2MXD\pts.mxd"
userName
=
" "
passWord
=
" "
# All paths are built by joining names to the tempPath
SDdraft
=
os.path.join(tempPath,
"tempdraft.sddraft"
)
newSDdraft
=
os.path.join(tempPath,
"updatedDraft.sddraft"
)
SD
=
os.path.join(tempPath, serviceName
+
".sd"
)
arcpy.SignInToPortal_server(userName, passWord,
"http://www.arcgis.com/"
)
mxd
=
arcpy.mapping.MapDocument(path2MXD)
arcpy.mapping.CreateMapSDDraft(mxd, SDdraft, serviceName,
"MY_HOSTED_SERVICES"
)
# Read the contents of the original SDDraft into an xml parser
doc
=
DOM.parse(SDdraft)
# The follow 5 code pieces modify the SDDraft from a new MapService
# with caching capabilities to a FeatureService with Query,Create,
# Update,Delete,Uploads,Editing capabilities. The first two code
# pieces handle overwriting an existing service. The last three pieces
# change Map to Feature Service, disable caching and set appropriate
# capabilities. You can customize the capabilities by removing items.
# Note you cannot disable Query from a Feature Service.
tagsType
=
doc.getElementsByTagName(
'Type'
)
for
tagType
in
tagsType:
if
tagType.parentNode.tagName
=
=
'SVCManifest'
:
if
tagType.hasChildNodes():
tagType.firstChild.data
=
"esriServiceDefinitionType_Replacement"
tagsState
=
doc.getElementsByTagName(
'State'
)
for
tagState
in
tagsState:
if
tagState.parentNode.tagName
=
=
'SVCManifest'
:
if
tagState.hasChildNodes():
tagState.firstChild.data
=
"esriSDState_Published"
# Change service type from map service to feature service
typeNames
=
doc.getElementsByTagName(
'TypeName'
)
for
typeName
in
typeNames:
if
typeName.firstChild.data
=
=
"MapServer"
:
typeName.firstChild.data
=
"FeatureServer"
#Turn off caching
configProps
=
doc.getElementsByTagName(
'ConfigurationProperties'
)[
0
]
propArray
=
configProps.firstChild
propSets
=
propArray.childNodes
for
propSet
in
propSets:
keyValues
=
propSet.childNodes
for
keyValue
in
keyValues:
if
keyValue.tagName
=
=
'Key'
:
if
keyValue.firstChild.data
=
=
"isCached"
:
keyValue.nextSibling.firstChild.data
=
"false"
#Turn on feature access capabilities
configProps
=
doc.getElementsByTagName(
'Info'
)[
0
]
propArray
=
configProps.firstChild
propSets
=
propArray.childNodes
for
propSet
in
propSets:
keyValues
=
propSet.childNodes
for
keyValue
in
keyValues:
if
keyValue.tagName
=
=
'Key'
:
if
keyValue.firstChild.data
=
=
"WebCapabilities"
:
keyValue.nextSibling.firstChild.data
=
"Query,Create,Update,Delete,Uploads,Editing"
# Write the new draft to disk
f
=
open
(newSDdraft,
'w'
)
doc.writexml( f )
f.close()
# Analyze the service
analysis
=
arcpy.mapping.AnalyzeForSD(newSDdraft)
if
analysis[
'errors'
]
=
=
{}:
# Stage the service
arcpy.StageService_server(newSDdraft, SD)
# Upload the service. The OVERRIDE_DEFINITION parameter allows you to override the
# sharing properties set in the service definition with new values. In this case,
# the feature service will be shared to everyone on ArcGIS.com by specifying the
# SHARE_ONLINE and PUBLIC parameters. Optionally you can share to specific groups
# using the last parameter, in_groups.
arcpy.UploadServiceDefinition_server(SD,
"My Hosted Services"
, serviceName,
"
", "
", "
", "
", "
OVERRIDE_DEFINITION
","
SHARE_ONLINE",
"PUBLIC"
,
"SHARE_ORGANIZATION"
, "")
print
"Uploaded and overwrote service"
else
:
# If the sddraft analysis contained errors, display them and quit.
print
analysis[
'errors'
]
原文http://blogs.esri.com/esri/arcgis/2013/04/23/updating-arcgis-com-hosted-feature-services-with-python/
0 0
- Python 上传服务并覆盖同名服务
- 同名覆盖
- xfire发布ws服务-同名函数问题
- 本地开发spark代码上传spark集群服务并运行
- python rabbitmq 服务实例--图片流上传oss
- web 服务上传文件。
- 上传文件的服务
- 后台服务上传头像
- jersey服务调用python脚本并动态传参
- 多继承同名覆盖
- 同名函数覆盖
- 遍历windows服务并启动指定服务
- C# Windows 服务安装并运行服务
- 绑定服务并调用服务中的方法
- [Python]读取xls并搜索文件夹,归类同名文件
- python时间服务应用
- python 守护进程 服务
- 搭建Python HTTP服务
- 字符检测 cctype(ctype.h)
- git基本原理详解
- Http开发模块
- bat shell删除目录下文件
- 交换两个变量的值,不使用第三个变量的四种法方
- Python 上传服务并覆盖同名服务
- How Do I Route Audio to Speaker without using AudioSessionSetProperty?
- SSM框架——使用MyBatis Generator自动创建代码
- C# 图片的转换,一个简单的实例,没有特别的修饰,涉及线程
- guid 的javascript 生成方法
- Struts bean标签
- NSIS Win7 创建任务栏快速启动快捷方式方法
- [动态规划]UVA674 - Coin Change
- struts2-core-2.3.15.1.jar!/struts-default.xml:53:178核心包加载报错