SceneLayerSharingDraft

Summary

The SceneLayerSharingDraft class allows you to create a sharing draft for a web scene layer with an associated web feature layer. You can configure the SceneLayerSharingDraft object for a web scene layer that copies all data or references registered data to ArcGIS Enterprise, or copies all data to ArcGIS Online.

The object can publish the following types of scene layers:

  • Point
  • 3D object
  • Building

To publish a web scene layer cached locally in Python, use geoprocessing tools instead. For more information, see Publish web layers using packages.

Discussion

To create the SceneLayerSharingDraft object, use the Map object's getWebLayerSharingDraft method and set the service_type parameter to SCENE_LAYER. To specify whether the web scene layer copies all data or references registered data to ArcGIS Enterprise, set the server_type parameter to one of the following:

  • HOSTING_SERVER—Copies all data; an associated web feature layer is included.
  • FEDERATED_SERVER—References registered data; an associated map image layer and web feature layer are included.

Additionally, the layers_and_tables parameter in the getWebLayerSharingDraft method must be a list with a single layer. Use the listMaps function from the ArcGISProject object and the listLayers method on the Map class to reference the layer in the 3D scene you want to publish.

The SceneLayerSharingDraft object can then be configured by setting service level properties. You can also set properties on the SceneLayerSharingDraft object for the associated web feature layer and map image layer. If no value is specified for a property, the default value is used. Information about each property is provided in the Properties list below.

Note:

If metadata properties (credits, description, summary, tags, and useLimitations) are not set or consist of empty strings, the web layer item will source metadata from the scene layer in the ArcGIS Pro project, depending on what is shared. For more information about how web layers source metadata, see Web layer metadata.

After the SceneLayerSharingDraft object is configured, it can be analyzed for errors and warnings using the optional analyzeForSharing method, and published using the Publish function. The Publish function publishes the web scene layer and any associated web layers to either ArcGIS Online or ArcGIS Enterprise, and starts caching on the server.

Code samples are available for the following:

Properties

PropertyExplanationData Type
allowUpdateWithoutMValues
(Read and Write)

Specifies whether geometry updates to m-enabled features will be allowed without specifying an m-value. The default value is True.

This is a web feature layer and map image layer property.

Boolean
approvePublicDataCollection
(Read and Write)

Specifies whether public editing will be allowed on a web feature layer.

Boolean
cachedAttributes
(Read and Write)

A list of the layer's fields that will be included in the web scene layer cache.

List
compressedTextures
(Read and Write)

Specifies whether texture optimization will be enabled, which supports faster display in 3D applications. This property is supported when sharing a multipatch or 3D object feature layer.

Boolean
credits
(Read and Write)

The credits of the web layer.

String
description
(Read and Write)

The description of the web layer.

String
export
(Read and Write)

Specifies whether users can export the web scene layer to different formats.

Boolean
featureCapabilities
(Read and Write)

The enabled capabilities, separated by commas. The following capabilities are supported:

  • Query
  • Create
  • Update
  • Delete
  • Sync
  • Extract
  • Editing

Query, Create, Update, Delete, and Editing are the defaults when the server_type property is set to FEDERATED_SERVER.

This a web feature layer and map image layer property.

String
maxRecordCount
(Read and Write)

The maximum number of records that will be returned by the server during querying. The default value is 2000.

This a web feature layer and map image layer property.

Integer
portalFolder
(Read and Write)

The name of the portal folder where the web layer will be published. The default folder is your root folder in My Content.

String
preserveEditUsersAndTimestamps
(Read and Write)

Specifies whether editor tracking information will be preserved. The default value is False.

This is a web feature layer property.

Boolean
serviceName
(Read and Write)

The name of the web layer. This is the name people will see and use to identify the web layer. 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
(Read and Write)

The group names, separated by commas.

String
sharing.sharingLevel
(Read and Write)

The sharing level of the web layer.

  • OWNER—Only the owner (and organization members with privileges to view content owned by other members) can access the item.
  • ORGANIZATION—Share your content with all authenticated users in your organization.
  • EVERYONE—Share your content with the public. Anyone can access and see it.

String
summary
(Read and Write)

The summary of the web layer.

String
tags
(Read and Write)

The tags of the web layer. Multiple tags can be added or separated by a comma.

String
timezone.DaylightSavingTime
(Read and Write)

Specifies whether the time zone accounts for daylight saving time. The default value is False.

This a web feature layer and map image layer property.

Boolean
timezone.ID
(Read and Write)

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.

This is a web feature layer and map image layer property.

String
timezone.preferredTimezoneID
(Read and Write)

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.

This is a web feature layer and map image layer property.

String
timezone.preferredTimezoneIDDaylightSavingTime
(Read and Write)

Specifies whether the preferred time zone accounts for daylight saving time. The default value is False.

This is a web feature layer and map image layer property.

Boolean
useLimitations
(Read and Write)

The use limitations of the web layer.

String
zDefault.enable
(Read and Write)

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 True.

This is a web feature layer and map image layer property.

Boolean
zDefault.value
(Read and Write)

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.

This is a web feature layer and map image layer property.

Double

Method Overview

MethodExplanation
analyzeForSharing ()

The analyzeForSharing method analyzes the SceneLayerSharingDraft object and returns errors, warnings, and messages.

Methods

analyzeForSharing ()
Return Value
Data TypeExplanation
Dictionary

A dictionary of errors, warnings, and messages.

Code sample

Publish a web scene layer that copies all data to a portal folder

The following script creates a web scene layer sharing draft for a layer in a scene and sets metadata and folder properties. The web scene layer is published to a folder in either ArcGIS Online or ArcGIS Enterprise and shared with everyone (public). Portal information is obtained from the SignInToPortal function.

import arcpy

# Sign in to portal
arcpy.SignInToPortal("https://www.arcgis.com", "MyUserName", "MyPassword")

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

# Create SceneLayerSharingDraft and set metadata and portal folder properties
server_type = "HOSTING_SERVER"
service_type = "SCENE_LAYER"
service_name = "SceneLayerSharingDraftExample"
scene_draft = m.getWebLayerSharingDraft(server_type, service_type, service_name, lyr)
scene_draft.credits = "These are credits"
scene_draft.description = "This is description"
scene_draft.summary = "This is summary"
scene_draft.tags = "tag1, tag2"
scene_draft.useLimitations = "These are use limitations"
scene_draft.portalFolder = "my folder name"
scene_draft.sharing.sharingLevel = "EVERYONE"
scene_draft.sharing.groups = ""  # Group names = "group1,group2"

# Share to portal
print("Start Publishing")
res = arcpy.sharing.Publish(scene_draft)

print(r"item_url: " + res["web_scene_layer"]["item_url"])
print(r"rest_url: " + res["web_scene_layer"]["rest_url"])
print(r"cache_job_id: " + res["web_scene_layer"]["cache_job_id"])
print("Finish Publishing")
Publish a web scene layer that references registered data

The following script creates a web scene layer sharing draft. The sharing draft is analyzed. If analyzer 00231 is returned, the data store is registered using the arcgis.gis module in ArcGIS API for Python.

import arcpy

# 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 == fedserver_dict["adminUrl"]+"/admin"][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__":
    portal_url = "https://organization.example.com/webadaptorname"
    username = "MyUserName"
    password = "MyPassword"

    # Sign in to portal
    arcpy.SignInToPortal(portal_url, username, password)

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

    # Local variables
    server_type = "FEDERATED_SERVER"
    service_type = "SCENE_LAYER"
    service_name = "SceneLayerSharingDraftExample"
    sde_conn_file = r"C:\Project\db_conn.sde"
    data_store_name = "PortalDSItem"

    # Create SceneLayerSharingDraft for scene layer that references data in registered data store and set metadata, portal folder, and server folder properties
    scene_draft = m.getWebLayerSharingDraft(server_type, service_type, service_name, lyr)
    scene_draft.credits = "These are credits"
    scene_draft.description = "This is description"
    scene_draft.summary = "This is summary"
    scene_draft.tags = "tag1, tag2"
    scene_draft.useLimitations = "These are use limitations"
    scene_draft.portalFolder = "my folder name"
    scene_draft.serverFolder = "MyServerFolder"
    scene_draft.sharing.sharingLevel = "EVERYONE"
    scene_draft.sharing.groups = ""  # Group names = "group1,group2"

    print("Analyzing")
    analyze_res = scene_draft.analyzeForSharing()
    print(analyze_res)
    register_error = [err for err in analyze_res["errors"] if err["code"] == "00231"]
    # If data store is not registered
    if register_error:
        # Register data store
        register_res = register_datastore_item(portal_url, username, password, sde_conn_file, data_store_name,
                                               "https://gisserver.example.com/webadaptorname")
        if not register_res:
            print("Unable to register the data store, skipping publish")
            exit()

    # Share to portal
    print("Start Publishing")
    res = arcpy.sharing.Publish(scene_draft)

    print(r"item_url: " + res["web_scene_layer"]["item_url"])
    print(r"rest_url: " + res["web_scene_layer"]["rest_url"])
    print(r"cache_job_id: " + res["web_scene_layer"]["cache_job_id"])
    print("Finish Publishing")
Set associated web feature layer capabilities and item IDs

The following script creates a web scene layer sharing draft and sets capabilities, time zone, and cached attributes for the associated web feature layer. It then specifies item IDs for the web scene layer and associated web layers. The web scene layer is published to ArcGIS Enterprise. The data store must be registered on the server before the data can be referenced.

import arcpy

# Sign in to portal
arcpy.SignInToPortal("https://organization.example.com/webadaptorname",
                     "MyUserName", "MyPassword")

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

# Create SceneLayerSharingDraft and set feature capabilities, time zone, and cached attributes properties
server_type = "HOSTING_SERVER"
service_type = "SCENE_LAYER"
service_name = "SceneLayerSharingDraftExample"
scene_draft = m.getWebLayerSharingDraft(server_type, service_type, service_name, lyr)
scene_draft.featureCapabilities = "Query,Create,Update"
scene_draft.timezone.ID = "Pacific Standard Time"
scene_draft.timezone.DaylightSavingTime = True
scene_draft.cachedAttributes = ["field1", "field2"]

# Publish scene layer using the SceneLayerSharingDraft object and specific item ID
# The ID must be available and contain 32 alphanumeric values ranging from letters a to f and numbers 0 to 9
item_id = {
 "web_scene_layer_id": "itemid1",
 "web_feature_layer_id": "itemid2",
 "map_image_layer_id": "itemid3"
}

# Share to portal
print("Start Publishing")
res = arcpy.sharing.Publish(scene_draft, item_id)

print(r"item_url: " + res["web_scene_layer"]["item_url"])
print(r"rest_url: " + res["web_scene_layer"]["rest_url"])
print(r"cache_job_id: " + res["web_scene_layer"]["cache_job_id"])
print("Finish Publishing")

Related topics