OSM = """<GDAL_WMS>
<Service name="TMS"><ServerUrl>https://tile.openstreetmap.org/${z}/${x}/${y}.png</ServerUrl></Service>
<DataWindow>
<UpperLeftX>-20037508.34</UpperLeftX><UpperLeftY>20037508.34</UpperLeftY>
<LowerRightX>20037508.34</LowerRightX><LowerRightY>-20037508.34</LowerRightY>
<TileLevel>19</TileLevel><TileCountX>1</TileCountX><TileCountY>1</TileCountY>
<YOrigin>top</YOrigin>
</DataWindow>
<Projection>EPSG:3857</Projection>
<BlockSizeX>256</BlockSizeX><BlockSizeY>256</BlockSizeY>
<BandsCount>3</BandsCount>
<UserAgent>gdalxarray-docs (+https://github.com/hypertidy/gdalxarray)</UserAgent>
<MaxConnections>2</MaxConnections>
<Cache><Path>_tilecache/osm</Path></Cache>
</GDAL_WMS>"""Tile services: XYZ, WMTS and WCS
GDAL reads tile services through its WMS, WMTS and WCS drivers. To GDAL a tile service is just a raster, with its zoom levels as overviews. gdalxarray opens it like any other raster, and gdalxarray.warp() puts it on any grid: any CRS, any extent, any resolution. The warp reads only the tiles under the output, from the zoom level that matches the output resolution.
An XYZ service needs only a short XML description: the URL template, the extent of zoom 0, the deepest zoom, and some rules for using the service politely.
UserAgent and MaxConnections follow the OpenStreetMap tile usage policy. Cache keeps every tile on disk, so a later read of the same area makes no requests.
The whole world as one lazy array
- Address:
<GDAL_WMS> <Service name="TMS"><ServerUrl>https://tile.openstreetmap.org/${z}/${x}/${y}.png</ServerUrl></Service> <DataWindow> <UpperLeftX>-20037508.34</UpperLeftX><UpperLeftY>20037508.34</UpperLeftY> <LowerRightX>20037508.34</LowerRightX><LowerRightY>-20037508.34</LowerRightY> <TileLevel>19</TileLevel><TileCountX>1</TileCountX><TileCountY>1</TileCountY> <YOrigin>top</YOrigin> </DataWindow> <Projection>EPSG:3857</Projection> <BlockSizeX>256</BlockSizeX><BlockSizeY>256</BlockSizeY> <BandsCount>3</BandsCount> <UserAgent>gdalxarray-docs (+https://github.com/hypertidy/gdalxarray)</UserAgent> <MaxConnections>2</MaxConnections> <Cache><Path>_tilecache/osm</Path></Cache> </GDAL_WMS> - Provider: OpenStreetMap Foundation
- Permanent: an archive the provider commits to keeping.
- Status: answered the store check at 2026-11-30 01:21 UTC.
Opening the service reads nothing over the network. At zoom 19 the world is 134 million pixels on a side. The x and y coordinates are an affine index, not arrays, so even at that size the open is instant.
if live("osm-xyz"):
world = xr.open_dataset(OSM, engine="gdalxarray", multidim=False)["band_data"]
print(world.shape)(3, 134217728, 134217728)
Don’t pass chunks={} to a raster this size: dask would try to plan one task per tile, for every tile on Earth. Select a window first, or warp.
London on British National Grid
The tiles are Web Mercator. The warp below puts them on the Ordnance Survey grid, at a whole-metre extent and 1 m pixels, in one step.
if live("osm-xyz"):
rec = gdalxarray.warp(OSM, crs="EPSG:27700", bbox=(529800, 179200, 530600, 179800),
resolution=1, resampling="bilinear")
bng = xr.open_dataset(rec, engine="gdalxarray", multidim=False)["band_data"]
print(bng.shape, float(bng.x[0]), float(bng.y[0]))
fig, ax = plt.subplots(figsize=(8, 6))
bng.plot.imshow(ax=ax, rgb="band")
ax.set_aspect("equal")
plt.show()(3, 600, 800) 529800.5 179799.5

The first pixel centre is half a metre in from the corner you asked for. Nothing was snapped to the tile grid.
The resolution picks the zoom
The same source, at 200 m over south-east England. GDAL chooses the overview, that is the zoom level, that fits the output resolution. It fetches a handful of zoom 9 or 10 tiles, not thousands at zoom 19.
if live("osm-xyz"):
rec = gdalxarray.warp(OSM, crs="EPSG:27700", bbox=(450000, 100000, 650000, 230000),
resolution=200, resampling="average")
se = xr.open_dataset(rec, engine="gdalxarray", multidim=False)["band_data"]
fig, ax = plt.subplots(figsize=(8, 5.5))
se.plot.imshow(ax=ax, rgb="band")
ax.set_aspect("equal")
plt.show()
Chips on their local UTM zone
For sample chips, each site can have its own grid. Here each one is in its own UTM zone, centred on whole 10 m, from the one source:
if live("osm-xyz"):
sites = {"Hobart": (147.33, -42.88), "Oslo": (10.75, 59.91),
"Quito": (-78.47, -0.18), "Anchorage": (-149.90, 61.22)}
fig, axs = plt.subplots(1, 4, figsize=(12, 3.4), layout="constrained")
for ax, (name, (lon, lat)) in zip(axs, sites.items()):
epsg = (32700 if lat < 0 else 32600) + int((lon + 180) // 6) + 1
cx, cy = Transformer.from_crs(4326, epsg, always_xy=True).transform(lon, lat)
cx, cy = round(cx, -1), round(cy, -1)
rec = gdalxarray.warp(OSM, crs=f"EPSG:{epsg}", resolution=10,
bbox=(cx - 1280, cy - 1280, cx + 1280, cy + 1280))
chip = xr.open_dataset(rec, engine="gdalxarray", multidim=False)["band_data"]
chip.plot.imshow(ax=ax, rgb="band")
ax.set_title(f"{name}, EPSG:{epsg}"); ax.set_aspect("equal"); ax.set_axis_off()
plt.show()
Each recipe is a VRT string. Save it next to the chip, and the chip can be rebuilt from its source exactly, or rebuilt later at another resolution.
A WMTS on its own tile matrix
- Address:
WMTS:https://cache.kartverket.no/v1/wmts/1.0.0/WMTSCapabilities.xml,layer=topo,tilematrixset=utm33n - Provider: Kartverket (Norwegian Mapping Authority)
- Permanent: an archive the provider commits to keeping.
- Status: answered the store check at 2026-11-30 01:21 UTC.
The WMTS: prefix reads the capabilities document and opens one layer on one tile matrix set. The Norwegian topographic cache is published on UTM zone 33N, but Bergen is in zone 32. The warp moves it there:
dsn = "WMTS:https://cache.kartverket.no/v1/wmts/1.0.0/WMTSCapabilities.xml,layer=topo,tilematrixset=utm33n"
if live("kartverket-wmts"):
topo = xr.open_dataset(dsn, engine="gdalxarray", multidim=False)["band_data"]
print(topo.shape)
cx, cy = Transformer.from_crs(4326, 32632, always_xy=True).transform(5.324, 60.393)
cx, cy = round(cx, -2), round(cy, -2)
rec = gdalxarray.warp(dsn, crs="EPSG:32632", resolution=2,
bbox=(cx - 1500, cy - 1000, cx + 1500, cy + 1000))
bergen = xr.open_dataset(rec, engine="gdalxarray", multidim=False)["band_data"]
fig, ax = plt.subplots(figsize=(8, 5.5))
bergen.isel(band=slice(0, 3)).plot.imshow(ax=ax, rgb="band")
ax.set_aspect("equal")
plt.show()(4, 19122340, 20277434)

Blue Marble onto Antarctica
- Address:
<GDAL_WMS> <Service name="TMS"><ServerUrl>https://gibs.earthdata.nasa.gov/wmts/epsg4326/best/BlueMarble_NextGeneration/default/500m/${z}/${y}/${x}.jpeg</ServerUrl></Service> <DataWindow> <UpperLeftX>-180.0</UpperLeftX><UpperLeftY>90</UpperLeftY> <LowerRightX>396.0</LowerRightX><LowerRightY>-198</LowerRightY> <TileLevel>8</TileLevel><TileCountX>2</TileCountX><TileCountY>1</TileCountY> <YOrigin>top</YOrigin> </DataWindow> <Projection>EPSG:4326</Projection> <BlockSizeX>512</BlockSizeX><BlockSizeY>512</BlockSizeY> <BandsCount>3</BandsCount> <ZeroBlockHttpCodes>400,404</ZeroBlockHttpCodes> <UserAgent>gdalxarray-docs (+https://github.com/hypertidy/gdalxarray)</UserAgent> <Cache><Path>_tilecache/gibs</Path></Cache> </GDAL_WMS> - Provider: NASA GIBS
- Permanent: an archive the provider commits to keeping.
- Status: answered the store check at 2026-11-30 01:21 UTC.
NASA GIBS publishes each layer in several projections. Its geographic tile matrix has two 512-pixel tiles at zoom 0. Warping it to polar stereographic gives a map with no Web Mercator cut-off at 85 degrees.
GIBS = """<GDAL_WMS>
<Service name="TMS"><ServerUrl>https://gibs.earthdata.nasa.gov/wmts/epsg4326/best/BlueMarble_NextGeneration/default/500m/${z}/${y}/${x}.jpeg</ServerUrl></Service>
<DataWindow>
<UpperLeftX>-180.0</UpperLeftX><UpperLeftY>90</UpperLeftY>
<LowerRightX>396.0</LowerRightX><LowerRightY>-198</LowerRightY>
<TileLevel>8</TileLevel><TileCountX>2</TileCountX><TileCountY>1</TileCountY>
<YOrigin>top</YOrigin>
</DataWindow>
<Projection>EPSG:4326</Projection>
<BlockSizeX>512</BlockSizeX><BlockSizeY>512</BlockSizeY>
<BandsCount>3</BandsCount>
<ZeroBlockHttpCodes>400,404</ZeroBlockHttpCodes>
<UserAgent>gdalxarray-docs (+https://github.com/hypertidy/gdalxarray)</UserAgent>
<Cache><Path>_tilecache/gibs</Path></Cache>
</GDAL_WMS>"""if live("gibs-bluemarble-4326"):
rec = gdalxarray.warp(GIBS, crs="EPSG:3031", bbox=(-4e6, -4e6, 4e6, 4e6),
resolution=8000, resampling="average")
ant = xr.open_dataset(rec, engine="gdalxarray", multidim=False)["band_data"]
fig, ax = plt.subplots(figsize=(7, 7))
ant.plot.imshow(ax=ax, rgb="band")
ax.set_aspect("equal")
plt.show()--------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) Cell In[15], line 6 2 rec = gdalxarray.warp(GIBS, crs="EPSG:3031", bbox=(-4e6, -4e6, 4e6, 4e6), 3 resolution=8000, resampling="average") 4 ant = xr.open_dataset(rec, engine="gdalxarray", multidim=False)["band_data"] 5 fig, ax = plt.subplots(figsize=(7, 7)) ----> 6 ant.plot.imshow(ax=ax, rgb="band") 7 ax.set_aspect("equal") 8 plt.show() File /opt/gdal-py/lib/python3.14/site-packages/xarray/plot/accessor.py:421, in DataArrayPlotAccessor.imshow(self, *args, **kwargs) 419 @functools.wraps(dataarray_plot.imshow, assigned=("__doc__",)) 420 def imshow(self, *args, **kwargs) -> AxesImage | FacetGrid[DataArray]: --> 421 return dataarray_plot.imshow(self._da, *args, **kwargs) File /opt/gdal-py/lib/python3.14/site-packages/xarray/plot/dataarray_plot.py:1580, in _plot2d.<locals>.newplotfunc(***failed resolving arguments***) 1577 yvalnp = yval.to_numpy() 1579 # Pass the data as a masked ndarray too -> 1580 zval = darray.to_masked_array(copy=False) 1582 # Replace pd.Intervals if contained in xval or yval. 1583 xplt, xlab_extra = _resolve_intervals_2dplot(xvalnp, plotfunc.__name__) File /opt/gdal-py/lib/python3.14/site-packages/xarray/core/dataarray.py:4065, in DataArray.to_masked_array(self, copy) 4051 def to_masked_array(self, copy: bool = True) -> np.ma.MaskedArray: 4052 """Convert this array into a numpy.ma.MaskedArray 4053 4054 Parameters (...) 4063 Masked where invalid values (nan or inf) occur. 4064 """ -> 4065 values = self.to_numpy() # only compute lazy arrays once 4066 isnull = pd.isnull(values) 4067 return np.ma.MaskedArray(data=values, mask=isnull, copy=copy) File /opt/gdal-py/lib/python3.14/site-packages/xarray/core/dataarray.py:820, in DataArray.to_numpy(self) 809 def to_numpy(self) -> np.ndarray: 810 """ 811 Coerces wrapped data to numpy and returns a numpy.ndarray. 812 (...) 818 DataArray.data 819 """ --> 820 return self.variable.to_numpy() File /opt/gdal-py/lib/python3.14/site-packages/xarray/namedarray/core.py:869, in NamedArray.to_numpy(self) 867 """Coerces wrapped data to numpy and returns a numpy.ndarray""" 868 # TODO an entrypoint so array libraries can choose coercion method? --> 869 return to_numpy(self._data) File /opt/gdal-py/lib/python3.14/site-packages/xarray/namedarray/pycompat.py:112, in to_numpy(data, **kwargs) 109 pass 111 if isinstance(data, ExplicitlyIndexed): --> 112 data = data.get_duck_array() # type: ignore[no-untyped-call] 114 # TODO first attempt to call .to_numpy() once some libraries implement it 115 if is_chunked_array(data): File /opt/gdal-py/lib/python3.14/site-packages/xarray/core/indexing.py:852, in LazilyVectorizedIndexedArray.get_duck_array(self) 849 from xarray.backends.common import BackendArray 851 if isinstance(self.array, BackendArray): --> 852 array = self.array[self.key] 853 else: 854 array = apply_indexer(self.array, self.key) File /__w/gdalxarray/gdalxarray/gdalxarray/backend.py:579, in GDALMultiBandArray.__getitem__(self, key) 577 if not isinstance(key, indexing.ExplicitIndexer): 578 key = indexing.BasicIndexer(key if isinstance(key, tuple) else (key,)) --> 579 return indexing.explicit_indexing_adapter( 580 key, 581 self.shape, 582 indexing.IndexingSupport.BASIC, 583 self._raw_indexing_method, 584 ) File /opt/gdal-py/lib/python3.14/site-packages/xarray/core/indexing.py:1162, in explicit_indexing_adapter(key, shape, indexing_support, raw_indexing_method) 1140 """Support explicit indexing by delegating to a raw indexing method. 1141 1142 Outer and/or vectorized indexers are supported by indexing a second time (...) 1159 Indexing result, in the form of a duck numpy-array. 1160 """ 1161 raw_key, numpy_indices = decompose_indexer(key, shape, indexing_support) -> 1162 result = raw_indexing_method(raw_key.tuple) 1163 if numpy_indices.tuple: 1164 # index the loaded duck array 1165 indexable = as_indexable(result) File /__w/gdalxarray/gdalxarray/gdalxarray/backend.py:647, in GDALMultiBandArray._raw_indexing_method(self, key) 645 with _gdal_config_context(self._config_options): 646 ds = self._get_dataset() --> 647 data = ds.ReadAsArray( 648 xoff=x0, 649 yoff=y0, 650 xsize=nx, 651 ysize=ny, 652 band_list=band_list, 653 ) 655 # ReadAsArray returns 2D for a single band, 3D for multiple - normalise 656 if data.ndim == 2: File /opt/gdal-py/lib/python3.14/site-packages/osgeo/gdal.py:6695, in Dataset.ReadAsArray(self, xoff, yoff, xsize, ysize, buf_obj, buf_xsize, buf_ysize, buf_type, resample_alg, operate_in_buf_type, callback, callback_data, interleave, band_list) 6691 [12, 13, 14, 15]]], dtype=uint8) 6692 """ 6693 6694 from osgeo import gdal_array -> 6695 return gdal_array.DatasetReadAsArray(self, xoff, yoff, xsize, ysize, buf_obj, 6696 buf_xsize, buf_ysize, buf_type, 6697 resample_alg=resample_alg, 6698 operate_in_buf_type=operate_in_buf_type, File /opt/gdal-py/lib/python3.14/site-packages/osgeo/gdal_array.py:508, in DatasetReadAsArray(ds, xoff, yoff, win_xsize, win_ysize, buf_obj, buf_xsize, buf_ysize, buf_type, resample_alg, operate_in_buf_type, callback, callback_data, interleave, band_list) 505 raise ValueError("Specified buf_type not consistent with array type") 506 buf_type = datatype --> 508 if DatasetIONumPy(ds, 0, xoff, yoff, win_xsize, win_ysize, 509 buf_obj, buf_type, resample_alg, 510 operate_in_buf_type, 511 callback, callback_data, 512 interleave, band_list) != 0: 513 _RaiseException() 514 return None File /opt/gdal-py/lib/python3.14/site-packages/osgeo/gdal_array.py:270, in DatasetIONumPy(ds, bWrite, xoff, yoff, xsize, ysize, psArray, buf_type, resample_alg, operate_in_buf_type, callback, callback_data, binterleave, band_list) 268 def DatasetIONumPy(ds, bWrite, xoff, yoff, xsize, ysize, psArray, buf_type, resample_alg, operate_in_buf_type, callback=0, callback_data=None, binterleave=True, band_list=0): 269 r"""DatasetIONumPy(Dataset ds, int bWrite, double xoff, double yoff, double xsize, double ysize, PyArrayObject * psArray, GDALDataType buf_type, GDALRIOResampleAlg resample_alg, int operate_in_buf_type, GDALProgressFunc callback=0, void * callback_data=None, bool binterleave=True, int band_list=0) -> CPLErr""" --> 270 return _gdal_array.DatasetIONumPy(ds, bWrite, xoff, yoff, xsize, ysize, psArray, buf_type, resample_alg, operate_in_buf_type, callback, callback_data, binterleave, band_list) RuntimeError: GDALWMS: Unable to open downloaded block. [...] May be caused by: _tilecache/gibs/39320b16299fb77e2774d1428d58ada9/1/f/1fb090ca580416f0b4e8055c1ae25f7f: No such file or directory May be caused by: PROJ: stere: Invalid latitude May be caused by: PROJ: stere: Invalid latitude May be caused by: PROJ: stere: Invalid latitude May be caused by: PROJ: stere: Invalid latitude May be caused by: PROJ: stere: Invalid latitude May be caused by: PROJ: stere: Invalid latitude May be caused by: PROJ: stere: I

A numerical coverage over WCS
- Address:
WCS:https://environment.data.gov.uk/spatialdata/lidar-composite-digital-terrain-model-dtm-1m/wcs?version=2.0.1&coverage=13787b9a-26a4-4775-8523-806d13af58fc__Lidar_Composite_Elevation_DTM_1m - Provider: Environment Agency (England)
- Permanent: an archive the provider commits to keeping.
- Status: answered the store check at 2026-11-30 01:21 UTC.
A WCS returns values, not pictures. The WCS: prefix opens a coverage; here it is England’s 1 m LiDAR composite terrain model. The warp puts it on a 2 m grid in the Lake District, and the result can be used for analysis (here, hillshade):
dsn = ("WCS:https://environment.data.gov.uk/spatialdata/lidar-composite-digital-terrain-model-dtm-1m/wcs"
"?version=2.0.1&coverage=13787b9a-26a4-4775-8523-806d13af58fc__Lidar_Composite_Elevation_DTM_1m")
if live("ea-lidar-wcs"):
rec = gdalxarray.warp(dsn, crs="EPSG:27700", bbox=(320000, 505000, 324000, 509000),
resolution=2, resampling="bilinear", nodata=-9999)
dtm = xr.open_dataset(rec, engine="gdalxarray", multidim=False)["band_data"].isel(band=0)
dtm = dtm.where(dtm > -9999)
dzdy, dzdx = np.gradient(dtm.values, -2.0, 2.0) # rows run north to south
az, alt = np.radians(315), np.radians(45) # light from the north-west
slope = np.arctan(np.hypot(dzdx, dzdy))
aspect = np.arctan2(-dzdx, dzdy)
shade = np.sin(alt) * np.cos(slope) + np.cos(alt) * np.sin(slope) * np.cos(az - aspect)
fig, ax = plt.subplots(figsize=(7, 6))
dtm.plot(ax=ax, cmap="gist_earth", cbar_kwargs={"label": "elevation (m)"})
ax.imshow(shade, cmap="gray", alpha=0.35,
extent=(float(dtm.x[0]), float(dtm.x[-1]), float(dtm.y[-1]), float(dtm.y[0])))
ax.set_aspect("equal")
plt.show()
Using a service politely
Being polite is the caller’s job, and GDAL has the settings for it:
| Setting | Where | Effect |
|---|---|---|
<UserAgent> |
WMS XML | identifies you; some hosts refuse requests without one |
<MaxConnections> |
WMS XML | concurrent requests to the host (default 2) |
<Cache><Path> |
WMS XML | tiles kept on disk and reused |
GDAL_HTTP_MAX_RETRY, GDAL_HTTP_RETRY_DELAY |
config option | retries on 429 and 5xx |
GDAL_HTTP_USERAGENT, GDAL_HTTP_HEADERS |
config option | the same, for WMTS: and WCS: sources |
With dask, keep the band dimension in one chunk (chunks={"band": -1, "x": 1024, "y": 1024}). Otherwise each band chunk fetches the same tiles again. Tiles on the seams between chunks are also fetched once per chunk; the cache absorbs those.