{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Example - Convert dataset to raster (GeoTiff)\n", "\n", "Often, it is desirable to take a variable (band) out of your dataset and export it to a raster.\n", "This is possible with the `rio.to_raster()`method. It does most of the work for you so you don't\n", "have to.\n", "\n", "Note: The `rio.to_raster()` method only works on a 2-dimensional or 3-dimensional `xarray.DataArray` or a 2-dimensional `xarray.Dataset`.\n", "\n", "API Reference:\n", "\n", "- DataArray: [rio.to_raster()](../rioxarray.rst#rioxarray.raster_array.RasterArray.to_raster)\n", "- Dataset: [rio.to_raster()](../rioxarray.rst#rioxarray.raster_dataset.RasterDataset.to_raster)\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import rioxarray" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "See docs for [rioxarray.open_rasterio](../rioxarray.rst#rioxarray-open-rasterio)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset>\n", "Dimensions: (time: 2, x: 10, y: 10)\n", "Coordinates:\n", " * time (time) object 2016-12-19 10:27:29.687763 2016-12-29 12:52:42...\n", " * x (x) float64 4.663e+05 4.663e+05 ... 4.663e+05 4.663e+05\n", " * y (y) float64 8.085e+06 8.085e+06 ... 8.085e+06 8.085e+06\n", " spatial_ref int32 0\n", "Data variables:\n", " blue (time, y, x) float64 ...\n", " green (time, y, x) float64 ...\n", "Attributes:\n", " coordinates: spatial_ref