Last active
August 29, 2015 14:01
-
-
Save knu2xs/d702ba1c3e7729f950b9 to your computer and use it in GitHub Desktop.
Convert ArcGIS Server Definition draft from map service to feature service with editing permissions to be published on ArcGIS online
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# import minidom module | |
import xml.dom.minidom as DOM | |
def get_feature_service(sddraft): | |
""" | |
Converts the default type of sddraft file from a map service to a feature service for publishing to AGOL. | |
Copied and adaped from http://resources.arcgis.com/en/help/main/10.1/index.html#//00s30000006q000000 | |
:param sddraft: | |
:return: sddraft: modified to be a feature service | |
""" | |
# read the contents of the original SDDraft into an xml parser | |
doc = DOM.parse(sddraft) | |
# 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 updated sd draft to disk | |
new_sddraft = open(path.join(scratch, 'fileservice.sddraft'), 'w') | |
doc.writexml(new_sddraft) | |
new_sddraft.close() | |
# return new_sddraft | |
return new_sddraft |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment