Using rasterio you could do
file_list = ['file1.tif', 'file2.tif', 'file3.tif']
# Read metadata of first file
with rasterio.open(file_list) as src0:
meta = src0.meta
# Update meta to reflect the number of layers
meta.update(count = len(file_list))
# Read each layer and write it to stack
with rasterio.open('stack.tif', 'w', **meta) ...
If using GDAL 2.1+ it's as simple as gdal.BuildVRT then gdal.Translate:
from osgeo import gdal
outvrt = '/vsimem/stacked.vrt' #/vsimem is special in-memory virtual "directory"
outtif = '/tmp/stacked.tif'
tifs = ['a.tif', 'b.tif', 'c.tif', 'd.tif']
#or for all tifs in a dir
#tifs = glob.glob('dir/*.tif')
outds = gdal.BuildVRT(outvrt, tifs, ...
You could use gdal_translate from the new workflow, which is under:
Raster > Conversion > Rearrange bands...
You won't be able to select the pencil as in the past, but you can select only the band you need from the UI. You also get the python code in case you want to use it in pyqgis:
gdal_translate "path/to/raster.tif" -b 1 "path/to/...
What you want to do is Set Raster Properties in a script or change it manually in ArcCatalog. This will not create a new raster or even take very long.
In python it's a bit tricky:
import sys, os, arcpy
InFolder = sys.argv
arcpy.env.workspace = InFolder
for Ras in arcpy.ListRasters():
arcpy.AddMessage("Processing " + Ras)
You can use a simple python script that uses the Band.SetDescription method to set the band names:
Set Band descriptions
python set_band_desc.py /path/to/file.ext band desc [band desc...]
band = band number to set (starting from 1)
desc = band description string (enclose in "double quotes" if it contains spaces)
Your values aren't in 0,255 since they are UInt16. You can try rescaling to 0,255 (GDAL works it out by default from input min/max and output default 0,255):
gdal_translate -b 1 -b 2 -b 3 -mask "none" "input.tif" "output.tif" -scale
Note you can add params if the defaults aren't sensible:
-scale [src_min src_max [dst_min dst_max]]
To calculate a grey-scale from the same input file using different bands u can open the file multiple times and define the band which you want to use with --A_band=n.
See my example for calculating the NDVI from a satellite image with red at band 1 and near-infrared at band 4.
gdal_calc.py -A input.tif --A_band=1 -B input.tif --B_band=4 --outfile=ndvi.tif -...
This is a limitation of the PNG format. It only has 3 information channels (RGB), so one of your bands will be suppressed. If you really need to, you can save your NIR band as an alpha channel, but beware - you won't be able to access it easily. Neither QGIS nor ArcGIS allow allocating the alpha channel to one of its display channels. The information will ...
The Rasterio Plotting documentation describes how to visualize multiband imagery. For example, using 4-band NAIP imagery:
from rasterio.plot import show
src = rasterio.open("path/to/your/image/m_3511642_sw_11_1_20140704.tif")
To visualize specific band combination use the following approach (source). In this case, I am creating a ...
i've found a way using a gdal object supported by numpy arrays..
import numpy as np
from affine import Affine
def save_multiband (output_name, dataset, raster_data, driver,
NaN_Value, nband, arr_projection=None):
if arr_projection is None:
arr_projection = 
if str(type(arr_projection)) == "<...
It depends upon the intended use of the Landsat data. Generally speaking, if you are doing multi-temporal analyses, you need atmospherically corrected data, otherwise DN format is sufficient. I would recommend reading the following landmark paper on the subject:
Song, C., Woodcock, C. E., Seto, K. C., Lenney, M. P., & Macomber, S. A. (2001). ...
You have downloaded the data and you can find it if you unpack the .tar.gz file using 7zip or similar software for unpacking files. The .tar.gz file is the fourth file from the top that can be seen in your first screenshot.
Do note that you have to unpack the .tar.gz twice in order to get to the data. You will easily recognize it as you will see the ...
Next code works with multi band raster. It uses QgsRasterDataProvider objects to calculate statistic through QgsRasterBandStats objects.
layer = iface.activeLayer()
extent = layer.extent()
provider = layer.dataProvider()
for band in range(1, layer.bandCount() + 1):
stats = provider.bandStatistics(band, QgsRasterBandStats.All, extent, 0)
min = ...
This is a display issue: you want to display a continuous band using categories. You do not need to split your image to create a new new image: this can be done directly on the multiple band image, and you can add the multiple band layer multiple times on the map.
Go to layer properties > Symbology
Select singleband pseudocolor
Choose the band that you ...
You need to use each single band as an image to do raster calculator in ArcGIS. Raster calculator cannot give you access to the multiple bands composited into a one image. However, you can access each band of the composite image from ArcCatalog.
Navigate to the 5-band composite image from raster catalog,
Drag and drop each band into ArcMap,
Now you can ...
You can read specific bands in a single call using rasterio by passing a list/tuple of band numbers (Following the GDAL convention, bands are indexed from 1):
dataset = rasterio.open('multiband.tif')
dataset.read((1,2)) #read 1st two bands into an array.
array([[[ 85, 98, 75, ..., 53, 55, ...
Using the creation option -co "ALPHA=NO" param in the gdal_translate command prevented the 4th band being set as alpha (its set as undefined now) which solved the issue.
This solution was found here: How can I use gdal_retile on RGBI (4 band) GeoTIFFs while preserving band information?
I will just answer my own question here, if anyone runs into the same problem with multiband images and TensorFlow.
I ended up using Keras on top of TensorFlow and instead of feeding the image files into the network, I converted my tiff-files to numpy arrays and appended all of them to the same array, which I saved as a .npy-file. In this way I avoided the ...
Here is another approach:
// Make a (toy) 3 bands image
var image = ee.Image([1,2,3]).rename(['one', 'two', 'three'])
Map.addLayer(image, null, '3 bands image')
// Sum all bands
var sum_bands = image.reduce('sum')
Map.addLayer(sum_bands, null, 'sum')
// You can compute any reduction
var mean_bands = image.reduce('mean')
Map.addLayer(mean_bands, null, '...
Building on FelixIP's answer, the following method checks for 1) zero values in a 200x200m area located at the center of the image and 2) corrupt rasters that will not read. The bad files are added to one of two lists based on the problem. Efficiency is good, with the script scanning ~2 tiles/sec.
import arcpy, os, numpy
arcpy.env.workspace = r'D:\temp\...
You will not be able to generate the NDVI from Landsat Look images. These are generated from the visible bands to "simulate natural color"
In order to get the image with all bands, including red and near infrared, download it from another source - for example the USGS EarthExplorer
For Landsat 8 the NDVI is calculated as (band5 - band4) / (band5 + band4).
According to NASA, a spectral radiometer is a multispectral sensor.
Spectroradiometer—A radiometer that measures the intensity of radiation in multiple wavelength bands (i.e., multispectral). Many times the bands are of high-spectral resolution, designed for remotely sensing specific geophysical parameters
Perhaps you're thinking of a spectrometer, which ...
With a multi-band raster input, ArcGIS will only process the first band:
Multiband raster data
When a multiband raster is used as input, most Spatial Analyst tools operate only on the first band.
The exceptions are certain tools in the Multivariate and Extraction toolsets which do process each of the bands in a multiband input and can create a ...
With more than one calibration target, you can estimate the relationship between your measurement and the albedo/reflectance with a linear regression.
If you have only one calibration target, you need some more assumptions and I recommend you to use simple equations to avoid overfitting. Those are applied for each band individually.
With a clear sky, the ...
This is a non-trivial problem. One solution is to collect ground reflectance spectra coincident with the time of UAV flight. The reference spectra may consist of white, grey and black panels that are placed on the ground in a visible location. A spectral radiometer is then used to measure the reflectance of each calibration panel.
The radiometer readings ...
There's a function in rgdal for this SGDF2PCT, so here I coerce to SpatialGridDataFrame, build the colour table and rebuild the raster. Note that indexing in raster is assuming [0, 255].
Control the number of colours with ncolors argument.
b <- brick(system.file("external/rlogo.grd", package="raster"))
pct <- rgdal::SGDF2PCT(as(b, "...