Rasterio provides fast and direct raster I/O for use with NumPy, built on top of GDAL. It's a fundamental library for reading, writing, and manipulating geospatial raster data in Python. Rasterio typically releases new versions in response to GDAL updates and Python version changes, with minor releases for bug fixes and new features.
pip install rasterioVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to open a raster dataset, access its metadata (profile, CRS, bounds), and read a specific band into a NumPy array. A dummy GeoTIFF is created for standalone execution.
Ensure your environment meets these new minimums before upgrading to 1.5.0. If unable to upgrade dependencies, use an older Rasterio version (e.g., 1.4.x) that aligns with your environment.
Consult the official Rasterio and GDAL documentation for platform-specific installation instructions (e.g., `conda install -c conda-forge rasterio`). Pre-built wheels for Rasterio often bundle GDAL, but direct system-level GDAL installation might be required for certain features or environments.
Upgrade to Rasterio 1.4.3 or newer to resolve erroneous masking and ensure consistent `reproject()` output. Always test masking and reprojection carefully when using older versions.
Upgrade to Rasterio 1.4.3+ to receive a `TypeError` instead of a crash. Always ensure you are passing a file path or URL string, not an already open `rasterio.DatasetReader` object, to `rasterio.open()`.
Install GDAL development libraries appropriate for your operating system (e.g., `sudo apt-get install libgdal-dev` on Linux, `brew install gdal` on macOS, or OSGeo4W on Windows) before attempting `pip install rasterio`. Alternatively, use `conda install -c conda-forge rasterio` for easier dependency management.
Verify the integrity of the raster file, ensure it's a valid geospatial raster, and check if the GDAL installation linked with Rasterio supports the specific file format and compression used. Try opening the file with `gdalinfo` or another GIS software to confirm its validity.
Provide a valid CRS definition using a standard format such as an EPSG code (e.g., `CRS.from_epsg(4326)`), a well-formed WKT string, or a `pyproj.CRS` object.
Always include the `crs` and `transform` arguments when opening a new dataset in write mode (`'w'`), typically derived from an existing dataset or explicitly defined, for example: `with rasterio.open('output.tif', 'w', driver='GTiff', height=array.shape[0], width=array.shape[1], count=1, dtype=array.dtype, crs=source_dataset.crs, transform=source_dataset.transform) as dst:`