Hi, I'm working on a script to programatically load Water Junction (taps), Water Line (service lines), and Water Device (meters) into a branch version within a water Utility Network.
The script uses the ArcGIS Python API to get the version from the Version Manager. It then uses the Version.edit() method to add new features to the version. Finally, it uses the Utility Network Manager's validate_topology() method to validate the entire UN.
The features are successfully loaded into the version and the dirty areas are removed from the newly added features, but the new features are not connected to the Utility Network and they are not returned in any trace results. They do seem to be connected to each other, however. For example, if you move one of the newly added meters, then the attached newly added service line will also move with it. Also, if I open ArcGIS Pro and move a tap away from a water main, re-attach it, and validate topology, then the tap, service line, and meter all become connected to the UN and are returned in trace results.
I'm wondering if there's some step or other GP tool that I need to run within the script, other than the topology validation, in order to make sure the newly added features are connected to the UN. Below are code samples of the adding of features and the topology validation done in the script. I may need to consult with ESRI on this, but figured that I'd try the forums first, to see if there's something glaring that I'm missing. Thanks!
Code sample: Adding features to branch version:
# Add meters
script.logger.info('Adding water devices')
meters_add_feature_set = arcpy.FeatureSet(new_meters_fc)
meters_add_feature_set_json = json.loads(meters_add_feature_set.JSON)
edit_layer = service_script_version.layers[water_device_layer_index]
service_script_version.mode = 'edit'
add_result = service_script_version.edit(layer=edit_layer, adds=meters_add_feature_set_json['features'])
number_successful_adds = 0
for entry in add_result['addResults']:
if entry['success'] is True:
number_successful_adds += 1
script.logger.info('Number of features successfully added: ' + str(number_successful_adds))
script.logger.info('Stopping editing and saving edits')
service_script_version.stop_editing(save=True)
Code sample: Validating topology:
# Validate topology
service_script_version = version_manager.get(version_name)
service_script_version.mode = 'edit'
script.logger.info('Getting utility network from version')
utility_network_manager = service_script_version.utility
script.logger.info('Validating Network Topology')
validation_envelope = {"xmin": 2944897.7434605407,
"ymin": 9969206.089035971,
"xmax": 3210005.065902318,
"ymax": 10211905.345106306,
"spatialReference": {"wkid": 102739,
"latestWkid": 2277}
}
validation_result = utility_network_manager.validate_topology(envelope=validation_envelope)
script.logger.info('Validation result: ' + str(validation_result))
service_script_version.stop_editing(save=True)
You mentioned that they seem to be "connected" in the sense that they are snapped to the line and the line moves when the device is moved.
The next thing to check is Z values. They won't be connected unless the line and device all have the same x/y/z coordinate.
Just to add to the above, worth checking what Z value is being supplied in the "adds" operation.
It's possible that the editing in ArcGIS pro add the default z value (usually 0 unless defined) which would mean they are "fully connected"
The new features are all connected to each other (meter, service line, and tap), but they don’t connect to their respective existing water mains. I checked the Z values, and they are all 0. Thanks for this suggestion. I think that the issue is the lack of a vertex on the main where the newly added tap is. I’ll need to work through the code to update the main lines with a new vertex at the same XY as the new taps. Disappointing as this was all handled behind the scenes with the GN
You need to update the line and insert a vertex
For example, if you move one of the newly added meters, then the attached newly added service line will also move with it.
I thought that implied that a Vertex was created?
I think you’re probably right. I manually dropped a vertex where one of the service lines meets a main in Pro and all the features became connected. Going to need to work through doing this programatically for all the features to be added.