Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BeninSmallHolderCashews: return geospatial metadata in sample #377

Merged
merged 13 commits into from
Feb 24, 2022
5 changes: 4 additions & 1 deletion torchgeo/datasets/benin_cashews.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def __getitem__(self, index: int) -> Dict[str, Tensor]:
index: index to return

Returns:
image, mask, and metadata at that index
image, mask, geotransform, crs and metadata at that index
adamjstewart marked this conversation as resolved.
Show resolved Hide resolved
"""
y, x = self.chips_metadata[index]

Expand All @@ -248,6 +248,8 @@ def __getitem__(self, index: int) -> Dict[str, Tensor]:
"mask": labels,
"x": torch.tensor(x), # type: ignore[attr-defined]
"y": torch.tensor(y), # type: ignore[attr-defined]
"geotransform": self.tile_transform,
adamjstewart marked this conversation as resolved.
Show resolved Hide resolved
"crs": self.crs
}

if self.transforms is not None:
Expand Down Expand Up @@ -343,6 +345,7 @@ def _load_single_scene(self, date: str, bands: Tuple[str, ...]) -> Tensor:
)
with rasterio.open(filepath) as src:
self.tile_transform = src.transform
self.crs = src.crs
calebrob6 marked this conversation as resolved.
Show resolved Hide resolved
array = src.read().astype(np.float32)
img[band_index] = torch.from_numpy(array) # type: ignore[attr-defined]

Expand Down