Branched Version Parcel Fabric Workflow

2081
15
Jump to solution
09-02-2022 06:28 AM
DeanAnderson2
Occasional Contributor II

I am looking for some advice.  I am currently using ArcPro 2.9+ with a branched versioning and am setting up a new workflow.  As a first step in our workflow process I need to create a version with a record.  I prefer to do this all in one step so that I can programmatically control/manage both version and record info with one user interface.  Once a version is created I have found that I can programmatically create a record using the following code which creates a record in the Parcel Fabric records feature class (with no spatial component). Obviously, I will be adding more attributes but am using this as a basic test. 

-------------

thisProject = arcpy.mp.ArcGISProject("CURRENT")
Map = thisProject.activeMap
TargetFabric = Map.listLayers("TaxlotsPF")[0]
TargetRecord = Map.listLayers("Records")[0]

cursor = arcpy.da.InsertCursor(TargetRecord, ["Name"])

cursor.insertRow(["DeanTest111"])

----------------

I also found I can create a version using the "CreateVersion" tool.  Again, using the tool from a script is important as we want to manage both the version name and the record name following a set of rules and also ensure that improper characters are not used to name a version or a record.  I just took the following example from the user documentation but have used the tool successfully in a test environment. 

arcpy.CreateVersion_management(inWorkspace, parentVersion, versionName, "PUBLIC")

-----

The "Change Version" tool only seems to apply to specific layers.   It does seem to work that I can assign my new record change to a specific version (yay). Can this tool apply to "ALL" layers in my current project?  (I will be trying this next - It should be pretty simple to loop through all layers in my current active map )

My question is:  Is this a good way to do this or are there better ways?  I have been testing a variety of tools, scripts, tasks etc. in a branched version environment for awhile. 

Again Our Goal - One user interface that helps the user create both  a new version with a new record  and changes the version and makes the new record active. 

0 Kudos
1 Solution

Accepted Solutions
KenGalliher1
Esri Contributor

Hello,

One suggestion would be to use the ArcGIS API for Python (ArcGIS Python API). This API is designed to work with feature services and contains all the necessary components to work with branch versioned parcel fabrics.

I have written a few samples that show how to manage branch versioning, creating parcel records and other parcel fabric functionality.

Part 1 - Introduction to Parcel Fabric layers | ArcGIS API for Python

Part 2 - Branch Versioning with Parcel Fabric | ArcGIS API for Python

Part 3 - Create a New Parcel Record | ArcGIS API for Python

In the "Part 3" example, you can see the new version is passed as an argument when creating a new record. All methods that insert, update or delete data from a feature layer have a parameter to pass in a branch version.

edit_features(adds=[record_dict], gdb_version=<branch version name>)               

 

The ArcGIS Python API can be used with the ArcPy module and any other python packages.

 

Another suggestion, since it seems you are in a Pro map, would be to create an Add-In with the Pro SDK. This can help simplify setting the version and parcel record and persisting those throughout the map session.

ProConcepts Parcel Fabric · Esri/arcgis-pro-sdk Wiki (github.com)

View solution in original post

0 Kudos
15 Replies
KenGalliher1
Esri Contributor

Hello,

One suggestion would be to use the ArcGIS API for Python (ArcGIS Python API). This API is designed to work with feature services and contains all the necessary components to work with branch versioned parcel fabrics.

I have written a few samples that show how to manage branch versioning, creating parcel records and other parcel fabric functionality.

Part 1 - Introduction to Parcel Fabric layers | ArcGIS API for Python

Part 2 - Branch Versioning with Parcel Fabric | ArcGIS API for Python

Part 3 - Create a New Parcel Record | ArcGIS API for Python

In the "Part 3" example, you can see the new version is passed as an argument when creating a new record. All methods that insert, update or delete data from a feature layer have a parameter to pass in a branch version.

edit_features(adds=[record_dict], gdb_version=<branch version name>)               

 

The ArcGIS Python API can be used with the ArcPy module and any other python packages.

 

Another suggestion, since it seems you are in a Pro map, would be to create an Add-In with the Pro SDK. This can help simplify setting the version and parcel record and persisting those throughout the map session.

ProConcepts Parcel Fabric · Esri/arcgis-pro-sdk Wiki (github.com)

0 Kudos
DeanAnderson2
Occasional Contributor II

Thanks - this will get me started.  Was looking at SDK but was hoping I could make it happen with Python.  Will see how it goes. 

Thanks again

 

DeanAnderson2
Occasional Contributor II

Good examples - I seem to be missing something though (not surprising).  I will be running this form inside an ArcPro session so was glad to see that I can reference the gis class using pro.  However, it appears that I am doing something wrong.  I have used the following code in a python window and get the following error.  It appears that I do not have permission but it seems like I should (as referenced in the documentation). 

-- Python Code --- 

base_server_url = "https://gisportal.co.polk.or.us/server/rest/services/ParcelTest"
gis = GIS("pro")

arcpy.AddMessage(gis.properties.user.username)

service_endpoints = ["FeatureServer", "VersionManagementServer"]
service_urls = {url: base_server_url + url for url in service_endpoints}
parcel_fabric_flc = FeatureLayerCollection(service_urls["FeatureServer"], gis)

------ Error Message --------- 

Traceback (most recent call last):
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\__init__.py", line 14205, in _hydrate
    self._refresh()
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\__init__.py", line 14164, in _refresh
    raise e
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\__init__.py", line 14157, in _refresh
    dictdata = self._con.post(self.url, params, token=self._lazy_token)
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 1079, in post
    force_bytes=kwargs.pop("force_bytes", False),
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 625, in _handle_response
    self._handle_json_error(data["error"], errorcode)
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 648, in _handle_json_error
    raise Exception(errormessage)
Exception: User does not have permissions to access this folder.
(Error Code: 403)

0 Kudos
DeanAnderson2
Occasional Contributor II

Also - I did not include the printed user name but the correct user name is printed before the error is generated so I know that  "gis"  is being referenced correctly. 

0 Kudos
KenGalliher1
Esri Contributor

Hi Dean. I am seeing some issues using Pro's Python window as well. I'll continue to look into it.

In the meantime, can you try the same thing using a Pro Notebook? I am not getting any errors getting the fabric and version manager.

 

KenGalliher1_1-1662481325721.png

 

0 Kudos
DeanAnderson2
Occasional Contributor II

I get the same error when I when I run the script from a tbx tool. (just shells out to the script).  I will look at notebook. Thanks for looking at this 

 

0 Kudos
DeanAnderson2
Occasional Contributor II

Not a "notebook" user and got similar error. 

Entered code... 

import arcpy, datetime, sys
from arcgis import GIS
from arcgis.features.layer import FeatureLayer
from arcgis.features.layer import FeatureLayerCollection

base_server_url = "https://gisportal.co.polk.or.us/server/rest/services/ParcelTest"
gis = GIS("pro")
print("url: " + base_server_url)
print("username:" + gis.properties.user.username)

service_endpoints = ["FeatureServer", "VersionManagementServer"]
service_urls = {url: base_server_url + url for url in service_endpoints}

parcel_fabric_flc = FeatureLayerCollection(service_urls["FeatureServer"], gis)

---- "run" 

 
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
In  [1]:
Line 14:    parcel_fabric_flc = FeatureLayerCollection(service_urls["FeatureServer"], gis)

File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\features\layer.py, in __init__:
Line 3732:  if self.properties.syncEnabled:

File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\__init__.py, in properties:
Line 14176: self._hydrate()

File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\__init__.py, in _hydrate:
Line 14228: self._refresh()

File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\__init__.py, in _refresh:
Line 14162: dictdata = self._con.get(self.url, params)

File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\_impl\_con\_connection.py, in get:
Line 506:   ignore_error_key=ignore_error_key,

File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\_impl\_con\_connection.py, in _handle_response:
Line 625:   self._handle_json_error(data["error"], errorcode)

File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\_impl\_con\_connection.py, in _handle_json_error:
Line 648:   raise Exception(errormessage)

Exception: User does not have permissions to access this folder.
(Error Code: 403)

 

0 Kudos
DeanAnderson2
Occasional Contributor II

Ken 

Its a new day  / I started over from your example - First test worked - Both in a python window  and from a tool/script. Code and results running the tool/script are: 

Code -----------

import arcpy, datetime, sys

from arcgis import GIS
from arcgis.features import _version

base_server_url = "https://gisportal.co.polk.or.us/server/rest/services/ParcelTest"

gis =GIS("pro")
arcpy.AddMessage("username:" + gis.properties.user.username)

from arcgis.features._version import VersionManager

version_management_server_url = f"{base_server_url}/VersionManagementServer"
vms = VersionManager(version_management_server_url, gis)
arcpy.AddMessage(vms.properties)

---- Result Messages ---- 

Start Time: Wednesday, September 7, 2022 6:02:57 AM
username:andersd
{
  "name": "Version Management Server",
  "type": "Map Server Extension",
  "defaultVersionName": "sde.DEFAULT",
  "defaultVersionGuid": "{BD3F4817-9A00-41AC-B0CC-58F78DBAE0A1}",
  "capabilities": {
    "supportsConflictDetectionByAttribute": true,
    "supportsPartialPost": true,
    "supportsDifferencesFromMoment": true,
    "supportsDifferencesWithLayers": true,
    "supportsAsyncReconcile": true,
    "supportsAsyncPost": true,
    "supportsAsyncDifferences": true
  }
}
Succeeded at Wednesday, September 7, 2022 6:02:57 AM (Elapsed Time: 0.30 seconds)

----------------------------------------

I will keep testing - thanks again for looking into this.  

DeanAnderson2
Occasional Contributor II

Ken 

I think I have figured it out.  IN our example for Part 2 - Branched Versioning for Parcel Fabric when you reference the Service_urls it appears that you may be missing a "/".  The example is as follows: 

 

DeanAnderson2_0-1662569528490.png

I got it to work by changing the service_urls to be the following: 

service_urls = {url: base_server_url + "/" + url for url in service_endpoints}

I no longer get the permissions error I was getting and will continue to proceed.