Making Sense Remotely
Making Sense Remotely
  • 15
  • 300 236
Visualizing multi-band satellite images in Python
In this tutorial, I explain how to visualize multi-band Landsat 8 satellite imagery as true- and false-color composites using Python and matplotlib. The basic procedure is: 1) read individual raster bands as array 2) rescale to 0 and 1 using minimum and maximum values (or percentiles or mean + - standard deviation for contrast enhancement) 3) stack arrays using numpy.dstack 4) plot RGB composite with plt.imshow()
Code:
from osgeo import gdal
import numpy as np
import matplotlib.pyplot as plt
def scaleMinMax(x):
return((x - np.nanmin(x))/(np.nanmax(x) - np.nanmin(x)))
def scaleCCC(x):
return((x - np.nanpercentile(x, 2))/(np.nanpercentile(x, 98) - np.nanpercentile(x,2)))
def scaleStd(x):
return((x - (np.nanmean(x)-np.nanstd(x)*2))/((np.nanmean(x)+np.nanstd(x)*2) - (np.nanmean(x)-np.nanstd(x)*2)))
ds = gdal.Open("Landsat8_20200423_B1-7.tif")
r = ds.GetRasterBand(4).ReadAsArray()
g = ds.GetRasterBand(3).ReadAsArray()
b = ds.GetRasterBand(2).ReadAsArray()
ds = None
rMinMax = scaleMinMax(r)
gMinMax = scaleMinMax(g)
bMinMax = scaleMinMax(b)
rgbMinMax = np.dstack((rMinMax,gMinMax,bMinMax))
plt.figure()
plt.imshow(rgbMinMax)
plt.show()
rCCC = scaleCCC(r)
gCCC = scaleCCC(g)
bCCC = scaleCCC(b)
rgbCCC = np.dstack((rCCC,gCCC,bCCC))
plt.figure()
plt.imshow(rgbCCC)
plt.show()
rStd = scaleStd(r)
gStd = scaleStd(g)
bStd = scaleStd(b)
rgbStd = np.dstack((rStd,gStd,bStd))
plt.figure()
plt.imshow(rgbStd)
plt.show()
Переглядів: 12 818

Відео

Spatial Interpolation with GDAL in Python #2: IDW and Linear Interpolation
Переглядів 14 тис.3 роки тому
In this second interpolation tutorial, I talk about the Inverse Distance to a Power and Linear Interpolation algorithms available for the program gdal_grid (or gdal.Grid() if you use the GDAL Python API). I explain a little about the theoretical background of these spatial interpolation algorithms and then apply them to create a regular grid from scattered point data in Python. gdal_grid docume...
Spatial Interpolation with GDAL in Python #1: Nearest Neighbor and Moving Average
Переглядів 13 тис.3 роки тому
In this tutorial, I will give an introduction to the spatial interpolation algorithms nearest neighbor and moving average. We will use gdal.Grid() from the geospatial data abstraction library GDAL to create a regular grid from scattered point data in Python. gdal_grid documentation: gdal.org/programs/gdal_grid.html GDAL Grid Tutorial: gdal.org/tutorials/gdal_grid_tut.html#gdal-grid-tut GDAL/OGR...
Convert between CSV and GeoTIFF with GDAL in Python
Переглядів 21 тис.3 роки тому
Recently I got a couple of questions regarding the conversion of raster data from CSV to GeoTIFF and vice versa, so I decided to make a tutorial on this topic. In this video, I explain different methods to convert a GeoTIFF file into a three-column structure with X Y coordinates and raster value and to convert CSV data into GeoTiff using GDAL and Python. GDAL/OGR Python API: gdal.org/python/ Ch...
Merge raster data with GDAL in Python
Переглядів 18 тис.3 роки тому
This tutorial explains how to merge a bunch of raster tiles from the same directory to a single geotiff file using GDAL in Python. There are two options to merge raster data with GDAL: 1) run gdal_merge.py with subprocess 2) build a virtual mosaic of all raster files and convert that to geotiff. GDAL/OGR Python API: gdal.org/python/ Code: from osgeo import gdal import glob import subprocess # l...
Splitting raster data into equal pieces with GDAL in Python
Переглядів 11 тис.4 роки тому
In this tutorial, I will guide you through the creation of a Python script that uses GDAL to split raster data into several equal parts. The key to this task is to find out the xmin, ymin, xmax, and ymax coordinates of the smaller tiles and then use gdal.Warp or gdal.Translate to adjust the output boundaries of the input raster data. Be aware that the output tiles might have a slightly differen...
Reproject, resample and clip raster data with GDAL in Python
Переглядів 23 тис.4 роки тому
In this tutorial, I explain how to use gdalwarp in Python to reproject raster data to a different coordinate reference system, change the resolution (resample) and clip it to a shapefile. GDAL/OGR Python API: gdal.org/python/ Code: from osgeo import gdal import numpy as np import matplotlib.pyplot as plt ds = gdal.Open("dem.tif") # reproject dsReprj = gdal.Warp("demReprj.tif", ds, dstSRS = "EPS...
Processing DEMs with GDAL in Python
Переглядів 14 тис.4 роки тому
In this tutorial I explain various approaches to calculating terrain attributes such as the slope, aspect and hillshade of a digital elevation model (DEM) in Python. The different options are: 1) Run gdaldem with os.system() or subprocess.call() gdal.org/programs/gdaldem.html 2) Use the GDAL/OGR Python API and DEMProcessing() gdal.org/python/ 3) Use richdem.TerrainAttribute() richdem.readthedoc...
Read and write vector files with GDAL/OGR in Python
Переглядів 15 тис.4 роки тому
This tutorial explains how to open vector files with GDAL/OGR in Python, add attribute fields to store measures such as the perimeter and area of a polygon, and save the updated features to a new shapefile. We will also look at how to create a geometry from individual coordinates in Python and write it to a new vector file. GDAL/OGR Python API: gdal.org/python/ Python GDAL/OGR Cookbook: pcjeric...
Read and write raster files with GDAL in Python
Переглядів 46 тис.4 роки тому
This tutorial explains how to read raster data as an array and save arrays as a GeoTiff file using the GDAL library in Python. GDAL/OGR Python API: gdal.org/python/ Code: from osgeo import gdal import numpy as np import matplotlib.pyplot as plt # import ds = gdal.Open("dem.tif") gt = ds.GetGeoTransform() proj = ds.GetProjection() band = ds.GetRasterBand(1) array = band.ReadAsArray() plt.figure(...
GDAL Tutorial #5: Process vector data with GDAL/OGR
Переглядів 7 тис.4 роки тому
This tutorial provides an overview of the vector programs that exist in GDAL/OGR, specifically ogrinfo and ogr2ogr. We will use GDAL and the command line process and transform vector datasets. Information on the projection, extent, geometry, etc. of a shapefile can be retrieved using ogrinfo. To convert between different vector file formats and merge shapefiles we will use ogr2ogr. Finally we w...
GDAL Tutorial #4: Rasterize and Polygonize
Переглядів 12 тис.4 роки тому
This tutorial explains how to convert between raster and vector files using gdal_rasterize and gdal_polygonize from the command line. I provide several examples for raster/vector conversion, including how to pass attribute values to the output raster file, how to perform an attribute-based feature-selection and how to create a multi-band raster storing values from different poygons in different...
GDAL Tutorial #3: Raster calculation
Переглядів 11 тис.4 роки тому
In this tutorial, we will explore the GDAL command line raster calculator gdal_calc.py. gdal_calc is the equivalent to the raster calculator in QGIS and the expressions from this tutorial are easily transferrable. I provide three examples for the use of gdal_calc.py: 1) Masking pixel-values above a given threshold (e.g. to extract river networks). 2) Computation of the Normalized Difference Veg...
GDAL Tutorial #2: Converting, Resampling, Reprojecting, Clipping
Переглядів 27 тис.4 роки тому
This second GDAL tutorial explains the processing of geospatial raster data using GDAL and the command line interface. The following commands are introduced: - gdalinfo to obtain information on a given raster dataset - gdal_edit to manipulate this information - gdal_translate to convert between different raster formats and resample data to a different resolution - gdalwarp to change the coordin...
GDAL Tutorial #1: Introduction + Installation
Переглядів 54 тис.4 роки тому
The Geospatial Data Abstraction Library (GDAL) is a collection of tools that allow you to read, manipulate and write both raster and vector data using GDAL and the Simple Feature Library (OGR). This tutorial video is an introduction to the GDAL library, showing examples for more efficient processing of geospatial data using GDAL and also providing help for installing the library on Windows and ...

КОМЕНТАРІ

  • @woutzweers
    @woutzweers 2 дні тому

    I (as a windows user, not familiar with the command line) spent some time finding the proper command line terminal. It worked for me when i opened the terminal from the Qgis browser (right click on a folder or even quicker: your working folder>> open in terminal). The windows terminal (maybe i used the wrong one) did not work properly. But from the browser in Qgis i had no problem at all to execute the commands.

  • @woutzweers
    @woutzweers 18 днів тому

    just what i needed as a newby in commandline work :-)

  • @GalbraithGriffith-v9w
    @GalbraithGriffith-v9w Місяць тому

    Kessler Shoal

  • @ChristineFulton-q5y
    @ChristineFulton-q5y Місяць тому

    Kling Alley

  • @EllisDean-b9m
    @EllisDean-b9m Місяць тому

    Oberbrunner Overpass

  • @AnnieLevenhagen-f7n
    @AnnieLevenhagen-f7n Місяць тому

    Hilll Mountain

  • @stozi92
    @stozi92 2 місяці тому

    Thanks for the video. How can I convert X and Y to Lat and Lon in a csv file?

  • @andressanchez175
    @andressanchez175 2 місяці тому

    Amazing video, and love your accent. Muchas gracias!

  • @jeewankbastola2272
    @jeewankbastola2272 3 місяці тому

    Please provide the files as well so it wont be confusing to practice the same

  • @jeewankbastola2272
    @jeewankbastola2272 3 місяці тому

    Hi. It's a great tutorial. Would you mind to share the files you have used in the tutorial please 🙏❤

  • @JohnWick-n9y
    @JohnWick-n9y 3 місяці тому

    Extremely helpful! Please keep updating this series!💕

  • @FocusStudySoundscapes
    @FocusStudySoundscapes 4 місяці тому

    Data Set available?

  • @Kiwinov
    @Kiwinov 7 місяців тому

    This is amazing, thank you!

  • @gz6616
    @gz6616 7 місяців тому

    Hi, I'm wondering is it possible to provide the 2nd argument to the Grid() function, not using a "points.shp" file name, but some other format? I don't have a points.shp file, but only the x- and y- and z- coordinates. How do I provide those to the Grid() function?

  • @KONDAGENIDEVA
    @KONDAGENIDEVA 7 місяців тому

    From where will get dem.tif file?

  • @nikhilkumarkulkarni8798
    @nikhilkumarkulkarni8798 7 місяців тому

    How to rotet tif file actioly im trying open tiff file using python but i can able to load but if compated to global mapper image is looking like mirrer image kindly help me to solove this issue

  • @bruinshockey199
    @bruinshockey199 8 місяців тому

    Thank you for this tutorial! Very helpful.

  • @AlulaKebedew-y3o
    @AlulaKebedew-y3o 8 місяців тому

    Perfect explanation, thank you!

  • @LuckyLAK17
    @LuckyLAK17 8 місяців тому

    Hi many thanks for the video. Very interesting allthough I am not yet quite there with my project. Is there a way how to combine hillshading with colormap to show the terrain relief in way that the shading conveys a 3D effect while looking at a 2D map?

  • @CarlosSánchez-m9m
    @CarlosSánchez-m9m 9 місяців тому

    Great tutorial!! I'm stuck on this, and I was wondering if you could help me out. I have a coarse mesh coarse.tif and a fine mesh fine.tif. The extent of coarse.tif is larger and completely includes fine.tif. Both have different resolutions, but I want the points (pixels) of each to be "nested", giving precedence to the arrangement of points in the fine mesh. This means that starting from the fine mesh, I want to construct a coarse mesh where there is one coarse mesh point for every 4 fine mesh points. In other words, the square formed by every 4 fine mesh points has the corresponding coarse mesh point in the center. Once this coarse mesh is created, the average of the involved fine mesh points is considered in the points where both meshes overlap, and interpolation of the coarse mesh points is used outside the overlap. Is it possible by using gdalwarp? Thanks

  • @seyedpeyman6092
    @seyedpeyman6092 9 місяців тому

    Useful and Clear ! Thank You for this Great Tutorial

  • @KingKzTuts2000
    @KingKzTuts2000 9 місяців тому

    is there a way to have gdal working with react project.

  • @metalthower
    @metalthower 10 місяців тому

    Fantastic!!!

  • @boazmwubahimana7129
    @boazmwubahimana7129 11 місяців тому

    Can you please provide solution for gdal cropping RGB images into black and white patches

  • @kerimmirzeyev4340
    @kerimmirzeyev4340 Рік тому

    Hello, thank you for this tutorial it helped me a lot of, I just have a 1 question, I modfied your code instead of 1 data, I'm trying to divide folder of sentinel 2 images to 32x32 tiles, even though I don't get error and when printing it does show the coordinates of newly divided tiles, but output folder remains empty I think warp is not doing what it supposed to do and I don't know what else I could to do get it working, can you tell me what I'm doing wrong? This is my code import os from osgeo import gdal # Specify the input folder containing 256x256 images input_folder = r"E:\ytu\PHD\data eslihan_sentinel_testing\kodlar\SmartpolAIProcess\images" # Output folder for 32x32 tiles output_folder = r"E:\ytu\PHD\data eslihan_sentinel_testing\imagesTiles" image_files = [file for file in os.listdir(input_folder) if file.endswith('.tif')] # Loop through each image file for image_file in image_files: sen = gdal.Open(os.path.join(input_folder, image_file)) # Get the geotransform gt = sen.GetGeoTransform() # Get the dimensions of the image xlen = gt[1] * sen.RasterXSize ylen = gt[1] * sen.RasterYSize # Number of tiles in x and y direction div = 8 # Size of a single tile xsize = xlen // div ysize = ylen // div # Create lists of x and y coordinates xsteps = [gt[0] + xsize * i for i in range(div + 1)] ysteps = [gt[3] - ysize * i for i in range(div + 1)] # Loop over min and max x and y coordinates for i in range(div): for j in range(div): xmin = xsteps[i] xmax = xsteps[i + 1] ymax = ysteps[j] ymin = ysteps[j + 1] print("xmin: "+str(xmin)) print("xmax: "+str(xmax)) print("ymin: "+str(ymin)) print("ymax: "+str(ymax)) print(" ") # Use gdal warp to create 32x32 tiles gdal.Warp( os.path.join(output_folder, f"{os.path.splitext(image_file)[0]}_{i}_{j}.tif"), sen, outputBounds=(xmin, ymin, xmax, ymax), dstNodata=-9999, )

  • @johnegyir9704
    @johnegyir9704 Рік тому

    Clearly explained! Thank you very much. This is really helpful.

  • @DianaRocíoGalindoGonzález

    Graciaaaaas <3

  • @surajpatil6766
    @surajpatil6766 Рік тому

    Haw to install gedal in Jupiter notebook

  • @antonstsezhkin6578
    @antonstsezhkin6578 Рік тому

    Oh! one more thing: you operate with x and y - which one should be latitude and which one the longitude?

    • @ecoro_
      @ecoro_ 9 місяців тому

      x is lon and y is lat, like in a map ... right?

    • @antonstsezhkin6578
      @antonstsezhkin6578 9 місяців тому

      @@ecoro_ thanks!

  • @antonstsezhkin6578
    @antonstsezhkin6578 Рік тому

    Bless you for covering different use cases! And thanks than mine is included.

  • @saremish
    @saremish Рік тому

    Very useful and informative!

  • @navneetsrivastava688
    @navneetsrivastava688 Рік тому

    Please complete the gdal python series. Also it would be very much helpful if you could create a video on how to convert lat long ( spatial coordinates) to pixel coordinates (x,y) and vice versa, with introduction to different projection and crs. Thank you for the video though

  • @AfagRizayeva
    @AfagRizayeva Рік тому

    Thank you for your videos! It's the third video that has been really helpful for me - appreciate it

  • @hrishikeshkatkar7641
    @hrishikeshkatkar7641 Рік тому

    my python version is >3.8 and its returning error to import gdal from osgeo what should I do

  • @livmaritharstad1629
    @livmaritharstad1629 Рік тому

    Great video! I've merged a couple of datasets with no issue, but now I get this error: ERROR 1: ZIPDecode:Decoding error at scanline 0 ERROR 1: TIFFReadEncodedTile() failed. ERROR 1: \\Path to this file...\DTM_1km_6159_636.tif, band 1: IReadBlock failed at X offset 0, Y offset 0: TIFFReadEncodedTile() failed. the data is from Denmark and I've got different offset values like x=6, 1 or 8 and y=5 or 6 I've been stuck on this problem for a while and tried all the solutions I've found on the internet, have you encountered this problem before?

  • @rohitraman6257
    @rohitraman6257 Рік тому

    I am facing difficulty while installing gdal. The error shows 'Environment Not Writable' Please help me.

  • @guanglou2065
    @guanglou2065 Рік тому

    Thanks for the tutorial, very awesome! Just wondering where to download your data for reproducing your demo? Thanks. 🙂

  • @MsTooteh
    @MsTooteh Рік тому

    These tutorials are so incredibly helpful. Thank you!!!

  • @JavierParra-bz2rs
    @JavierParra-bz2rs Рік тому

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

  • @scientistgeospatial
    @scientistgeospatial Рік тому

    thanks

  • @sandeepbhatti3124
    @sandeepbhatti3124 Рік тому

    Thank you so much! I was looking to convert CSV to Tiff and none of other posts on internet seemed to work. Your tutorial was perfect solution to my use case. Thanks again!

  • @sahilkamble8750
    @sahilkamble8750 Рік тому

    I want to generate the raster data, so what should be the method i should follow should be it on python or any other ? Please suggest me some

  •  Рік тому

    I tested the code and I found two issues: 1) using gdal warp i got a Warning: "Warning 1: for band 1, destination nodata value has been clamped to 0, the original value being out of range." It seems related with the nodata values. At the end the resulting tiles are not workables. 2) the resolution res is not valid for y-axis, therefore the tiles generated are incomplete. I defined resx and resy (one per axis), at the result was ok. But in general, your code is the best example that I found surfing the web. Thanks a lot.

  • @amillatali2589
    @amillatali2589 Рік тому

    thank you so much

  • @lorhannascimento200
    @lorhannascimento200 Рік тому

    u're a lifesaver, thank you so much!

  • @louis-philip
    @louis-philip Рік тому

    Thanks for all this, it helps a lot!

  • @rogersc4195
    @rogersc4195 Рік тому

    Come back pls!!!

  • @wangbadan1249
    @wangbadan1249 Рік тому

    Nice Tutor and Tutorial ! where can I get the sample data used in the tutorial? Thanks!

  • @guilhermetorres928
    @guilhermetorres928 Рік тому

    first of all congratulations for the content!!! would you know how to inform how the code would be to convert a raster (orthomosaic) tiff into ecw???

  • @asdfgh7486
    @asdfgh7486 Рік тому

    how can we do aspect analysis and slope analysis?