Using python to Validate Network Topology in a version

1858
18
Jump to solution
09-15-2023 04:44 AM
jclarke
Occasional Contributor

Hi all,

I am trying to write a standalone python script that does something like this

arcpy.ChangeVersion_management('unnetworklayer','BRANCH', version_name, '#', 'INCLUDE')
arcpy.ValidateNetworkTopology_un('unnetworklayer', 'DEFAULT')
 
The documentation says both these tools accept a "Utility Network Layer" as input. But how can I make one? I have tried MakeFeatureLayer etc.
0 Kudos
1 Solution

Accepted Solutions
RobertKrisher
Esri Regular Contributor

You should be able to pass in the URL to the feature service and layer id of the utility network to get this information. However, for creating standalone Python scripts doing fine-grained operations against ArcGIS Enterprise my recommendation is to use the ArcGIS API for Python (read this article about pros/cons of different apis for more details).

One other important item to take into consideration, that the ArcGIS API for Python will give you but ArcPy won't, is that when you connect to a version and start making edits (or validating, reconciling, etc) you are potentially going to be competing with other users for locks. If another user is editing that version, your process will fail. If your process is running on a version than other users won't be able to edit it.

View solution in original post

18 Replies
RobertKrisher
Esri Regular Contributor

You should be able to pass in the URL to the feature service and layer id of the utility network to get this information. However, for creating standalone Python scripts doing fine-grained operations against ArcGIS Enterprise my recommendation is to use the ArcGIS API for Python (read this article about pros/cons of different apis for more details).

One other important item to take into consideration, that the ArcGIS API for Python will give you but ArcPy won't, is that when you connect to a version and start making edits (or validating, reconciling, etc) you are potentially going to be competing with other users for locks. If another user is editing that version, your process will fail. If your process is running on a version than other users won't be able to edit it.

jclarke
Occasional Contributor

Thanks for the reply - I particularly like that pros and cons matrix in the link.

At this site many arcpy scripts are in use and not ArcGIS API for Python, so it would be great to get this script working, though its good to have that fall-back option of changing API. The edits are being applied beforehand via FME, and no-one else should be editing the version.

When using the URL to the UN layer with arcpy I cant see a way to to change version - the Validate call works on sde.default. 

0 Kudos
RobertKrisher
Esri Regular Contributor

I've been out this week so haven't had a chance to test this on my end, but are you saying if you run a standalone python script that does the following:

  • Create Layer (using feature service URL and giving it some unique layer name)
  • Change version (on layer)
  • Validate topology (on layer)

You are seeing that it is still only validating default? If you're performing this test in ArcGIS Pro you should make sure that the layer name you are using is unique. I can tell you that the ArcGIS API for Python does support all this.

0 Kudos
jclarke
Occasional Contributor

Hi Robert - re these three steps - I cant get those to run without error

  • Create Layer (using feature service URL and giving it some unique layer name)
  • Change version (on layer)
  • Validate topology (on layer)

I think its the "Create Layer" step I am stuck on - its MakeFeatureLayer I am using for this, but ValidateNetworkTopology needs a Utility Network layer, not a feature layer, and so errors.

0 Kudos
RobertKrisher
Esri Regular Contributor

The correct approach for what you want to do is to use the ArcGIS API for Python. I was able to get around some of this by saving an existing utility network layer to a file, then opening it as a layer file, accessing the first layer in the file. But I ran into problems in getting the rest the tools to behave properly, especially since they don't get me the ability to set/clear locks as I discussed above.

0 Kudos
jclarke
Occasional Contributor

Thanks for your help Robert!

0 Kudos
KevinPiraino2
Regular Contributor

I am trying to automate some of the UN admin tasks using the Python API, but I am struggling a bit with this task, namely creating the UN object (and hitting the default version). Have either of @jclarke or @RobertKrisher had any success in developing this script? Below is what I have so far.

 

import arcgis
from arcgis.gis import GIS

gis = GIS('https://myorg.gov/portal/','username', 'password')


#utility network URL
util_url = 'https://myorg.gov/un_fabric/rest/services/Utility_Network/Water_Distribution_Source/UtilityNetworkServer'

network_url = 'https://myorg.gov/un_fabric/rest/services/Utility_Network/Water_Distribution_Source/FeatureServer/9'

UN_url = 'https://myorg.gov/un_fabric/rest/services/Utility_Network/Water_Distribution_Source/FeatureServer'

UN_vers = 'https://myorg.gov/un_fabric/rest/services/Utility_Network/Water_Distribution_Source/VersionManagementServer'

#--------------------------------------------------------
UN_flc = arcgis.features.layer.FeatureLayerCollection(UN_url,gis)
vms_from_flc = UN_flc.versions
default_version = vms_from_flc.all[0]
default_guid = default_version.properties.versionGuid
#---------------------------------------------------------

#returns error "AttributeError: 'PropertyMap' instance has no attribute 'versionName'"
df_version = arcgis.features._version.Version(url=UN_url,flc=UN_flc,gis=gis,session_guid=default_guid)

UN = arcgis.features._utility.UtilityNetworkManager(url=util_url,version=default_version,gis=gis)

envelope = {
    "xmin": 1018472.222250,
    "ymin": 1819952.386750,
    "xmax": 1105416.666750,
    "ymax": 1940603.168750,
    "spatialReference": {
    "wkid": 3435,
    "latestWkid": 102671
    }
}

#returns error "Exception: Unable to resume a service session."
UN.validate_topology(envelope) 

#returns error "Exception: Unable to resume a service session."
UN.update_subnetwork('Water','Water System',all_subnetwork_tier=True,continue_on_failure=True)

UN.update_is_connected()

 

0 Kudos
RobertKrisher
Esri Regular Contributor

It seems a little like cheating, but my preferred way to get a UN pointed as a specific version is to get it from the version itself. there is a "utility" property on each version that contains a reference to the utility network for that version (if one is present in the service).

RobertKrisher_0-1727099663493.png

 

0 Kudos
KevinPiraino2
Regular Contributor

I think my issue currently is that I am unable to instantiate the Version object using the provided UN information from earlier in the script. Every time I try to create the Version object, the script will create it, but when calling the Version object I get the following error:

"AttributeError: 'PropertyMap' instance has no attribute 'versionName'"

I also receive this same error when trying to access the utility property from the Version object.

0 Kudos