{"id":4238,"library":"rioxarray","title":"Rioxarray","description":"Rioxarray is an open-source Python library that extends xarray with geospatial capabilities, powered by rasterio. It provides a `.rio` accessor for xarray DataArrays and Datasets, enabling easy manipulation, reprojecting, and analysis of geospatial raster data. It is actively maintained with regular releases, typically following `xarray` and `rasterio` updates.","status":"active","version":"0.22.0","language":"en","source_language":"en","source_url":"https://github.com/corteva/rioxarray","tags":["geospatial","xarray","raster","GIS","rasterio","earth-science","remote-sensing"],"install":[{"cmd":"pip install rioxarray","lang":"bash","label":"Default Install"},{"cmd":"pip install 'rioxarray[tools]' # For CLI tools, requires GDAL","lang":"bash","label":"With CLI Tools"}],"dependencies":[{"reason":"Core data structure for labeled arrays, which rioxarray extends.","package":"xarray"},{"reason":"Backend for reading, writing, and manipulating geospatial raster data.","package":"rasterio"},{"reason":"Required for Coordinate Reference System (CRS) transformations like `da.rio.reproject()`. Often installed automatically with `rasterio`.","package":"pyproj","optional":true},{"reason":"Enables out-of-core and parallel processing for large datasets.","package":"dask","optional":true}],"imports":[{"note":"Importing `rioxarray` activates the `.rio` accessor on `xarray.DataArray` and `xarray.Dataset` objects. You don't typically import specific classes or functions directly from `rioxarray` for most common use cases.","symbol":"rioxarray","correct":"import rioxarray"}],"quickstart":{"code":"import xarray as xr\nimport rioxarray # Enables the .rio accessor\nimport numpy as np\n\n# Create a dummy DataArray for demonstration\n# In a real scenario, you'd typically open a GeoTIFF like this:\n# da = xr.open_dataarray(\"path/to/your/file.tif\", engine=\"rasterio\")\n\n# Dummy data: a 2x2 grid representing a small geographic area\ndata = np.array([[10.1, 20.2], [30.3, 40.4]], dtype=np.float32)\ncoords = {\n    \"y\": [45.5, 45.0],  # Example latitude (y-coordinate, usually decreasing)\n    \"x\": [-120.0, -119.5], # Example longitude (x-coordinate, usually increasing)\n}\nda = xr.DataArray(data, coords=coords, dims=(\"y\", \"x\"), name=\"temperature\")\n\n# Assign geospatial metadata using the .rio accessor\n# These properties are typically inferred automatically when opening a geospatial file.\nda = da.rio.write_crs(\"EPSG:4326\") # WGS84 Geographic CRS\nda = da.rio.set_spatial_dims(x_dim=\"x\", y_dim=\"y\") # Explicitly set spatial dimensions\n\nprint(f\"Original CRS: {da.rio.crs}\")\nprint(f\"Original Bounds: {da.rio.bounds()}\")\nprint(f\"Original Resolution: {da.rio.resolution()}\")\nprint(f\"Original Width: {da.rio.width}\")\nprint(f\"Original Height: {da.rio.height}\")\n\n# Example of a common operation: Reproject to a different CRS\n# Note: This operation requires 'pyproj' to be installed. Some systems \n# might also need GDAL for full functionality and performance.\n# try:\n#     # Reproject to Web Mercator (EPSG:3857)\n#     reprojected_da = da.rio.reproject(\"EPSG:3857\")\n#     print(f\"\\nReprojected CRS: {reprojected_da.rio.crs}\")\n#     print(f\"Reprojected Bounds: {reprojected_da.rio.bounds()}\")\n#     print(f\"Reprojected Resolution: {reprojected_da.rio.resolution()}\")\n# except ImportError:\n#     print(\"\\nSkipping reprojection: 'pyproj' not installed. Install with 'pip install pyproj'.\")\n# except Exception as e:\n#     print(f\"\\nCould not reproject: {e}\")\n","lang":"python","description":"Demonstrates how to create a simple xarray DataArray, assign geospatial metadata using the `.rio` accessor, and retrieve basic spatial properties like CRS, bounds, and resolution. It also includes a commented-out example of reprojection, a common geospatial operation."},"warnings":[{"fix":"Always ensure your DataArray has a CRS set. When opening files, use `xr.open_dataarray(..., engine='rasterio')` to infer it. For in-memory arrays or when modifying, use `da.rio.write_crs(crs_string_or_object)`.","message":"Many `.rio` operations (e.g., `reproject`, `bounds`, `resolution`) explicitly require a Coordinate Reference System (CRS) to be set on the DataArray. If the CRS is missing, these operations will raise an error.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Instead of modifying, create a new `CRS` object or use `da.rio.write_crs()` to completely replace the CRS. For example, `new_crs = rasterio.crs.CRS.from_epsg(4326)` then `da.rio.write_crs(new_crs)`.","message":"The `rasterio.crs.CRS` object, which `rioxarray` uses, became immutable in `rasterio` version 1.2.x (a dependency for `rioxarray >= 0.20.0`). This means direct in-place modification of CRS attributes (e.g., `da.rio.crs['init'] = 'epsg:4326'`) will now raise an error.","severity":"breaking","affected_versions":"rioxarray >= 0.20.0 (due to rasterio >= 1.2.0)"},{"fix":"Explicitly set and manage nodata values using `da.rio.write_nodata()` or `da.rio.update_attrs(nodata=...)` for consistency. Be mindful of `NaN` values introduced by transformations and handle them appropriately.","message":"There can be nuances in handling `_FillValue` from NetCDF/HDF and `nodata` from GeoTIFFs. `rioxarray` attempts to unify these under `da.rio.nodata`, but inconsistencies or unexpected behavior can arise, especially when merging datasets or after reprojection where new `NaN` values might be introduced.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Replace `da.rio.set_crs(...)` with `da.rio.write_crs(...)`.","message":"The `da.rio.set_crs()` method is deprecated. While it may still function in current versions, it is recommended to use `da.rio.write_crs()` for better clarity and future compatibility.","severity":"deprecated","affected_versions":"rioxarray >= 0.19.0"},{"fix":"Always specify `engine='rasterio'` (e.g., `xr.open_dataarray('file.nc', engine='rasterio')`) when you intend `rioxarray` to handle the geospatial interpretation of a file.","message":"When opening non-geospatial-specific file formats (e.g., generic NetCDF, HDF files without explicit geospatial metadata), you must explicitly specify `engine='rasterio'` with `xr.open_dataarray` or `xr.open_dataset` for `rioxarray` to process them. Otherwise, `xarray`'s default engine will be used, and the `.rio` accessor might not be available or fully functional.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}