Datatype : GeoTIFF#

GeoTIFF files are image files format having additional spatial information embedded in the .tiff file as tags. It includes metadata like CRS, Resolution, Spatial extent, etc along with the pixel values.#

In this example we are using Belize-BioClim30s_Temperature.tif file.

The recommended method to open a geoTIFF file on a python notebook is by downloading and installing GDAL. The link can be found here. Make sure the GDAL version matches your python version. If you have python 3.8, procced to download GDAL-3.1.4-cp38-cp38m-win_amd64.whl, where cp38 stands for python3.8.

Next, download and install raster from here. Download the correct version that matches your python version.

Make sure you have the geoTIFF file, the previously downloaded GDAL and rasterio file in the same folder. Copy the path file and open it in your terminal. Run the following commands to install GDAL and rasterio. Run the following commands to install GDAL and rasterio respectively:

pip install GDAL-3.4.1-cp38-cp38-win_amd64.whl
pip install rasterio-1.2.10-cp38-cp38-win_amd64.whl

Make sure the version matches with the file that you have downloaded.

Follow the steps to view the geoTIFF file:

  1. Import rasterio and rasterio.plot

import rasterio as rs
from rasterio.plot import show
  1. Store the geoTIFF file in a variable, use the rs.open() and show() functions to open view the image in the next cell.

fp = r'Belize-BioClim30s_Temperature.tif'
img = rs.open(fp)
show(img)
../../../_images/d672a22cb57779846787b31fe5b190b2e1b538482627782cd2a6de7c032f459e.png
<AxesSubplot:>

The x and the y-axis represent the longitude and latitude values.

To extract the image related data with rasterIO, use the following commands:

#No. of bands
print(img.count)

#Image resolution
print(img.height, img.width)

# CRS
print(img.crs)
1
314 135
EPSG:4326