<jupyter_start><jupyter_text>Introduction to GDAL<jupyter_code>%matplotlib inline
import gdal
import numpy as np
import matplotlib.pyplot as plt
dataset = gdal.Open("../data/world.tif")
if dataset is None:
    raise IOError("can't open dataset")
width = dataset.RasterXSize
height = dataset.RasterYSize

print(f"width={width}, height={height}")
bands = dataset.RasterCount
print(f"number of raster bands: {bands}")
data = dataset.ReadAsArray()
rgb = np.dstack((data[0], data[1], data[2])) # put RGB values together
fig = plt.figure(figsize=(15,8))
plt.imshow(rgb)
plt.xticks([]), plt.yticks([]);
data[0].shape
empty = np.zeros((height, width), dtype=np.uint8)
empty.shape
rg = np.dstack((data[0],data[1],empty))
fig = plt.figure(figsize=(15,8))
plt.imshow(rg)
plt.xticks([]), plt.yticks([]);<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1753958587088916, 'fraction_numerical': 0.015834348355663823, 'mean_word_length': 6.754716981132075, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '546725', 'license': 'MIT', 'n_tokens_mistral': 309, 'n_tokens_neox': 307, 'n_words': 65, 'path': 'Chapter3/notebooks/00_GDAL.ipynb', 'repo_name': 'PacktPublishing/Hands-On-Deep-Learning-for-Geospatial-Analysis', 'size': '821'}