Re: [gdal-dev] How do I select 3 of 5 bands for output?

Lucena, Ivan ivan.lucena at pmldnet.com
Fri Nov 7 15:11:48 EST 2008


Hi Steve,

>  I have a script that was processing MrSID files and need to convert it
>  to support jp2 files also. It seems pretty straight forward except the
>  jp2 files have bands R,G,B,IR and I need to chop these into GeoTif tiles
>  with only R,G,B bands.
>  
>  The script was iterating over the src image and chopping it into tiles
>  using the following command:
>  
>  system("gdalwarp -srcnodata 0 -dstnodata 0 -s_srs +init=epsg:$epsg
>  -t_srs EPSG:4326 -te $xm $ym $xx $yx -rb -wm 250 --config
>  GDAL_ONE_BIG_READ ON -co "TILED=YES" $infile $work/$outd/$outf\n");
>  
>  1) How does this behave with R,G,B,IR as input and how can I get R,G,B
>  only into the GeoTif?

I would add one call to gdal_translate with "-b 1 -b 2 -b 3" first to build a VRT and then call gdalwarp from the VRT.

{
  system("gdaltranslate $infile -b 1 -b 2 -b 3 tmp.vrt");
  system("gdalwarp -srcnodata 0 -dstnodata 0 -s_srs +init=epsg:$epsg -t_srs EPSG:4326 -te $xm $ym $xx $yx -rb -
wm 250 --config GDAL_ONE_BIG_READ ON -co "TILED=YES" tmp.vrt $work/$outd/$outf\n");
}
system("gdalmanage delete tmp.vrt");

Regards,

Ivan



More information about the gdal-dev mailing list