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 by either using sharing drafts created with the Sharing module or using packages. The approach you should use depends on the type of web layer you want to publish. If you use the sharing draft approach, most web layers are 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 type | Sharing draft | Package |
---|---|---|
Note:
Some web layer configurations cannot be published with Python. For example, vector tile layers with an associated map image layer and/or web feature layer must be published using the application user interface.
Publish web layers using sharing drafts
The workflow to publish a web layer begins with a map in a project or raster dataset that you want to share.
- First, create a sharing draft using the getWebLayerSharingDraft method from the Map class. For more information, see FeatureSharingDraft, MapImageSharingDraft, TileSharingDraft, or SceneLayerSharingDraft. To create a sharing draft for a web scene layer, use the listLayers method on the Map class with the SceneLayerSharingDraft class. To create a sharing draft for a stand-alone table, use the ListTables function with the FeatureSharingDraft or MapImageSharingDraft 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 or SceneLayerSharingDraft. Alternative workflows are available. For web tile layers, use the Replace Web Layer geoprocessing tool instead. For web scene layers, obtain the existing item ID and specify it in the item_id parameter of the Publish function when you are ready to republish the web layer.
- If your sharing draft is a FeatureSharingDraft, MapImageSharingDraft, or TileSharingDraft, stage and publish the service definition.
- Use the Stage Service geoprocessing tool to stage the service definition draft, consolidating all the necessary information to share the web layer into a complete service definition.
- Use the Upload Service Definition geoprocessing tool to upload the service definition and publish the web layer
- If your sharing draft is a SceneLayerSharingDraft, use the Publish function to publish the web scene layer with an associated web feature layer.
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 using 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.
- 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 Create Map Tile Package Create Vector Tile Package There are several tools that create scene layer packages. See Create and share a scene layer package for more information.
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.
- Next, use the Share Package tool to upload and publish the package as a web layer to ArcGIS Online or ArcGIS Enterprise.
- 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.