Skip to content

Commit

Permalink
Set CRS only after it is no longer None
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjstewart committed Aug 13, 2021
1 parent 1dd8ce8 commit 085d90e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions torchgeo/datasets/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def _merge_files(self, filepaths: Sequence[str], query: BoundingBox) -> Tensor:

# Merge files
bounds = (query.minx, query.miny, query.maxx, query.maxy)
dest, _ = rasterio.merge.merge(vrt_fhs, bounds, self.res, nodata=0)
dest, _ = rasterio.merge.merge(vrt_fhs, bounds, self.res)
dest = dest.astype(np.int32)

# Close file handles
Expand Down Expand Up @@ -399,7 +399,6 @@ def __init__(
super().__init__(transforms)

self.root = root
self.crs = crs
self.res = res

# Populate the dataset index
Expand All @@ -408,12 +407,12 @@ def __init__(
for filepath in glob.iglob(pathname, recursive=True):
try:
with fiona.open(filepath) as src:
if self.crs is None:
self.crs = CRS.from_dict(src.crs)
if crs is None:
crs = CRS.from_dict(src.crs)

minx, miny, maxx, maxy = src.bounds
(minx, maxx), (miny, maxy) = fiona.transform.transform(
src.crs, self.crs.to_dict(), [minx, maxx], [miny, maxy]
src.crs, crs.to_dict(), [minx, maxx], [miny, maxy]
)
except (fiona.errors.DriverError, fiona.errors.FionaValueError):
# Skip files that fiona is unable to read
Expand All @@ -430,6 +429,8 @@ def __init__(
f"No {self.__class__.__name__} data was found in '{root}'"
)

self.crs = crs

def __getitem__(self, query: BoundingBox) -> Dict[str, Any]:
"""Retrieve image/mask and metadata indexed by query.
Expand Down

0 comments on commit 085d90e

Please sign in to comment.