From 37e176d7114fc5ca3bb6fa7d0baa1a6903aa3b04 Mon Sep 17 00:00:00 2001
From: Trygve Leithe Svalheim <tlsvalheim@gmail.com>
Date: Tue, 25 Feb 2025 10:45:37 +0100
Subject: [PATCH] Allow Negative Target Height in Viewshed Analysis
 (viewshed.py)

Description:

This pull request introduces support for negative target heights in the viewshed function. The modification ensures that target points can have a decreased z-value, which is particularly useful for cases where visibility analysis needs to account for building facades rather than rooftops.

Reason for Change:

When using the library for viewshed analysis from an observer in a tall building, the function primarily returns visible points on rooftops rather than building facades. Allowing negative target heights makes it possible to adjust the z-value of the target point while keeping all other points treated normally, improving accuracy in urban visibility studies.
---
 xrspatial/viewshed.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xrspatial/viewshed.py b/xrspatial/viewshed.py
index 2af02077..0f3adea7 100644
--- a/xrspatial/viewshed.py
+++ b/xrspatial/viewshed.py
@@ -1538,7 +1538,7 @@ def _viewshed_cpu(
     viewpoint_col = x_view
     viewpoint_elev = raster.values[y_view, x_view] + observer_elev
     viewpoint_target = 0.0
-    if target_elev > 0:
+    if abs(target_elev) > 0:
         viewpoint_target = target_elev
 
     # int getgrdhead(FILE * fd, struct Cell_head *cellhd)