サマリー
The MapImageSharingDraft class allows you to create a service definition draft file (.sddraft) for a map image layer that copies all data or references registered data to ArcGIS Enterprise.
説明
To create the MapImageSharingDraft object, use the Map object's getWebLayerSharingDraft method and set the service_type parameter to MAP_IMAGE. The MapImageSharingDraft object can then be configured by setting service level properties and metadata properties. Use the federatedServerUrl property to specify the federated server to which the web layer is published.
You can also set web layer properties by modifying the .sddraft file. If no value is specified for a property, the default is set. Therefore, you must set the desired property values even if you are overwriting a web layer that has existing configured properties.
注意:
メタデータのプロパティ (credits、description、summary、tags、useLimitations) が設定されていないか空の文字列で構成されている場合、Web レイヤー アイテムは、共有されるものに応じてマップまたはレイヤーからメタデータを供給します。 Web レイヤーがメタデータを供給する方法については、「Web レイヤーのメタデータ」をご参照ください。
After the MapImageSharingDraft object has been configured, it can be saved to a service definition draft file (.sddraft) using the exportToSDDraft method. 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 arcpy.sharing.
Code samples are available for the following:
- Publish a map image layer to a portal folder
- Overwrite a map image layer
- Publish a map image layer with an associated feature layer
- Publish a cached map image layer
- Publish a map image layer that draws from existing cache
- Analyze and register a data store
- Set a time zone and configure pooling
- Publish a layer and table
- Create and publish an offline service definition
- Analyze to confirm map is set to allow assignment of unique numeric IDs
プロパティ
プロパティ | 説明 | データ タイプ |
cache.cacheOnDemand (読み書き) | Specifies whether tiles that are not cached will be created on demand when a client application requests them. The default value is False. | Boolean |
cache.configuration (読み書き) | The path and file name of a predefined tiling scheme .xml file generated by the Generate Map Server Cache Tiling Scheme tool. | String |
cache.exportTiles (読み書き) | Specifies whether clients will be allowed to download map tiles for offline use. The default value is False. | Boolean |
cache.exportTilesCount (読み書き) | The maximum number of tiles that can be downloaded in a single request. This property is only honored if the cache.exportTiles property is set to True. The default value is 100000. | Integer |
cache.useExistingCache (読み書き) | Specifies whether the data will be drawn from an existing cache. This property is only honored if the enableCache property is set to True. The default value is False. | Boolean |
checkUniqueIDAssignment (読み書き) | Specifies whether the map will be analyzed to confirm that the Allow assignment of unique numeric IDs for sharing web layers option in Map Properties is enabled. For more information, see Assign layer IDs. | Boolean |
copyDataToServer (読み書き) | Specifies whether the data in the map will be copied to the server. A value of True will copy all of the data in the 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. The default value is False. | Boolean |
credits (読み書き) | The credits of the web layer. | String |
description (読み書き) | The description of the web layer. | String |
enableCache (読み書き) | Specifies whether the web layer will draw dynamically or from a cache. The default value is False. | Boolean |
enableDynamicWorkspaces (読み書き) | Specifies whether users will be allowed to change the appearance or drawing behavior of the web layer. The default value is True. | Boolean |
extension.feature.allowTrueCurvesUpdates (読み書き) | Specifies whether web clients will be allowed to update the true curve geometry of a feature with densified geometry. This property is only honored when editing is enabled. The default value is True. | Boolean |
extension.feature.allowUpdateWithoutMValues (読み書き) | Specifies whether geometry updates to m-enabled features will be allowed without specifying an m-value. The default value is False. | Boolean |
extension.feature.featureCapabilities (読み書き) | The enabled capabilities, separated by commas. The following capabilities are supported:
| String |
extension.feature.isEnabled (読み書き) | Specifies whether an associated feature layer will be included. The default value is False. | Boolean |
extension.feature.onlyAllowTrueCurveUpdatesByTrueCurveClients (読み書き) | Specifies whether only clients that support true curves, such as ArcGIS Pro, will be allowed to update true curve geometries. This property is only honored when editing is enabled. The default value is True. | Boolean |
extension.feature.zDefault.enable (読み書き) | Specifies whether editors will be allowed to add or update features through clients that don't allow a z-value to be given. The default value is False. | Boolean |
extension.feature.zDefault.value (読み書き) | The default z-value that will be used when inserting or updating features. This property is only honored if the zDefault.enable property is set to True. The default value is 0. | Double |
extension.kml.isEnabled (読み書き) | Specifies whether the KML capability will be enabled. The default value is False. | Boolean |
extension.linearReferencing.isEnabled (読み書き) | Specifies whether the linear referencing capability will be enabled. The default value is False. | Boolean |
extension.networkAnalysis.isEnabled (読み書き) | Specifies whether a Network Analysis service will be enabled. The default value is False. | Boolean |
extension.ogcFeature.isEnabled (読み書き) | Specifies whether an OGC Features service will be enabled. The default value is False. | Boolean |
extension.topographicProduction.isEnabled (読み書き) | Specifies whether the topographic production capability will be enabled. The default value is False. | Boolean |
extension.validation.isEnabled (読み書き) | Specifies whether the validation capability will be enabled. The default value is False. | Boolean |
extension.versionManagement.isEnabled (読み書き) | Specifies whether the version management capability will be enabled. The default value is False. | Boolean |
extension.wcs.isEnabled (読み書き) | Specifies whether the WCS capability will be enabled. The default value is False. | Boolean |
extension.wfs.isEnabled (読み書き) | Specifies whether a WFS service will be enabled. The default value is False. | Boolean |
extension.wms.isEnabled (読み書き) | Specifies whether a WMS service will be enabled. The default value is False. | Boolean |
federatedServerUrl (読み書き) | The URL to the ArcGIS Enterprise portal federated server. ヒント:The federated server URL can also be used in the in_server parameter in the Upload Service Definition tool. | String |
mapOperations (読み書き) | The enabled operations, separated by commas. The following operations are supported:
| String |
maxRecordCount (読み書き) | The maximum number of records that will be returned by the server during querying. The default value is 2000. | Integer |
offline (読み書き) | Specifies whether a portal connection is required. If set to False, you must be signed in to a portal as well as provide an ArcGIS Enterprise portal federated server URL for the federatedServerUrl property to create a service definition draft file (.sddraft) using the exportToSDDraft function. If 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 |
offlineTarget (読み書き) | The target server version to which the service definition will be published. Specifying a version ensures that the service definition contains content compatible with your server. This property is only honored if the offline property is set to True.
| String |
overwriteExistingService (読み書き) | Specifies whether an existing web layer will be overwritten. | Boolean |
pooling.maxInstances (読み書き) | The maximum number of instances per machine. This property is only honored if the pooling.type property is set to DEDICATED. | Integer |
pooling.minInstances (読み書き) | The minimum number of instances per machine. This property is only honored if the pooling.type property is set to DEDICATED. | Integer |
pooling.type (読み書き) | The type of instance pooling that will be used.
| String |
portalFolder (読み書き) | The name of the existing portal folder where the web layer will be published. The default folder is your root folder in My Content. | String |
serverFolder (読み書き) | The name of the server folder where the service will be published. The default folder is the root folder of the federated server. | String |
serverType (読み取り専用) | 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 value of FEDERATED_SERVER indicates support for sharing to an ArcGIS Enterprise portal federated server. | String |
serviceName (読み書き) | 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. | String |
sharing.groups (読み書き) | The group names, separated by commas. | String |
sharing.sharingLevel (読み書き) | The sharing level of the web layer.
| String |
summary (読み書き) | The summary of the web layer. | String |
tags (読み書き) | The tags of the web layer. Multiple tags can be added or separated by a comma. | String |
useLimitations (読み書き) | The use limitations of the web layer. | String |
timezone.DaylightSavingTime (読み書き) | Specifies whether the time zone accounts for daylight saving time. The default value is False. | Boolean |
timezone.ID (読み書き) | The time zone in which date values are stored. The string value must match one of the official time zone IDs recognized by the Windows operating system. For a list of time zones, see Time zones in the Microsoft documentation. | String |
timezone.preferredTimezoneID (読み書き) | The time zone for ArcGIS Pro to use when displaying queries from the web feature layer. The string value must match one of the official time zone IDs recognized by the Windows operating system. For a list of time zones, see Time zones in the Microsoft documentation. | String |
timezone.preferredTimezoneIDDaylightSavingTime (読み書き) | Specifies whether the preferred time zone accounts for daylight saving time. The default value is False. | Boolean |
useCIMSymbols (読み書き) | Specifies whether Esri Cartographic Information Model (CIM) symbols, also known as ArcGIS Pro symbols, will be used. Set to False to use symbols that can be rendered by all clients. Set to True to use CIM symbols supported by newer clients such as ArcGIS API for JavaScript 4.x. This property is only honored if an associated feature layer is included, and the service definition is published to ArcGIS Enterprise 11.3 or later. | Boolean |
方法の概要
方法 | 説明 |
exportToSDDraft (out_sddraft) | Converts a MapImageSharingDraft to a service definition draft (.sddraft) file. |
方法
exportToSDDraft (out_sddraft)
パラメーター | 説明 | データ タイプ |
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 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.
コードのサンプル
The following script creates a map image layer service definition draft file (.sddraft) for a map and sets metadata properties. The map image layer is published to a folder in ArcGIS Enterprise and shared with everyone (public). Portal information is obtained from the SignInToPortal function.
import arcpy
import os
# Sign in to portal
arcpy.SignInToPortal("https://portal.domain.com/webadaptor",
"MyUserName", "MyPassword")
# Set output file names
outdir = r"C:\Project\Output"
service_name = "MapImageSharingDraftExample"
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"C:\Project\World.aprx")
m = aprx.listMaps('World')[0]
# Create MapImageSharingDraft and set metadata, portal folder, and server folder properties
server_type = "FEDERATED_SERVER"
federated_server_url = "https://MyFederatedServer.domain.com/serverWebadaptor"
sddraft = m.getWebLayerSharingDraft(server_type, "MAP_IMAGE", service_name)
sddraft.federatedServerUrl = federated_server_url
sddraft.credits = "These are credits"
sddraft.description = "This is description"
sddraft.summary = "This is summary"
sddraft.tags = "tag1, tag2"
sddraft.useLimitations = "These are use limitations"
sddraft.portalFolder = "my folder name"
sddraft.serverFolder = "MyServerFolder"
sddraft.sharing.sharingLevel = "EVERYONE"
sddraft.sharing.groups = "" # Group names = "group1,group2"
# Create Service Definition Draft file
sddraft.exportToSDDraft(sddraft_output_filename)
# Stage Service
print("Start Staging")
arcpy.server.StageService(sddraft_output_filename, sd_output_filename)
# Share to portal
print("Start Uploading")
arcpy.server.UploadServiceDefinition(sd_output_filename, federated_server_url)
print("Finish Publishing")
The following script overwrites a map image layer. If the service name already exists, the service will be overwritten; otherwise, a new service will be created. If you want your web layer to have specific properties, you must set property values even if the web layer being overwritten already has properties configured. Otherwise, the existing properties will be overwritten with default settings.
import arcpy
import os
# Sign in to portal
arcpy.SignInToPortal("https://portal.domain.com/webadaptor",
"MyUserName", "MyPassword")
# Set output file names
outdir = r"C:\Project\Output"
service_name = "MapImageSharingDraftExample"
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"C:\Project\World.aprx")
m = aprx.listMaps('World')[0]
# Create MapImageSharingDraft and set overwrite property
server_type = "FEDERATED_SERVER"
federated_server_url = "https://MyFederatedServer.domain.com/serverWebadaptor"
sddraft = m.getWebLayerSharingDraft(server_type, "MAP_IMAGE", service_name)
sddraft.federatedServerUrl = federated_server_url
sddraft.overwriteExistingService = True
# Create Service Definition Draft file
sddraft.exportToSDDraft(sddraft_output_filename)
# Stage Service
print("Start Staging")
arcpy.server.StageService(sddraft_output_filename, sd_output_filename)
# Share to portal
print("Start Uploading")
arcpy.server.UploadServiceDefinition(sd_output_filename, federated_server_url)
print("Finish Publishing")
The following script creates a map image layer service definition draft (.sddraft) file. It then includes a feature layer and sets feature layer and map image layer properties. The .sddraft file is then staged and published to an ArcGIS Enterprise portal federated server. The data store must be registered on the server before the data can be referenced.
import arcpy
import os
# Sign in to portal
arcpy.SignInToPortal("https://portal.domain.com/webadaptor",
"MyUserName", "MyPassword")
# Set output file names
outdir = r"C:\Project\Output"
service_name = "MapImageSharingDraftExample"
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"C:\Project\World.aprx")
m = aprx.listMaps('World')[0]
# Create MapImageSharingDraft, set copyDataToServer property to False to reference registered data, set CIM symbols, and map operations. Include feature layer and enable capabilities.
server_type = "FEDERATED_SERVER"
federated_server_url = "https://MyFederatedServer.esri.com/serverWebadaptor"
sddraft = m.getWebLayerSharingDraft(server_type, "MAP_IMAGE", service_name)
sddraft.federatedServerUrl = federated_server_url
sddraft.copyDataToServer = False
sddraft.useCIMSymbols = True
sddraft.mapOperations = "Map,Data"
sddraft.extension.feature.isEnabled = True
sddraft.extension.feature.featureCapabilities = "Create,Sync,Query"
# Create Service Definition Draft file
sddraft.exportToSDDraft(sddraft_output_filename)
# Stage Service
print("Start Staging")
arcpy.server.StageService(sddraft_output_filename, sd_output_filename)
# Share to portal
print("Start Uploading")
arcpy.server.UploadServiceDefinition(sd_output_filename, federated_server_url)
print("Finish Publishing")
The following script publishes a cached map image layer by calling the Manage Map Server Cache Tiles tool to create map service cache tiles. The .sddraft file is analyzed for errors and warnings during staging.
import arcpy
import os
# Sign in to portal
arcpy.SignInToPortal("https://portal.domain.com/webadaptor",
"MyUserName", "MyPassword")
# Set output file names
outdir = r"C:\Project\Output"
service_name = "MapImageSharingDraftExample"
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"C:\Project\World.aprx")
m = aprx.listMaps('World')[0]
# Create MapImageSharingDraft
server_type = "FEDERATED_SERVER"
federated_server_url = "https://MyFederatedServer.domain.com/serverWebadaptor"
sddraft = m.getWebLayerSharingDraft(server_type, "MAP_IMAGE", service_name)
sddraft.federatedServerUrl = federated_server_url
sddraft.enableCache = True
sddraft.cache.configuration = "C:\Program Files\ArcGIS\Pro\Resources\TilingSchemes\WGS84_Geographic_Coordinate_System_V2.xml"
# Create Service Definition Draft file
sddraft.exportToSDDraft(sddraft_output_filename)
try:
# Stage Service
print("Start Staging")
arcpy.server.StageService(sddraft_output_filename, sd_output_filename)
warnings = arcpy.GetMessages(1)
print(warnings)
# Share to portal
print("Start Uploading")
arcpy.server.UploadServiceDefinition(sd_output_filename, federated_server_url)
print("Finish Publishing")
# Manage Map Server Cache Tiles
# For cache, use multiple scales separated by semicolon (;)
# For example, "591657527.591555;295828763.795855"
arcpy.server.ManageMapServerCacheTiles(federated_server_url + "/" + "rest/services" + "/" + service_name + "/" + "MapServer", "295828763.795855", "RECREATE_ALL_TILES")
except Exception as stage_exception:
print("Analyzer errors encountered - {}".format(str(stage_exception)))
except arcpy.ExecuteError:
print(arcpy.GetMessages(2))
The following script creates a map image layer service definition draft (.sddraft) file. It then uses an existing cache to draw the service. The .sddraft file is then staged and published to an ArcGIS Enterprise portal federated server.
import arcpy
import os
# Sign in to portal
arcpy.SignInToPortal("https://portal.domain.com/webadaptor",
"MyUserName", "MyPassword")
# Set output file names
outdir = r"C:\Project\Output"
service_name = "MapImageSharingDraftExample"
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"C:\Project\World.aprx")
m = aprx.listMaps('World')[0]
# Create MapImageSharingDraft
server_type = "FEDERATED_SERVER"
federated_server_url = "https://MyFederatedServer.domain.com/serverWebadaptor"
sddraft = m.getWebLayerSharingDraft(server_type, "MAP_IMAGE", service_name)
sddraft.federatedServerUrl = federated_server_url
sddraft.enableCache = True
sddraft.cache.useExistingCache = True
# Create Service Definition Draft file
sddraft.exportToSDDraft(sddraft_output_filename)
# Stage Service
print("Start Staging")
arcpy.server.StageService(sddraft_output_filename, sd_output_filename)
# Share to portal
print("Start Uploading")
arcpy.server.UploadServiceDefinition(sd_output_filename, federated_server_url)
print("Finish Publishing")
The following script creates a service definition draft (.sddraft) file for a map image layer. The .sddraft file is analyzed during staging. If analyzer 24011 is returned warning that the data source is not registered with the server, the data store is registered using the arcgis.gis module in ArcGIS API for Python.
import arcpy
import os
# Add a data store item on the portal and register it with a federated server
def register_datastore_item(portal_url, username, password, sde_conn_file, data_store_name, federated_server_url):
from arcgis.gis import GIS
tags = "tag1, tag2"
description = "Data Store Item created from ArcGIS API for Python"
federated_server_url = federated_server_url.rstrip('/')
federated_server_adminurl = federated_server_url + "/admin"
# Connect to your portal using ArcGIS API for Python
gis = GIS(url=portal_url, username=username, password=password)
# Get federated server ID
server_list = gis.servers["servers"]
fedserver_dict = [srvr for srvr in server_list if srvr["url"] == federated_server_url][0]
fedserver_id = fedserver_dict["id"]
print("Server id: " + fedserver_id)
# Get federated server's DatastoreManager object
fedserver = [srvr for srvr in gis.admin.servers.list() if srvr.url == federated_server_adminurl][0]
fedserver_dsmgr = fedserver.datastores
# Create a connection string from .sde file connection
conn_file = sde_conn_file
conn_string = fedserver_dsmgr.generate_connection_string(conn_file)
print("Connection string generated")
# Create a dictionary for data store configuration
ds_config = {"type": "egdb",
"path": "/enterpriseDatabases/" + data_store_name,
"info": {"isManaged": "false",
"dataStoreConnectionType": "shared",
"connectionString": conn_string}
}
# Create a dictionary for the item properties
item_properties = {"title": data_store_name,
"type": "Data Store",
"tags": tags,
"snippet": description}
# Add the data store item to the portal
ds_item = gis.content.add(item_properties=item_properties,
text=ds_config)
print("Data store item added")
# Get portal data store
portal_ds = gis.datastore
# Validate the data store item can be connected to before registering
validation_state = portal_ds.validate(server_id=fedserver_id,
item=ds_item)
print("Data store item validated")
# Register the database with the federated server
portal_ds.register(item=ds_item,
server_id=fedserver_id,
bind=False)
print("Data store item registered to server")
return True
if __name__ == "__main__":
arcpy.env.overwriteOutput = True
portal_url = "https://portal.domain.com/webadaptor"
username = "MyUserName"
password = "MyPassword"
# Sign in to portal
arcpy.SignInToPortal(portal_url, username, password)
# Set output file names
outdir = r"C:\Project\Output"
service_name = "registerdatastore_example"
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)
sde_conn_file = r"C:\Project\db_conn.sde"
data_store_name = "PortalDSItem"
# Reference map to publish
aprx = arcpy.mp.ArcGISProject(r"C:\Project\World.aprx")
m = aprx.listMaps('Map')[0]
# Create MapImageSharingDraft and set copyDataToServer property to False to reference registered data
server_type = "FEDERATED_SERVER"
federated_server_url = "https://MyFederatedServer.domain.com/serverWebadaptor"
sddraft = m.getWebLayerSharingDraft(server_type, "MAP_IMAGE", service_name)
sddraft.federatedServerUrl = federated_server_url
sddraft.copyDataToServer = False
# Create Service Definition Draft file
sddraft.exportToSDDraft(sddraft_output_filename)
# Stage the service and analyze the .sddraft file for registered data store
# Continue publishing only if data store is registered
print("Start Staging")
stage_service = True
while stage_service:
arcpy.server.StageService(sddraft_output_filename, sd_output_filename)
# Get analyzer warnings to check if data store is registered
warnings = arcpy.GetMessages(1)
print(warnings)
# If data store is not registered
if "24011" in warnings:
# Register data store
register_res = register_datastore_item(portal_url, username, password, sde_conn_file, data_store_name,
federated_server_url)
if not register_res:
print("Unable to register the data store, skipping upload")
exit()
# Stage the service again
stage_service = True
else:
stage_service = False
# Share to portal
print("Start Uploading")
arcpy.server.UploadServiceDefinition(sd_output_filename, federated_server_url)
print("Finish Publishing")
The following script creates a map image layer service definition draft (.sddraft) file. It then sets a time zone for layers with date fields and configures service instance settings. The .sddraft file is then staged and published to an ArcGIS Enterprise portal federated server. The data store must be registered on the server before the data can be referenced.
import arcpy
import os
# Sign in to portal
arcpy.SignInToPortal("https://portal.domain.com/webadaptor",
"MyUserName", "MyPassword")
# Set output file names
outdir = r"C:\Project\Output"
service_name = "MapImageSharingDraftExample"
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"C:\Project\World.aprx")
m = aprx.listMaps('World')[0]
# Create MapImageSharingDraft and set time zone, enable version management, and configure pooling options
server_type = "FEDERATED_SERVER"
federated_server_url = "https://MyFederatedServer.esri.com/serverWebadaptor"
sddraft = m.getWebLayerSharingDraft(server_type, "MAP_IMAGE", service_name)
sddraft.federatedServerUrl = federated_server_url
sddraft.copyDataToServer = False
sddraft.pooling.type = "DEDICATED"
sddraft.pooling.minInstances = 0
sddraft.pooling.maxInstances = 2
sddraft.timezone.ID = "Pacific Standard Time"
sddraft.timezone.DaylightSavingTime = True
sddraft.extension.versionManagement.isEnabled = True
# Create Service Definition Draft file
sddraft.exportToSDDraft(sddraft_output_filename)
# Stage Service
print("Start Staging")
arcpy.server.StageService(sddraft_output_filename, sd_output_filename)
# Share to portal
print("Start Uploading")
arcpy.server.UploadServiceDefinition(sd_output_filename, federated_server_url)
print("Finish Publishing")
The following script publishes a layer and table as a map image layer to an ArcGIS Enterprise portal.
import arcpy
import os
# Sign in to portal
arcpy.SignInToPortal("https://portal.domain.com/webadaptor",
"MyUserName", "MyPassword")
# Set output file names
outdir = r"C:\Project\Output"
service_name = "MapImageSharingDraftExample"
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 layers to publish
aprx = arcpy.mp.ArcGISProject(r"C:\Project\World.aprx")
m = aprx.listMaps('World')[0]
selected_layer = m.listLayers('States')[0]
selected_table = m.listTables('Cities')[0]
# Create MapImageSharingDraft
server_type = "FEDERATED_SERVER"
federated_server_url = "https://MyFederatedServer.domain.com/serverWebadaptor"
sddraft = m.getWebLayerSharingDraft(server_type, "MAP_IMAGE", service_name, [selected_layer, selected_table])
sddraft.federatedServerUrl = federated_server_url
# Create Service Definition Draft file
sddraft.exportToSDDraft(sddraft_output_filename)
# Stage Service
print("Start Staging")
arcpy.server.StageService(sddraft_output_filename, sd_output_filename)
# Share to portal
print("Start Uploading")
arcpy.UploadServiceDefinition_server(sd_output_filename, federated_server_url)
print("Finish Publishing")
The following script creates an offline service definition for the target server version and publishes it as a map image layer.
import arcpy
import os
# Set output file names
outdir = r"C:\Project\Output"
service_name = "MapImageSharingDraftExample"
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"C:\Project\World.aprx")
m = aprx.listMaps('World')[0]
# Create MapImageSharingDraft and set offline and offlineTarget properties
server_type = "FEDERATED_SERVER"
sddraft = m.getWebLayerSharingDraft(server_type, "MAP_IMAGE", service_name)
sddraft.offline = True
# Set offlineTarget property to "ENTERPRISE_11" for ArcGIS Enterprise 11.0 or later
# The default is ArcGIS Enterprise 10.9.1 or earlier
sddraft.offlineTarget = "ENTERPRISE_10x"
# Create Service Definition Draft file
sddraft.exportToSDDraft(sddraft_output_filename)
# Stage Service
print("Start Staging")
arcpy.server.StageService(sddraft_output_filename, sd_output_filename)
# Sign in to portal to upload and publish
arcpy.SignInToPortal("https://portal.domain.com/webadaptor",
"MyUserName", "MyPassword")
# Share to portal
print("Start Uploading")
arcpy.server.UploadServiceDefinition(sd_output_filename, "https://MyFederatedServer.domain.com/serverWebadaptor")
print("Finish Publishing")
The following script creates a map image layer service definition draft file (.sddraft) that enables the checkUniqueIDAssignment property. The .sddraft file is analyzed during staging. If the map is not set to allow assignment of unique numeric IDs for sharing web layers, analyzer error 00374 is returned and a message is printed. For more information, see Assign layer IDs.
import arcpy
import os
# Sign in to portal
arcpy.SignInToPortal("https://portal.domain.com/webadaptor",
"MyUserName", "MyPassword")
# Set output file names
outdir = r"C:\Project\Output"
service_name = "MapImageSharingDraftExample"
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"C:\Project\World.aprx")
m = aprx.listMaps('World')[0]
# Create MapImageSharingDraft and set the check unique ID assignment property
server_type = "FEDERATED_SERVER"
federated_server_url = "https://MyFederatedServer.domain.com/serverWebadaptor"
sddraft = m.getWebLayerSharingDraft(server_type, "MAP_IMAGE", service_name)
sddraft.federatedServerUrl = federated_server_url
sddraft.checkUniqueIDAssignment = True
# Create Service Definition Draft file
sddraft.exportToSDDraft(sddraft_output_filename)
try:
# Stage Service
print("Start Staging")
arcpy.server.StageService(sddraft_output_filename, sd_output_filename)
# Share to portal
print("Start Uploading")
arcpy.server.UploadServiceDefinition(sd_output_filename, federated_server_url)
print("Finish Publishing")
except Exception as stage_exception:
if "00374" in str(stage_exception):
print("The map is not set to allow assignment of unique IDs")
print("Analyzer errors encountered - {}".format(str(stage_exception)))
except arcpy.ExecuteError:
print(arcpy.GetMessages(2))