Skip to content

Commit

Permalink
inverse distance weighting point extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
gregory-halverson committed Nov 7, 2024
1 parent 5b5441f commit 23ccd3e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 344 deletions.
361 changes: 21 additions & 340 deletions Open Raster at Point.ipynb

Large diffs are not rendered by default.

25 changes: 21 additions & 4 deletions rasters/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,14 @@ def open(
filename: str,
nodata=None,
remove=None,
geometry: RasterGeometry = None,
geometry: Union[RasterGeometry, Point] = None,
buffer: int = None,
window: Window = None,
resampling: str = None,
cmap: Union[Colormap, str] = None,
**kwargs) -> Raster:
from .point import Point

target_geometry = geometry

if filename.startswith("~"):
Expand All @@ -442,6 +444,9 @@ def open(

source_geometry = RasterGrid.open(filename)

if buffer is None and isinstance(target_geometry, Point):
buffer = 1

if window is None and target_geometry is not None:
window = source_geometry.window(geometry=target_geometry, buffer=buffer)

Expand Down Expand Up @@ -475,12 +480,16 @@ def open(
crs=CRS
)

image = Raster(data, geometry, nodata=nodata, filename=filename, cmap=cmap, **kwargs)
result = Raster(data, geometry, nodata=nodata, filename=filename, cmap=cmap, **kwargs)

if isinstance(target_geometry, RasterGeometry):
image = image.to_geometry(target_geometry, resampling=resampling)
result = result.to_geometry(target_geometry, resampling=resampling)
elif isinstance(target_geometry, Point):
# print(result.array)
# print(result.crs)
result = result.to_point(target_geometry)

return image
return result

@classmethod
def merge(
Expand Down Expand Up @@ -970,7 +979,15 @@ def geolocation(self) -> Raster:
return self.contain(geometry=self.geometry.geolocation)

def to_point(self, point: Point):
# print(f"to_point({point})")
if isinstance(point, shapely.geometry.Point):
point = Point(point, crs=WGS84)

point = point.to_crs(self.crs)
point._crs = self.crs

if not self.geometry.intersects(point):
# print("does not intersect")
return np.nan

index = self.geometry.index_point(point)
Expand Down

0 comments on commit 23ccd3e

Please sign in to comment.