Read and write raster files with GDAL in Python

preview_player
Показать описание
This tutorial explains how to read raster data as an array and save arrays as a GeoTiff file using the GDAL library in Python.

Code:

from osgeo import gdal
import numpy as np

# import
gt = ds.GetGeoTransform()
proj = ds.GetProjection()

band = ds.GetRasterBand(1)
array = band.ReadAsArray()

# manipulate

# export
driver = gdal.GetDriverByName("GTiff")
driver.Register()
eType = gdal.GDT_Int16)
outds.SetGeoTransform(gt)
outds.SetProjection(proj)
outband = outds.GetRasterBand(1)
outband.WriteArray(binmask)
outband.FlushCache()

# close your datasets and bands!!!
outband = None
outds = None
Рекомендации по теме
Комментарии
Автор

This has been very helpful, I remember taking a course of Python in GIS and being very lost however I continued. Following this tutorial allowed me to finally make sense of those codes I've been using because they worked somehow. So big thank you!

itzahernandez
Автор

I want cry of happyness, I´m so grateful with you, finally i have found what I as looking for, i has been a great tutorial.Greetings from Perú. :3

anthonyurbina
Автор

Wow!!! You did a very great and accurate lesson, thank you very much, dear.
Hoping you will do more in time series raster volume spatial analysis.

filmonafewerki
Автор

Thanks for sharing these great learning resources!

nlee
Автор

Gracias. Me sacó de un gran apuro el hecho de exportar un raster filtrando valores específocos.

dannye.isaiassantosg.
Автор

Great great great video. Thank you for doing these, they’re so helpful.

colinmccavitt
Автор

Thanks for making this series you saved me

zainabkhan
Автор

Muchas gracias, clarísimo el video, entendí todo!

JavierParra-bzrs
Автор

Obrigado pela playlist, Otimo Conteudo !!

Geotec
Автор

Great tutorial, thanks! The third and fifth values in gt are skew

farzinashouri
Автор

thank you, this video is very very very nice! give you a big like!

petexplorex
Автор

The zeros in the geotransform refer to rotation. Zero in this case because north is up

jenniferbuz
Автор

What if I got a crop of the numpy array and would like to keep the global coordinates of the remaining pixels? Is there some way to pass the Affine Transform or the geo location of some of the array corners to the driver?

Thanks!

MathCeOuStTA
Автор

If I want to use no data values instead of zeros for line 19 would I need to move line 32 above line 19? outband.SetNoDataValue (np.nan)
binmask = np.where((array >= np.mean(array)), 1, np.nan)

brittanykrzyzanowski
Автор

Hello,
I have a question, How can we georeference a raster by corner points?

alimardy
Автор

When I run the script to test gdal.Open, no variable shows up under variable explorer. How can I fix this please?

diplo
Автор

thanks for this useful video, I have a question, how we can change the resolution of raster file ?

seyedpeyman
Автор

What if I want multiple bands in my output, will I have to run a loop and store all the bands in the output file. I am dealing with hyperspectral data.

aryanirvaan
Автор

Thanks for your contribution. It is really useful!

I have two questions.

How can I import a RasterStack as an array with 3 dimensions?

How can I import the RasterStack or RasterBand files into a folder as a list of arrays?

Thank youu for yout time!!!

sergiomorellmonzo
Автор

I have a .grc file, is there any way to use GDAL for this kind of raster file?

nupursonigandhi
join shbcf.ru