-
Expected behavior and actual behavior.I expected
Steps to reproduce the problem.The intent was to project one Landsat raster dataset (from Landsat 9) to match another (from Landsat 8). The data were downloaded from USGS Earth Explorer. filename1 = f'{LANDSAT_DIR}/LC08_L2SP_015033_20220601_20220609_02_T1_SR_B4.TIF'
filename2 = f'{LANDSAT_DIR}/LC09_L2SP_015033_20220625_20230409_02_T1_SR_B4.TIF'
# Both files have the same CRS but different affine transformations
ref_ds = rio.open(filename1) # File I want to match
target_ds = rio.open(filename2) # File I want to change to match the other
original_transform = target_ds.transform
red = target_ds.read(1)
source = rio.open(
'', 'w+', driver = 'MEM', crs = ref_ds.crs, transform = original_transform,
width = red.shape[1], height = red.shape[0], count = 1, dtype = np.float32)
destination = rio.open(
'', 'w+', driver = 'MEM', crs = ref_ds.crs, transform = ref_ds.transform,
width = ref_ds.width, height = ref_ds.height, count = 1, dtype = np.float32)
# To facilitate a minimal working example... I'm actually doing a lot to the array
# before writing it into the "source" dataset
source.write(red, 1)
reproject(
source = rio.band(source, 1),
destination = rio.band(destination, 1),
method = Resampling.nearest)
red_proj = destination.read(1) Environment Information
Installation MethodWithin a virtual environment: pip install rasterio |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
It will be helpful if you have a link to these two files or files that are similar. The error seems to be raised from inside GDAL. Does the error occur with other resampling methods? What are the CRS and transforms for these two files? |
Beta Was this translation helpful? Give feedback.
-
The two Landsat files can be downloaded here and here. The error does occur with bilinear resampling as well. >>> ref_ds.transform
Affine(30.0, 0.0, 220485.0,
0.0, -30.0, 4426815.0)
>>> target_ds.transform
Affine(30.0, 0.0, 215985.0,
0.0, -30.0, 4426515.0)
>>> ref_ds.crs
CRS.from_epsg(32618)
>>> target_ds.crs
CRS.from_epsg(32618) |
Beta Was this translation helpful? Give feedback.
-
I've moved this to a discussion because it looks like a usage question to me. @arthur-e what is your intent with |
Beta Was this translation helpful? Give feedback.
-
I write data to # To facilitate a minimal working example... I'm actually doing a lot to the array
# before writing it into the "source" dataset
source.write(red, 1) Which is prior to calling |
Beta Was this translation helpful? Give feedback.
I write data to
source
on this line:Which is prior to calling
reproject()
, so I would expect that there are source data to work with. But perhaps I am missing a step to "flush" the cache or something like that?