Replace Web Layer (Server)

Summary

Replaces the content of a web layer in a portal with the content of another web layer.

Usage

  • The target layer is the web layer to be replaced. The update layer is the replacement web layer. The target and update layers can be the following types of web layers:

    • Vector tile layers published from vector tile packages
    • Tile layers
    • Scene layers published from one of the following sources:
      • Scene layer packages hosted on ArcGIS Online or an ArcGIS Enterprise portal
      • Referenced scene caches in folder or cloud data stores

      Voxel scene layers cannot be replaced.

  • To replace a vector tile layer on an ArcGIS Enterprise portal, you must be using version 10.6 or later. To replace a tile layer, you must be using version 10.8 or later. To replace a scene layer, you must be using version 10.8.1 or later.

  • Your ArcGIS Pro active portal must be the portal that hosts the target and update layers. You must be signed in to ArcGIS Pro with the account that owns the target and update layers.

  • The target and update layers must be of the same type. For example, you cannot replace a vector tile layer with a tile layer.

  • The scene layer type of the target layer and update layer must match. For example, you cannot replace a building scene layer with a 3D object scene layer.

  • To replace a web scene layer, the target layer and update layer must be published from the same source. For example, you cannot replace a web scene layer published from a scene layer package with a web scene layer published from a referenced scene cache.

  • To replace web scene layers published from referenced scene caches, the scene services of the target layer and update layer must exist in the same server and server folder.

  • When the target layer is updated, the content of the layer is replaced. The item ID and service URL of the target layer do not change.

  • The web layer that is replaced is not overwritten. It is archived in your portal with a new name. By default, the archive layer name is <layer name>_archive_<timestamp>. You can assign a different name, but it must be a unique web layer name in the portal.

  • By default, the archive layer uses the item ID of the update layer. You can specify a new item ID for the archive layer.

  • You can replace the item information of the target layer with the item information of the update layer. If you replace the item information, the summary, description, tags, and thumbnail image are replaced. Other information, such as the credits (attribution) and terms of use are not replaced.

Parameters

LabelExplanationData Type
Target Layer

The web layer that will be replaced. Provide a layer or catalog path, or provide the item ID or service URL of one of the following:

  • Vector tile layer published from vector tile package
  • Tile layer
  • Scene layer published from one of the following sources:
    • Scene layer package
    • Referenced scene cache in folder or cloud data stores

Vector Tile Layer; Internet Tiled Layer; Scene Layer
Archive Layer Name

A unique name for the archive layer. The web layer that is replaced remains in the portal as an archive layer.

String
Update Layer

The replacement web layer. Provide a layer or catalog path, or provide the item ID or service URL of one of the following:

  • Vector tile layer published from vector tile package
  • Tile layer
  • Scene layer published from one of the following sources:
    • Scene layer package
    • Referenced scene cache in folder or cloud data stores

Vector Tile Layer; Internet Tiled Layer; Scene Layer
Replace Item Information
(Optional)

Specifies whether the target layer's item information (thumbnail image, summary, description, and tags) will be replaced. With either option, the item's credits (attribution), terms of use, and created-from information will not be replaced.

  • Unchecked—The target layer's item information will not be replaced when the layer is updated. This is the default.
  • Checked—The target layer's item information will be replaced by the update layer's item information.
Boolean
Create New Item For Archive Layer
(Optional)

Specifies whether an item will be created for the archive layer. This parameter is supported on portals in ArcGIS Online and ArcGIS Enterprise 10.8 or later.

  • Unchecked—The item ID of the update layer will be used for the archive layer. This is the default for vector tile layers and tile layers.
  • Checked—An item ID will be created for the archive layer. This is the default for scene layers.
Boolean

Derived Output

LabelExplanationData Type
Updated Target Layer

The URL of the updated web layer.

String

arcpy.server.ReplaceWebLayer(target_layer, archive_layer_name, update_layer, {replace_item_info}, {create_new_item})
NameExplanationData Type
target_layer

The web layer that will be replaced. Provide a layer or catalog path, or provide the item ID or service URL of one of the following:

  • Vector tile layer published from vector tile package
  • Tile layer
  • Scene layer published from one of the following sources:
    • Scene layer package
    • Referenced scene cache in folder or cloud data stores

Vector Tile Layer; Internet Tiled Layer; Scene Layer
archive_layer_name

A unique name for the archive layer. The web layer that is replaced remains in the portal as an archive layer.

String
update_layer

The replacement web layer. Provide a layer or catalog path, or provide the item ID or service URL of one of the following:

  • Vector tile layer published from vector tile package
  • Tile layer
  • Scene layer published from one of the following sources:
    • Scene layer package
    • Referenced scene cache in folder or cloud data stores

Vector Tile Layer; Internet Tiled Layer; Scene Layer
replace_item_info
(Optional)

Specifies whether the target layer's item information (thumbnail image, summary, description, and tags) will be replaced. With either option, the item's credits (attribution), terms of use, and created-from information will not be replaced.

  • KEEPThe target layer's item information will not be replaced when the layer is updated. This is the default.
  • REPLACEThe target layer's item information will be replaced by the update layer's item information.
Boolean
create_new_item
(Optional)

Specifies whether an item will be created for the archive layer. This parameter is supported on portals in ArcGIS Online and ArcGIS Enterprise 10.8 or later.

  • TRUEAn item ID will be created for the archive layer. This is the default for scene layers.
  • FALSEThe item ID of the update layer will be used for the archive layer. This is the default for vector tile layers and tile layers.
Boolean

Derived Output

NameExplanationData Type
updated_target_layer

The URL of the updated web layer.

String

Code sample

ReplaceWebLayer example 1 (stand-alone script)

The following script replaces a web layer using the item IDs of the input layers.

import arcpy
import time

# Set local variables
targetLayerID = "42994b1a3e63425aa02bcfa1200683ae"
archiveLayerName = "ReplaceWebLayerExample_archive_" + time.strftime("%Y%m%d")
updateLayerID = "9e1d80c874e040fc88ad06b0cfa01381"
replaceItemInfo = "REPLACE"
createNewItem = "TRUE"

# Run Replace Web Layer
arcpy.server.ReplaceWebLayer(targetLayerID, archiveLayerName, updateLayerID, 
                             replaceItemInfo, createNewItem)

print("Successfully replaced web layer.")
ReplaceWebLayer example 2 (stand-alone script)

The following script replaces a web layer on ArcGIS Enterprise using the service URLs of the input layers.

import arcpy
import time

# Set local variables
targetLayer = "https://webadaptorhost.domain.com/webadaptorname/rest/services/Hosted/targetServiceName/VectorTileServer"
archiveLayerName = "targetServiceName_archive_" + time.strftime("%Y%m%d")
updateLayer = "https://webadaptorhost.domain.com/webadaptorname/rest/services/Hosted/updateServiceName/VectorTileServer"

# Run Replace Web Layer
arcpy.server.ReplaceWebLayer(targetLayer, archiveLayerName, updateLayer)

print("Successfully replaced web layer.")
ReplaceWebLayer example 3 (stand-alone script)

The following script publishes and replaces a vector tile layer.

The script creates a vector tile package by calling the CreateVectorTilePackage function for a map. Next, the SharePackage function uploads the vector tile package to ArcGIS Online or ArcGIS Enterprise and publishes it as a vector tile layer. Finally, the ReplaceWebLayer function uses item IDs to replace the content of an existing web layer in the portal with the content of the new web layer. The vector tile layer that is replaced is archived in the portal with a new name. Portal information is obtained from the SignInToPortal function.

import arcpy
import os
import json

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

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

# Set output file names
outdir = r"C:\Project\Output"
service_name = "VectorTileLayerExample"
package_filename = service_name + ".vtpk"
package_output_filename = os.path.join(outdir, package_filename)

# Create vector tile package
arcpy.management.CreateVectorTilePackage(m, package_output_filename, "ONLINE")

# Upload and publish vector tile package
result = arcpy.management.SharePackage(package_output_filename, publish_web_layer=True)

print("Finish uploading and publishing package")

# Get the item ID or service URL of the vector tile layer
jobresult = result[1]
result = json.loads(jobresult)

# Publish results JSON response example: {"publishStatus":"<status>","publishMessage":"<message>","publishResult":{"type":"Vector Tile Service","serviceurl":"<service_url>","size":1913146,"jobId":"<ID>","serviceItemId":"<ItemID>"}}
itemID = str(result.get('publishResult', {}).get('serviceItemId'))

print("Start Replacing")

# Set local variables for Replace Web Layer workflow
# target_layer/update_layer can be item ID or service URL; example below uses item ID
target_layer = "808ecf02f39441d69f245c0cb261134b"
archive_layer_name = "ReplaceWebLayerExample_archive"
update_layer = itemID
replace_item_info = "REPLACE"
create_new_item = "TRUE"

# Run Replace Web Layer
arcpy.server.ReplaceWebLayer(target_layer, archive_layer_name, update_layer,
                             replace_item_info, create_new_item)

print("Finished Replacing")

Environments

Licensing information

  • Basic: Yes
  • Standard: Yes
  • Advanced: Yes

Related topics