Skip to content

Commit af489e7

Browse files
authored
Merge pull request #208 from Esri/chs_ar_dynamic_207
Add addtional AddRaster nodes at runtime #207
2 parents 3b075a8 + 34cec39 commit af489e7

1 file changed

Lines changed: 41 additions & 2 deletions

File tree

scripts/Base/Base.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ------------------------------------------------------------------------------
2-
# Copyright 2025 Esri
2+
# Copyright 2026 Esri
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
55
# You may obtain a copy of the License at
@@ -14,7 +14,7 @@
1414
# ------------------------------------------------------------------------------
1515
# Name: Base.py
1616
# Description: Base class used by MDCS/All Raster Solutions components.
17-
# Version: 20250220
17+
# Version: 20260708
1818
# Requirements: ArcGIS 10.1 SP1
1919
# Author: Esri Imagery Workflows team
2020
# ------------------------------------------------------------------------------
@@ -906,3 +906,42 @@ def _is_builtin_event(self, fnc_name: str):
906906
if fnc_name is None:
907907
return False
908908
return fnc_name in [self.EVT_ON_EXIT, self.EVT_ON_START]
909+
910+
def add_raster_nodes(self, dynamic_data: dict, purge_existing: bool = False) -> bool:
911+
"""
912+
Add AddRaster nodes to the XML document based on the provided dynamic data.
913+
purge_existing: If True, existing AddRaster nodes will be removed before
914+
adding new ones.
915+
"""
916+
if dynamic_data is None or len(dynamic_data) == 0 or self.m_doc is None:
917+
self.log("Dynamic data or XML document is not available.", 1)
918+
return False
919+
key = "AR"
920+
add_rasters = dynamic_data.get(key, [])
921+
if not add_rasters:
922+
self.log("No AddRasters data found in dynamic_data.", 1)
923+
return False
924+
parent = self.getXMLNode(self.m_doc, "AddRasters")
925+
clone = self.getXMLNode(self.m_doc, "AddRaster")
926+
if purge_existing:
927+
while parent.hasChildNodes():
928+
parent.removeChild(parent.lastChild)
929+
for item in add_rasters:
930+
cloned = clone.cloneNode(deep=True)
931+
for node_key in item:
932+
node = cloned.getElementsByTagName(node_key)
933+
if 0 == len(node):
934+
self.log(f"Node {item} not found in XML.", 1)
935+
continue
936+
try:
937+
if node[0].firstChild is None: # handles <node/> cases.
938+
node[0].appendChild(self.m_doc.createTextNode(item[node_key]))
939+
node[0].firstChild.nodeValue = item[node_key]
940+
except (IndexError, AttributeError) as e:
941+
self.log(
942+
f"Error occurred while setting node value for {node_key}: {e}",
943+
2,
944+
)
945+
return False # if any error occurs, return False
946+
parent.appendChild(cloned)
947+
return True

0 commit comments

Comments
 (0)