|
1 | 1 | # ------------------------------------------------------------------------------ |
2 | | -# Copyright 2025 Esri |
| 2 | +# Copyright 2026 Esri |
3 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
4 | 4 | # you may not use this file except in compliance with the License. |
5 | 5 | # You may obtain a copy of the License at |
|
14 | 14 | # ------------------------------------------------------------------------------ |
15 | 15 | # Name: Base.py |
16 | 16 | # Description: Base class used by MDCS/All Raster Solutions components. |
17 | | -# Version: 20250220 |
| 17 | +# Version: 20260708 |
18 | 18 | # Requirements: ArcGIS 10.1 SP1 |
19 | 19 | # Author: Esri Imagery Workflows team |
20 | 20 | # ------------------------------------------------------------------------------ |
@@ -906,3 +906,42 @@ def _is_builtin_event(self, fnc_name: str): |
906 | 906 | if fnc_name is None: |
907 | 907 | return False |
908 | 908 | 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