Automate sharing web layers

You can automate sharing, overwriting, and replacing web layers with Python by using a combination of ArcPy functions in the Sharing module and geoprocessing tools in the Publishing, Caching, Tile Cache, and Package toolsets.

There are two ways to automate sharing web layers: you can publish web layers from service definitions or from packages. The approach you should use depends on the type of web layer you want to publish. If you use the service definition approach, the web layer is published from a service definition. If you use the package approach, the cache is created locally as a package that is then uploaded and used to publish the web layer.

Web layer typeService definitionPackage

Web feature layer

Supported

Map image layer

Supported

Stand-alone table

Supported

Web tile layer

Supported

Supported

Vector tile layer

Supported

Web scene layer

Supported

Web elevation layer

Supported

Web layers by supported publishing approach
Note:

Some web layer configurations cannot be published with Python. The following must be published using the application user interface:

  • Vector tile layer with an associated map image layer and/or web feature layer
  • Web scene layer with an associated map image layer and/or web feature layer

Publish web layers from service definitions

The workflow to publish a web layer begins with a map in a project or raster dataset that you want to share.

  1. First, create a service definition draft using the getWebLayerSharingDraft method from the Map class. For more information, see FeatureSharingDraft, MapImageSharingDraft, or TileSharingDraft. To create a service definition draft for a stand-alone table, use the ListTables function with the FeatureSharingDraft class.

    To overwrite a web feature layer, map image layer, or stand-alone table, modify the overwriteExistingService property of the sharing draft.

    Note:

    This property is not available for TileSharingDraft. For web tile layers, use the Replace Web Layer geoprocessing tool instead.

  2. Next, use the Stage Service geoprocessing tool to stage the service definition. Staging takes the service definition draft and consolidates all the information needed to share the web layer into a complete service definition.
  3. Finally, use the Upload Service Definition geoprocessing tool to upload the service definition and publish the web layer.
  4. Note:

    You will need to sign in to ArcGIS Pro with an ArcGIS Online or ArcGIS Enterprise account that has privileges to create content and publish.

Publish web layers from packages

For web tile layers and vector tile layers, the workflow begins with a map in a project that you want to share. For web scene layers and web elevation layers, it begins with a supported input dataset.

  1. First, create a package for the type of web layer you want to share using the corresponding geoprocessing tool or tools.

    Web layer type Geoprocessing tool or tools

    Web tile layer

    Create Map Tile Package

    Vector tile layer

    Create Vector Tile Package

    Web scene layer

    There are several tools that create scene layer packages. See Create and share a scene layer package for more information.

    Web elevation layer

    Manage Tile Cache and Export Tile Cache

    Web layers by geoprocessing tools used to create their content
    Tip:

    Before creating a tile package for a web tile layer or web elevation layer, optionally use the Generate Map Server Cache Tiling Scheme or Generate Tile Cache Tiling Scheme tool to generate a tiling scheme in the projection of your map or elevation dataset. You can skip this step if you want to use the ArcGIS Online/Bing Maps/Google Maps tiling scheme. For more information, see Share a tile package.

  2. Next, use the Share Package tool to upload and publish the package as a web layer to ArcGIS Online or ArcGIS Enterprise.
  3. Finally, optionally, use the Replace Web Layer tool to replace the content of an existing web layer in a portal with the content of the new web layer.

    Note:

    Web elevation layers cannot be replaced.

Learn more about using tools in Python