Skip to content

xr.concat fails with RasterIndex when slices wrap around array boundary #89

@dcherian

Description

@dcherian

Description

xr.concat fails with ValueError: X offsets are incompatible when concatenating two subsets of a RasterIndex-indexed dataset that wrap around the array boundary (e.g., tail + head slices from a global EPSG:4326 raster).

Minimal reproducer

import rasterix
import numpy as np
import xarray as xr
from pyproj import CRS

nx, ny = 100, 100

ds = xr.Dataset({"foo": (("x", "y"), np.ones((nx, ny)))})
ds.coords["spatial_ref"] = ((), 0, CRS.from_epsg(4326).to_cf())
ds.spatial_ref.attrs["GeoTransform"] = "-181.8 3.6 0.0 90.9 0.0 -1.8"

ds = rasterix.assign_index(ds, x_dim="x", y_dim="y")

a = ds.isel(x=slice(-2, None))  # last 2 rows (x: [172.8, 176.4])
b = ds.isel(x=slice(0, 52))     # first 52 rows (x: [-180.0, ..., 3.6])

xr.concat([a, b], dim="x")

Error

ValueError: X offsets are incompatible. Provided offsets (171.0, -181.8), expected offsets: (171.0, 178.2)

Context

This comes up when rendering map tiles from a global lat/lon raster dataset. Tiles near the edges require padding that wraps around the array boundary, producing two slices (tail + head) that need to be concatenated. The RasterIndex concat logic expects contiguous offsets and rejects the wrap-around case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions