HOW TO
When publishing a feature layer from ArcGIS Pro, it is possible to set a time zone and specify daylight saving time using ArcPy by modifying the config properties for publishing.
import arcpy import os import xml.dom.minidom as DOM import codecs import xml.etree.ElementTree as ET
def enable_extensions(sddraftPath, soe): doc = DOM.parse(sddraftPath) typeNames = doc.getElementsByTagName('TypeName') for typeName in typeNames: if typeName.firstChild.data == soe: extension = typeName.parentNode for extElement in extension.childNodes: if extElement.tagName == 'Enabled': extElement.firstChild.data = 'true' f = open(sddraftPath, 'w') doc.writexml(f) f.close()
def enable_configproperties(sddraftPath, soe, property_set): doc = DOM.parse(sddraftPath) typeNames = doc.getElementsByTagName('TypeName') for typeName in typeNames: if typeName.firstChild.data == soe: extension = typeName.parentNode # prp = extension.childNodes.getElementsByTagNameNS('PropertyArray') for extElement in extension.childNodes: if extElement.tagName == 'Definition': for definition in extElement.childNodes: if definition.tagName == 'ConfigurationProperties': for config_prop in definition.childNodes: if config_prop.tagName == 'PropertyArray': for prop in property_set: prop_set = doc.createElement("PropertySetProperty") attr = doc.createAttribute("xsi:type") attr.value = "typens:PropertySetProperty" prop_set.setAttributeNode(attr) prop_key = doc.createElement("Key") txt = doc.createTextNode(prop["key"]) prop_key.appendChild(txt) prop_set.appendChild(prop_key) prop_value = doc.createElement("Value") attr = doc.createAttribute("xsi:type") attr.value = "xs:string" prop_value.setAttributeNode(attr) txt = doc.createTextNode(prop["value"]) prop_value.appendChild(txt) prop_set.appendChild(prop_value) config_prop.appendChild(prop_set) f = open(sddraftPath, 'w') doc.writexml(f) f.close()
Note: There may be an error upon connecting to the portal through arcpy.SignInToPortal(). Refer to Problem: Unable to log in to ArcGIS Online using ArcPy for more information.
if __name__ == "__main__": arcpy.SignInToPortal("https://www.arcgis.com/", "username", "password") # aprx = arcpy.mp.ArcGISProject("CURRENT") aprx = arcpy.mp.ArcGISProject(r"aprx path") m = aprx.listMaps('<Map_Name>')[0] # if to share selected layers # layers = m.listLayers() # lyr = layers[0] name = "service name" in_server = "https://server.domain.com:6443/arcgis/" sddraft = m.getWebLayerSharingDraft('FEDERATED_SERVER', 'MAP_IMAGE', name) sddraft.federatedServerUrl = in_server sddraft.copyDataToServer = False sddraft.exportToSDDraft("location and name of sddraft") #The desired timezone can be in UTC or PDT property_set = [{ "key": "dateFieldsRespectsDayLightSavingTime", "value": "true" }, { "key": "dateFieldsTimezoneID", "value": "<desired_timezone>" }] # To set time zone on hosted feature service, soe = "FeatureServer" enable_configproperties(sddraftPath, soe="MapServer", property_set=property_set) # Enable extensions on the map server enable_extensions(sddraftPath, "FeatureServer") # enable_extensions(sddraftPath, "VersionManagementServer") # enable_extensions(sddraftPath, "LRServer") print("Start Staging") arcpy.StageService_server("location and name of sddraft", "location and name of sd") print("Start Uploadinb") arcpy.UploadServiceDefinition_server("location and name of sd", in_server) print("Finish publishing")
Article ID: 000024162
Get help from ArcGIS experts
Download the Esri Support App