From 80a86bcc5999c19ef6dba28c6037a8a3e534857f Mon Sep 17 00:00:00 2001
From: "Laura, Jason R" <jlaura@usgs.gov>
Date: Wed, 28 Feb 2024 11:58:36 -0700
Subject: [PATCH] Adds valid height check for DEM intersection

---
 CHANGELOG.md  | 4 +++-
 knoten/csm.py | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 07c497e..8f7f78b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -36,5 +36,7 @@ release.
 ## Unreleased
 
 ### Changed
-- Removed all `pyproj` calls from csm.py, abstracting them into the reprojection and pyproj.Transformer code inside utils.py. Updated the transformations to use the new pipeline style syntax to avoid deprecation warnings about old syntax.p
+- Removed all `pyproj` calls from csm.py, abstracting them into the reprojection and pyproj.Transformer code inside utils.py. Updated the transformations to use the new pipeline style syntax to avoid deprecation warnings about old syntax.
 
+### Fixed
+- Added a check to `generate_ground_point` when a GeoDataset is used to raise a `ValueError` if the algorithm intersects a no data value in the passed DEM. This ensures that valid heights are used in the intersection computation.
diff --git a/knoten/csm.py b/knoten/csm.py
index ee70314..d951b1f 100644
--- a/knoten/csm.py
+++ b/knoten/csm.py
@@ -170,7 +170,9 @@ def _(dem, image_pt, camera, max_its = 20, tolerance = 0.001):
 
         px, py = dem.latlon_to_pixel(lat, lon)
         height = dem.read_array(1, [px, py, 1, 1])[0][0]
-
+        if height == dem.no_data_value:
+            raise ValueError(f'No DEM height at {lat}, {lon}')
+    
         next_intersection = camera.imageToGround(image_pt, float(height))
         dist = max(abs(intersection.x - next_intersection.x),
             abs(intersection.y - next_intersection.y),
-- 
GitLab