Skip to main content
Open navigation menu
Close suggestions
Search
Search
en
Change Language, English
Upload
Sign in
Sign in
100%
(1)
100% found this document useful (1 vote)
31 views
5 pages
Chapter 1 Exploring Rasterio
Uploaded by
Ha
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save Chapter 1 Exploring Rasterio For Later
Share
100%
100% found this document useful, Mark this document as useful
0%
0% found this document not useful, Mark this document as not useful
Print
Embed
Report
100%
(1)
100% found this document useful (1 vote)
31 views
5 pages
Chapter 1 Exploring Rasterio
Uploaded by
Ha
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Go to previous items
Download
Save
Save Chapter 1 Exploring Rasterio For Later
Share
100%
100% found this document useful, Mark this document as useful
0%
0% found this document not useful, Mark this document as not useful
Print
Embed
Report
Go to next items
Download
Patrick Gray ([Link] at duke) - [Link] Chapter 1: Exploring rasterio Introduction GDAL - the Geospatial Data Abstraction Library isa software library for reading and writing raster and vector geospatial data formats and forms the basis of most software for processing geospatial data. There are many formats for using GDAL ranging from graphical tools like ArcGIS or QGIS te command line GDAL tools but here we're using the fantastic rasterio python package which provides a pythonic wrapping around GDAL. Basically it reads and writes geospatial formats anc provides a Python API based on numpy N-dimensional arrays and GeoJSON f you're coming from another language and want an overview of object oriented programming in Python, see the python like you meant it short online course Module import in Python Before we can get started, we need to tell Python that we will be using functions, classes, and variables from some packages. The technical wording for this is that we need to import these modules into our namespace (see Python's documentation on the module system here). We will do this using some import statements import rasterio # import the main rasterio function import matplotlib # matplotlib is the primary python plotting and viz Library # this bit of magic allows matplotlib to plot inline in a jupyter notebook Xmatplotlib inline "_version_" # We can check which version we're running by printing the variable print("rasterio's version is: " + rasterio.__version_) print(rasterio) rasterio's version is: 1.2.3 Once we import these packages Python will know where to look on our system for the code that implements them, When we want to access classes, variables, or functions within these packages, we will need to reference the full path (e.g, [Link]() } Examples Open an imageWhen we open an image in rasterio we create a Dataset object. As the name would suggest, we car open an image with the “open’ function within rasterio . We will use an example image provided in the data directory for this chapter. This image is a subset ofa Landsat 7 image containing the 8 bands on this sensor rearranged in order of wavelength (e.g, Landsat 7's second SWIR channel comes before thermal channel in our stack). The last band in this image is a cloud and cloud shadow mask from Fmask # filepath to our image img_fp = ‘../data/LE7@220492002106EDC00_stack.gtif # Open a geospatial dataset dataset = [Link](img_ fp) print (dataset) Now that we have this dataset open, let's explore some of its capabilities Image attributes # what is the nane of this image img_nane = dataset .nane print(‘Inage filename: {n}\n' .fornat(n=ing_name)) # How many bands does this image have? nun_bands = [Link] print(‘Nunber of bands in image: {n}\n‘ -format(nenum_bands)) # How many rows and columns? rows, cols = [Link] print("Image size is: {r} rows x {c} colunns\n'.format(r=rows, c=cols)) # Does the raster have a description or metadata? desc = [Link] metadata = [Link] print(*Raster description: {desc}\n' . format (desc=desc)) # What driver was used to open the raster? driver = [Link] print(‘Raster driver: {d)\n" .format (d=driver)) # hat is the raster's projection? proj = [Link] print('Inage projection print(proj, ‘\n') # what is the raster's "geo-transform" gt = [Link] print('Inage geo-transform:\n(gt}\n' .fornat(gt=gt)) print(‘All raster metadata:') print (metadata) print(*\n")Image filename: ... /data/LE70220492¢02106EDCa0_stack.gtif Number of bands in image: 8 Image size is: 25@ rows x 25@ columns Raster description: (‘band 1 reflectance’, ‘band 2 reflectance’, ‘band 3 reflectance’, "band 4 reflectance’, ‘band 5 reflectance’, ‘band 7 reflectance’, ‘band 6 temperature’, “Band 8") Raster driver: Gift Image projection: £PSG:32615 Image geo-transform: | 3.08, 0.08, 462405.00 | @.00,-30.00, 1741815.00] | @.00, 0.08, 1.00 All raster metadata: {‘driver’: ‘Giff, ‘dtype’: ‘int16', ‘nodata': None, ‘width': 258, ‘height’: 258, ‘coun t': 8, ‘ers*: CRS.from_epsg(32615), ‘transform’: AfFine(30.0, 0.0, 462405.0, 0.0, -30., 1741815.0)} The first few pieces of information we obtained are fairly straightforward - image name, the raster size, the number of bands, a description, some metadata, and the rasters file format. The image's projection is formatted in what's known as “Well Known Text". For more information or specific projections and for format conversions among projection description formats (e.g, proja string, WKT, ESRI WKT, JSON, etc.) see Spatial Reference, The last piece of information we accessed is something called a "geotransform'. This set of 6 umbers provides all the information required to and from transform pixel and projected coordinates. In this example, the first number (462405) and the fourth number (1741815) are the top left of the upper left pixel of the raster. The pixel size in x and y dimensions of the raster is listed as the second (30) and the sixth (-30) numbers, Since our raster is north up oriented, the third and fifth numbers are 0. For more information on the GDAL data model, visit this web page. Image raster bands now for the fun part, actually visualizing and working the data The rasterio Dataset object we created contains a lot of useful information but itis not directly usec to read in the raster image. Instead we will need to access the raster’s bands using the read() method: # Open the fourth band in our image - NIR here nir = [Link](4) [Link] # check out the dimensions of the image (25, 25@)When we load our raster band into memory we will read it into a NumPy 2 dimensional array. Numby is, "the fundamental package for scientific computing with Python", because it allows us to represent our data in a very memory efficient way. NumPy arrays are the comerstone or building block of the rest of the Scientific Python suite of software. Get familiar with them: © NumPy for MATLAB users © NumPy tutorial © NumPy API reference manual Just as we made the routines and data types from rasterio available to us using import , we loadec up NumPy. When we import NumPy, we also gave it an alias so that we don't have to type numpy every time we want to use it # No alias import numpy print(numpy.__version_) # Alias or rename to "np" -- a very common practice import numpy as np print(np.__version__) 1.20.2 2 # What are the band's datatypes? datatype = [Link] print (‘Band datatypes: {dt}' .fornat(dt=datatype)) # How about some band statistics? band_mean = [Link](nir) band_nin = [Link](nir) band_max = [Link](nir) band_stddev = [Link](nir) print ("Band range: {minimum} - {naximun}’.format(maximun=band_max, ‘minimun=band_min)) print(‘Band mean, stddev: {m}, {s}\n'.format(msband_mean, s=band_stddev)) Band datatypes: (‘inti6", ‘inti6’, ‘inti6", ‘inti’, ‘inti6', ‘inti6", ‘intt6’, ‘inti6") Band range: 1007 - 8178 Band mean, stddev: 2700.18344, 710.129602141585S The method sead() takes arguments that allow us to specify a subset of the raster bands, specific X and Y offsets and sizes of the bands and much more. Remember this ability when you want to process large images or are working with a limited amount of memory. In these circumstances, you will run out of memory if you read the entire dataset in at once. Instead, read in a block of some umber of columns and rows at one time, perform your computation and store your output, anc then chunk through the rest of the image Read more here [Link] io/en/latest/api/[Link] [Link]For now, because this image is small, well ust read in and display the entire image: full_ing = [Link]() full_img.shape # bands, rows, cols (8, 25, 250) With our data read into a NumPy array, we can print it to console and even perform statistics on it in addition to helping us store massive amounts of data efficiently, NumPy will help us with some basic linear algebra, numerical operations, and summary statistics. For now let's plot that near infrared band we read in earlier. from [Link] import show # import the show function which allows us to display th print("Inage dimensions: ", full_img.shape) show(nir, transform=[Link], cnap="gray') Image dimensions: (8, 258, 25@) 464000 466000 468000 The next chapter (link to webpage or Notebook) puts these lessons to use in order to calculate the Normalized Difference Vegetation Index (NOVI).
You might also like
Intro to Spatial Data Analysis in Python
PDF
100% (1)
Intro to Spatial Data Analysis in Python
27 pages
QGIS 3.16 PyQGISDeveloperCookbook en
PDF
No ratings yet
QGIS 3.16 PyQGISDeveloperCookbook en
164 pages
OpenCV Python Computer Vision Course
PDF
100% (1)
OpenCV Python Computer Vision Course
85 pages
Advanced Image Processing Techniques
PDF
100% (1)
Advanced Image Processing Techniques
326 pages
Moon Surface Analysis Using Graph Neural Networks
PDF
No ratings yet
Moon Surface Analysis Using Graph Neural Networks
4 pages
Hybrid Quantum Deep Learning With Superpixel Encoding For Earth Observation Data Classification
PDF
No ratings yet
Hybrid Quantum Deep Learning With Superpixel Encoding For Earth Observation Data Classification
14 pages
ECognition Reference Book
PDF
No ratings yet
ECognition Reference Book
195 pages
Python Pillow Tutorial
PDF
100% (1)
Python Pillow Tutorial
95 pages
Cong Thesis Final
PDF
No ratings yet
Cong Thesis Final
220 pages
QgsLayerTreeGroup and DataSource URI
PDF
No ratings yet
QgsLayerTreeGroup and DataSource URI
170 pages
Accelerating Vision with VPI 1.1 Python
PDF
No ratings yet
Accelerating Vision with VPI 1.1 Python
23 pages
Anomaly Detection with CIFAR-10 Images
PDF
No ratings yet
Anomaly Detection with CIFAR-10 Images
9 pages
PyQGIS 3.40 Developer Cookbook
PDF
No ratings yet
PyQGIS 3.40 Developer Cookbook
176 pages
Digital Image Processing in Remote Sensing
PDF
No ratings yet
Digital Image Processing in Remote Sensing
140 pages
Understanding Map Algebra Operations
PDF
No ratings yet
Understanding Map Algebra Operations
8 pages
Object Detection with Python OpenCV
PDF
No ratings yet
Object Detection with Python OpenCV
23 pages
Super Resolution Imaging by Peyman
PDF
No ratings yet
Super Resolution Imaging by Peyman
69 pages
LiDAR Remote Sensing Fundamentals
PDF
No ratings yet
LiDAR Remote Sensing Fundamentals
47 pages
Pandas Basics for Data Analysis
PDF
No ratings yet
Pandas Basics for Data Analysis
21 pages
Deep Learning in ArcGIS Overview
PDF
No ratings yet
Deep Learning in ArcGIS Overview
34 pages
LiDAR Tutorial with ArcGIS Pro 2.3
PDF
No ratings yet
LiDAR Tutorial with ArcGIS Pro 2.3
44 pages
Deep Learning for Satellite Time-Series Analysis
PDF
No ratings yet
Deep Learning for Satellite Time-Series Analysis
44 pages
Quantum Image Processing Opportunities and Challenges
PDF
No ratings yet
Quantum Image Processing Opportunities and Challenges
8 pages
IMAP 4.0 Apr23 StudentWorkbook
PDF
No ratings yet
IMAP 4.0 Apr23 StudentWorkbook
221 pages
Image Processing with Python & OpenCV
PDF
No ratings yet
Image Processing with Python & OpenCV
3 pages
Digital Image Processing Concepts, Algorithms, and Scientific Applications Second Edition by Bemd Jahne PDF
PDF
No ratings yet
Digital Image Processing Concepts, Algorithms, and Scientific Applications Second Edition by Bemd Jahne PDF
413 pages
TensorFlow Basics for Machine Learning
PDF
No ratings yet
TensorFlow Basics for Machine Learning
65 pages
Python Scripting for ArcGIS Pro Guide
PDF
100% (2)
Python Scripting for ArcGIS Pro Guide
263 pages
Web GIS Setup: GeoServer & PostGIS Guide
PDF
100% (2)
Web GIS Setup: GeoServer & PostGIS Guide
30 pages
Introduction to Pandas Data Structures
PDF
No ratings yet
Introduction to Pandas Data Structures
87 pages
TensorFlow Satellite Image Classification
PDF
No ratings yet
TensorFlow Satellite Image Classification
297 pages
Mastering Python for Geospatial Development
PDF
100% (1)
Mastering Python for Geospatial Development
32 pages
Raspberry Pi Computer Vision Guide
PDF
50% (2)
Raspberry Pi Computer Vision Guide
23 pages
NumPy Cheat Sheet for Data Science
PDF
67% (3)
NumPy Cheat Sheet for Data Science
1 page
Introduction to Geospatial Data Science
PDF
No ratings yet
Introduction to Geospatial Data Science
10 pages
Understanding Org-mode Basics
PDF
No ratings yet
Understanding Org-mode Basics
8 pages
OpenCV: Overview and History
PDF
No ratings yet
OpenCV: Overview and History
13 pages
Pretrained Models in Computer Vision
PDF
No ratings yet
Pretrained Models in Computer Vision
10 pages
Hyperspectral Guide
PDF
No ratings yet
Hyperspectral Guide
17 pages
Learning QGIS
PDF
100% (2)
Learning QGIS
110 pages
Python Pandas Cheat Sheet Guide
PDF
No ratings yet
Python Pandas Cheat Sheet Guide
2 pages
Deep Learning Basics with Keras
PDF
25% (4)
Deep Learning Basics with Keras
13 pages
Hyperspectral Imaging Benefits in Agriculture
PDF
100% (1)
Hyperspectral Imaging Benefits in Agriculture
17 pages
Open QASM
PDF
No ratings yet
Open QASM
3 pages
Python Geospatial Analysis Cookbook - Sample Chapter
PDF
100% (1)
Python Geospatial Analysis Cookbook - Sample Chapter
29 pages
Digital Image Processing Basics in MATLAB
PDF
No ratings yet
Digital Image Processing Basics in MATLAB
8 pages
GeoPandas Documentation Overview
PDF
No ratings yet
GeoPandas Documentation Overview
45 pages
Pradip Python-PPT-Geoinformatics (Pradip)
PDF
100% (1)
Pradip Python-PPT-Geoinformatics (Pradip)
8 pages
Multi-Temporal Image Classification
PDF
No ratings yet
Multi-Temporal Image Classification
56 pages
Deep Learning for Imagery in ArcGIS
PDF
No ratings yet
Deep Learning for Imagery in ArcGIS
28 pages
Train Object Detection with MMDetection
PDF
No ratings yet
Train Object Detection with MMDetection
7 pages
Numpy Functions and Array Manipulation
PDF
No ratings yet
Numpy Functions and Array Manipulation
39 pages
Image Classification Using Pre-Trained Convolutional Neural Network in COLAB
PDF
No ratings yet
Image Classification Using Pre-Trained Convolutional Neural Network in COLAB
6 pages
Seaborn: A Comprehensive Introduction
PDF
No ratings yet
Seaborn: A Comprehensive Introduction
42 pages
Python Image Processing with Pillow
PDF
No ratings yet
Python Image Processing with Pillow
15 pages
Deep Learning with Orfeo Toolbox Tutorial
PDF
100% (1)
Deep Learning with Orfeo Toolbox Tutorial
13 pages
Linear Algebra Essentials for Deep Learning
PDF
No ratings yet
Linear Algebra Essentials for Deep Learning
20 pages
QGIS Python Programming Cookbook
PDF
100% (3)
QGIS Python Programming Cookbook
44 pages
Image Processing with Scilab Manual
PDF
No ratings yet
Image Processing with Scilab Manual
103 pages
Rasterio: Python Library Overview
PDF
No ratings yet
Rasterio: Python Library Overview
22 pages
Muslim Rule in the Subcontinent History
PDF
No ratings yet
Muslim Rule in the Subcontinent History
21 pages
Bioremediation of Arsenic and Lead Using Aspergillus Niger
PDF
No ratings yet
Bioremediation of Arsenic and Lead Using Aspergillus Niger
6 pages
Image Segmentation With Kmeans
PDF
No ratings yet
Image Segmentation With Kmeans
17 pages
Chapter 3 Plotting and Visualizing Your Data
PDF
No ratings yet
Chapter 3 Plotting and Visualizing Your Data
14 pages
Chapter 5 Classification of Land Cover
PDF
No ratings yet
Chapter 5 Classification of Land Cover
13 pages