HOW TO

Edit branch versioned feature layers using the ArcGIS API for Python

Last Published: May 22, 2024

Summary

Branch versioning is a type of geodatabase versioning that works with the ArcGIS Enterprise Web GIS model using a services-based architecture to allow multiuser editing workflows and long transaction scenarios through web feature layers. Web feature layers (also known as feature services) are layers that are shared to support displaying, querying, and editing data on the web.

The ArcGIS API for Python makes programmatic editing of branch-versioned feature layers possible. At a high level, a typical branch versioned editing workflow is as follows:

  • Create a branch version to isolate edits from the default version. (Version Management)
  • Start an edit session (Version Management)
  • Create a new feature (Feature Access)
  • Reconcile the current branch version with the default version. (Version Management)
  • Post changes from the current version to the default version. (Version Management)
  • Stop the edit session. (Version Management)
  • Delete the version. (Version Management)

Procedure

The below Python code snippet demonstrates how to perform edits on a branch versioned point feature layer via the Version Management Server

from arcgis.gis import GIS
from arcgis.features._version import VersionManager

try:
# parameters
machine = 'machine.domain'
portalUrl = 'https://{0}/webadaptor'.format(machine)
base_server_url = "https://{0}/server/rest/services/samplePointsBV".format(machine)
version_management_server_url = "{0}/VersionManagementServer".format(base_server_url)
new_version_name = "v1"
userName = ''
password = ''

# Sign in to Portal
gis = GIS(portalUrl, userName, password)

vms = VersionManager(version_management_server_url, gis)
print(vms.properties)

# Get a list of all versions
versions = vms.all
print(versions)

# feature to add
feature = {
"attributes": {
"name": "TEST123",
},
"geometry": {
"x": 153.11349,
"y": -27.492016
}
}

# Create a new version
version = vms.create(new_version_name)
print(version.properties)

# Get the layer to edit
editlayer = version.layers[0]
print(editlayer)

# Start an edit session
version.mode = 'edit'
version.start_editing()

add_result = version.edit(editlayer, adds=[feature], updates=None, deletes=None, use_global_ids=False, rollback_on_failure=True)
print(add_result)

version.stop_editing(save=True)
version.mode = None

print("Edits complete")

except Exception as err:
print("Error: {0}".format(err))

Article ID: 000032186

Software:
  • ArcGIS API for Python

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options