From b2a35e5408eeeffd2f0ed0610ec877f44d8656b4 Mon Sep 17 00:00:00 2001 From: Gregory Halverson Date: Tue, 5 Nov 2024 14:03:40 -0800 Subject: [PATCH 1/2] point extraction --- rasters/raster.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/rasters/raster.py b/rasters/raster.py index 79e8f8b..4bc1670 100644 --- a/rasters/raster.py +++ b/rasters/raster.py @@ -969,6 +969,12 @@ def bbox(self) -> BBox: def geolocation(self) -> Raster: return self.contain(geometry=self.geometry.geolocation) + def to_point(self, point: Point): + index = self.geometry.index_point(point) + value = self.array[index] + + return value + # @profile def to_grid( self, @@ -1086,7 +1092,7 @@ def to_geolocation( def to_geometry( self, - target_geometry: RasterGeometry, + target_geometry: Union[RasterGeometry, Point], resampling: str = None, search_radius_meters: float = None, kd_tree: KDTree = None, @@ -1117,6 +1123,8 @@ def to_geometry( kd_tree=kd_tree, **kwargs ) + elif isinstance(target_geometry, Point): + return self.to_point(target_geometry) else: raise ValueError(f"unsupported target geometry type: {type(target_geometry)}") From 1bfc63143fe6d5cb2b47ebacb7117e94ae963fa9 Mon Sep 17 00:00:00 2001 From: Gregory Halverson Date: Tue, 5 Nov 2024 15:10:42 -0800 Subject: [PATCH 2/2] working on point extraction --- rasters/raster.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rasters/raster.py b/rasters/raster.py index 4bc1670..62138ae 100644 --- a/rasters/raster.py +++ b/rasters/raster.py @@ -970,6 +970,9 @@ def geolocation(self) -> Raster: return self.contain(geometry=self.geometry.geolocation) def to_point(self, point: Point): + if not self.geometry.intersects(point): + return np.nan + index = self.geometry.index_point(point) value = self.array[index]