MapImageSharingDraft

Resumen

The MapImageSharingDraft class allows you to configure map image layer properties and create a service definition draft (.sddraft) file, which can then be shared to ArcGIS Enterprise.

Debate

To create the MapImageSharingDraft class object, use the map class function getWebLayerSharingDraft and set the service_type parameter to MAP_IMAGE. The MapImageSharingDraft class object can then be configured by setting service level properties. Use the federatedServerUrl property to specify which federated server the web layer is published to. After the MapImageSharingDraft class object has been configured, it can then be saved to a service definition draft (.sddraft) file using the exportToSDDraft function. It can then be staged and shared to ArcGIS Enterprise using the Stage Service and Upload Service Definition tools. For more information, see Introduction to the sharing module.

Propiedades

PropiedadExplicaciónTipo de datos
copyDataToServer
(Lectura y escritura)

A Boolean that indicates whether the data in your map is copied to the server or not. A value of True will copy all of the data in your map - including data that is registered with your federated server. A value of False will only copy data that is not registered with your federated server - data registered with your federated server will be referenced by the service.

Boolean
credits
(Lectura y escritura)

A string that represents the credits.

String
description
(Lectura y escritura)

A string that represents the description.

String
federatedServerUrl
(Lectura y escritura)

A string representing the URL to the ArcGIS Enterprise portal federated server.

Sugerencia:

The federated server URL can also be used in the in_server parameter in the Upload Service Definition tool. The code samples below demonstrate this.

String
offline
(Lectura y escritura)

A Boolean that determines whether to use a portal connection or not. If offline is set to False, you must be signed in to a portal as well as provide an ArcGIS Enterprise portal federated server URL to the federatedServerUrl property in order to create a service definition draft (.sddraft) file using the exportToSDDraft function. If offline is set to True, a service definition draft file can be created without being signed in to a portal and without populating the federatedServerUrl property.

Boolean
overwriteExistingService
(Lectura y escritura)

A Boolean that determines whether to overwrite an existing web layer or not.

Boolean
portalFolder
(Lectura y escritura)

A string that represents the name of a portal folder to which you want to publish the web layer. The default folder is your root folder in My Content.

String
serverFolder
(Lectura y escritura)

A string that represents the name of a server folder to which you want to publish the service. The default folder is the root folder of the federated server.

String
serverType
(Sólo lectura)

Returns a string representing the server type as specified when the sharing draft was created from the getWebLayerSharingDraft function from the map class. The only possible value returned from serverType for a MapImageSharingDraft is FEDERATED_SERVER. A serverType of FEDERATED_SERVER indicates support for sharing to an ArcGIS Enterprise portal federated server.

String
serviceName
(Lectura y escritura)

A string that represents the name of the web layer. This is the name people will see and use to identify the service. The name can only contain alphanumeric characters and underscores. No spaces or special characters are allowed. The name cannot be more than 120 characters in length.

String
summary
(Lectura y escritura)

A string that represents the summary.

String
tags
(Lectura y escritura)

A string that represents the tags. Multiple tags can be added or separated by a comma or semicolon.

String
useLimitations
(Lectura y escritura)

A string that represents the use limitations.

String

Descripción general del método

MétodoExplicación
exportToSDDraft (out_sddraft)

Converts a MapImageSharingDraft to a service definition draft (.sddraft) file.

Métodos

exportToSDDraft (out_sddraft)
ParámetroExplicaciónTipo de datos
out_sddraft

A string that represents the path and file name for the output service definition draft (.sddraft) file.

String

Once the MapImageSharingDraft has been configured, it can then be saved as a service definition draft (.sddraft) file. It can then be staged and shared to the ArcGIS Enterprise portal federated server using the Stage Service and Upload Service Definition tools.

Sugerencia:

If the offline property is set to False, you must be signed in to a portal as well as provide an ArcGIS Enterprise portal federated server URL to the federatedServerUrl property in order to create a service definition draft (.sddraft) file using the exportToSDDraft function. However, if offline is set to True, a service definition draft file can be created without being signed in to a portal and without populating the federatedServerUrl property.

Muestra de código

MapImageSharingDraft example

The following script publishes a map as a map image layer to an ArcGIS Enterprise portal federated server. Portal information is obtained from the Portals page in ArcGIS Pro.

import arcpy
import os

# Set output file names
outdir = r"C:\Project\Output"
service = "MapImageSharingDraftExample"
sddraft_filename = service + ".sddraft"
sddraft_output_filename = os.path.join(outdir, sddraft_filename)

# Reference map to publish
aprx = arcpy.mp.ArcGISProject(r"C:\Project\World.aprx")
m = aprx.listMaps("World")[0]

# Create MapImageSharingDraft and set service properties
sharing_draft = m.getWebLayerSharingDraft("FEDERATED_SERVER", "MAP_IMAGE", service)
sharing_draft.federatedServerUrl = "https://MyFederatedServer.esri.com/server"
sharing_draft.summary = "My Summary"
sharing_draft.tags = "My Tags"
sharing_draft.description = "My Description"
sharing_draft.credits = "My Credits"
sharing_draft.useLimitations = "My Use Limitations"

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

# Stage Service
sd_filename = service + ".sd"
sd_output_filename = os.path.join(outdir, sd_filename)
arcpy.StageService_server(sddraft_output_filename, sd_output_filename)

# Share to portal
print("Uploading Service Definition...")
arcpy.UploadServiceDefinition_server(sd_output_filename, "https://MyFederatedServer.esri.com/server")

print("Successfully Uploaded service.")
Modify SDDraft example

The following script creates a map image layer service definition draft (.sddraft) file for a map. It then enables feature access on the map image layer by modifying the service definition draft file using the xml.dom.minidom standard Python library. The modified service definition file is then published to an ArcGIS Enterprise portal federated server. Portal information is obtained from the Portals page in ArcGIS Pro.

import arcpy
import os
import xml.dom.minidom as DOM

# Set output file names.
outdir = r"C:\Project\Output"
service = "MapImage_ModifyXML_EnableFeatureAccess"
sddraft_filename = service + '.sddraft'
sddraft_output_filename = os.path.join(outdir, sddraft_filename)

# Reference map to publish.
aprx = arcpy.mp.ArcGISProject(r"C:\Project\World.aprx")
m = aprx.listMaps('World')[0]

# Create MapImageSharingDraft and set service properties.
sddraft = m.getWebLayerSharingDraft('FEDERATED_SERVER', 'MAP_IMAGE', service)
sddraft.federatedServerUrl = "https://MyFederatedServer.esri.com/server"

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

# Read the sddraft xml.
doc = DOM.parse(sddraft_output_filename)

# Find all elements named TypeName. This is where the server object extension
# (SOE) names are defined.
typeNames = doc.getElementsByTagName('TypeName')
for typeName in typeNames:
    # Get the TypeName we want to enable.
    if typeName.firstChild.data == "FeatureServer":
        extension = typeName.parentNode
        for extElement in extension.childNodes:
            # Enable Feature Access.
            if extElement.tagName == 'Enabled':
                extElement.firstChild.data = 'true'
				
# Output to a new sddraft.  
sddraft_mod_xml = service + '_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() 

# Stage Service.
sd_filename = service + '.sd'
sd_output_filename = os.path.join(outdir, sd_filename)
arcpy.StageService_server(sddraft_mod_xml_file, sd_output_filename)

# Share to portal.
print("Uploading Service Definition...")
arcpy.UploadServiceDefinition_server(sd_output_filename, "https://MyFederatedServer.esri.com/server")

print("Successfully Uploaded service.")