Skip to content

Commit

Permalink
Check import of rasterio sort_xy function
Browse files Browse the repository at this point in the history
  • Loading branch information
rantolin committed Oct 31, 2024
1 parent 5778b4c commit 135ae31
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions raster_loader/io/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import rio_cogeo
import rasterio
import quadbin
from rasterio.sample import sort_xy

from raster_loader.geo import raster_bounds
from raster_loader.errors import (
Expand Down Expand Up @@ -404,7 +403,12 @@ def not_enough_samples():
x = rng.uniform(west, east, n_samples)
y = rng.uniform(south, north, n_samples)

coords = sort_xy(zip(x, y))
try:
from rasterio.sample import sort_xy
except ImportError:
coords = zip(x, y)
else:
coords = sort_xy(zip(x, y))

samples = raster_dataset.sample(coords, indexes=bands, masked=True)
for sample in samples:
Expand Down

0 comments on commit 135ae31

Please sign in to comment.