I am interested to replace would like prefix with area name such that the raster layers should be more like 'Area_1_B01'.

1 year ago 5 Replies
PK
Patrick Ken Kalonde
4 years ago

Hi guys,

I have a lot of Sentinel-2 Satellite Images in my QGIS layers panel. For each of my study area i have organized the images into groups as Area 1, Area 2, Area 3 and so on.

As Sentinel 2 has 12 bands that come as separate raster files, i have 12 raster files under each of the groups. Each of the raster has a name that goes more like 'RT_T36LXH_A019251_20190228T080137_B01' thats for band 1. For the 12 bands of a particular area the only difference is the last part of the file name '_B01' which is the band name.

I am interested to replace would like prefix with area name such that the raster layers should be more like 'Area_1_B01'. Is there a way possible to automatically replace the prefixes with the group name? or the only way possible is to change the prefixes of the file names before adding the raster files into QGIS? Thanks in advance, looking forward to learn from others.

Patrick

3 Likes

Replies

Hafiz Hamid Gulzar 4 years ago

Yeah there is not any option to do it auto.... but u can also do it without opening through catalog of arcgis

0 Likes
Robbie Austrums 4 years ago

Renaming layers is easy enough using Python within QGIS, but it's probably even easier to rename the files using your OS before adding them. For example in Windows Command Prompt:

ren ABC123*.tif area1_*.tif

I suspect you'll make your life easier by combining your bands into VRTs though: Raster > Miscellaneous > Build Virtual Raster. Select all band files for one area and tick the 'Place each input file into a separate band' checkbox and name the output file e.g. 'Area1.vrt'

0 Likes
Patrick Ken Kalonde (4 years ago)

Robbie Austrums Great thanks i will try to get my fingers exposed to writing python scripts to serve that purpose.

Patrick Ken Kalonde (4 years ago)

Robbie Austrums regarding combining the bands, i have been using SCP plugin and it works pretty well when i use raster files for one particular area. But when i build one virtual raster for all the areas, there are challenges. You can see the output for an intersect of of some of the test areas

Robbie Austrums (4 years ago)

You may need to use several steps. Perhaps merge all bands for one tile into a VRT, repeat for other tiles, then finally merge all those VRTs into an overall VRT.