Skip to content

Commit

Permalink
fixing MultiRaster reprojection
Browse files Browse the repository at this point in the history
  • Loading branch information
gregory-halverson committed Jan 3, 2025
1 parent d7a585b commit 2351dd7
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "rasters"
version = "1.4.2"
version = "1.4.3"
description = "raster processing toolkit"
readme = "README.md"
authors = [
Expand Down
21 changes: 21 additions & 0 deletions rasters/multi_raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,27 @@ def __init__(
self.cmap = cmap
self._source_metadata = {}

def contain(self, array=None, geometry=None, nodata=None) -> Raster:
if array is None:
array = self.array

if geometry is None:
geometry = self.geometry

if np.size(array) == 1:
return array

if nodata is None:
nodata = self.nodata

return MultiRaster(
array,
nodata=nodata,
metadata=self.metadata,
cmap=self.cmap,
geometry=geometry
)

@classmethod
def stack(cls, rasters: List[Raster], *args, **kwargs) -> MultiRaster:
geometry = rasters[0].geometry
Expand Down
46 changes: 27 additions & 19 deletions rasters/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,25 +532,33 @@ def contain(self, array=None, geometry=None, nodata=None) -> Raster:
if nodata is None:
nodata = self.nodata

# try:
if len(array.shape) == 2:
return Raster(
array,
nodata=nodata,
metadata=self.metadata,
cmap=self.cmap,
geometry=geometry
)
elif len(array.shape) == 3:
return MultiRaster(
array,
nodata=nodata,
metadata=self.metadata,
cmap=self.cmap,
geometry=geometry
)
else:
raise ValueError(f"invalid raster array with shape {array.shape}")
return Raster(
array,
nodata=nodata,
metadata=self.metadata,
cmap=self.cmap,
geometry=geometry
)

# # try:
# if len(array.shape) == 2:
# return Raster(
# array,
# nodata=nodata,
# metadata=self.metadata,
# cmap=self.cmap,
# geometry=geometry
# )
# elif len(array.shape) == 3:
# return MultiRaster(
# array,
# nodata=nodata,
# metadata=self.metadata,
# cmap=self.cmap,
# geometry=geometry
# )
# else:
# raise ValueError(f"invalid raster array with shape {array.shape}")
# except Exception as e:
# return array

Expand Down
2 changes: 1 addition & 1 deletion rasters/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.4.2
1.4.3

0 comments on commit 2351dd7

Please sign in to comment.