Ticket #1985 (closed enhancement: fixed)

Opened 4 years ago

Last modified 7 months ago

improved gdal_vrtmerge.py

Reported by: vincentschut Owned by: warmerdam
Priority: normal Milestone:
Component: Utilities Version: svn-trunk
Severity: normal Keywords:
Cc:

Description

Attached is a slightly improved version of the gdal_vrtmerge.py that is currently in pymod/samples.

Changes: o uses ngpython bindings ('from osgeo import gdal') o fixed colortable bug o added customizable precision for coordinates and pixel sizes, by

default set to 10 digits. Can be adjusted by changing the variable 'precision' at the beginning of the python script. This is used 1) to round the calculation result of corner coordinates and pixel size, and 2) in the comparison between pixel size/scale of multiple datasets (including a conversion to string before comparison) to prevent bailing out on nanometer/degree scale differences due to rounding/floating point issues.

Any of you who speaks python, feel free to double check my changes and eventually propose/implement better ones :-) I hereby donate this version to the gdal community.

Vincent Schut.

Attachments

gdal_vrtmerge.py Download (9.2 KB) - added by vincentschut 4 years ago.
gdal_vrtmerge.py.diff Download (2.3 KB) - added by Blackhex 2 years ago.
Input file list and SourceProperties? patch.

Change History

Changed 4 years ago by vincentschut

follow-up: ↓ 2   Changed 4 years ago by sieczka

The -separate flag does not work. So one can't create multi-band VRTs. Trying to erge 7 Landsat bands:

$ gdal_vrtmerge.py -separate nn*.tif -o tm.vrt
Traceback (most recent call last):
  File "/home/shoofi/bin/gdal_vrtmerge.py", line 277, in ?
    t_fh.write('\t\t<ColorInterp>%s</ColorInterp>\n' %

in reply to: ↑ 1   Changed 4 years ago by vincentschut

Replying to sieczka:

The -separate flag does not work. So one can't create multi-band VRTs. Trying to erge 7 Landsat bands: {{{ $ gdal_vrtmerge.py -separate nn*.tif -o tm.vrt Traceback (most recent call last): File "/home/shoofi/bin/gdal_vrtmerge.py", line 277, in ? t_fh.write('\t\t<ColorInterp?>%s</ColorInterp>\n' % }}}

Ah, that must have been my colortable 'fix'. For me it was the other way around: without my fix, it wouldn't work without the -separate flag... I'll have a look into it later today, if time permits.

  Changed 4 years ago by msieczka

I have just tried it again against GDAL 1.5.1 + SVN r14376 and the '-separate' flag works now OK. Might be it failed before due to my error, earlier GDAL version, different Python or else (I'm now on Debian testing Python 2.5.2, before it was Ubuntu Dapper Python 2.4.2).

I can load the resulting VRT into QGIS and arrange any 3 of the 7 TM bands into an RGB composition as needed. E x c e l l e n t.

Without '-separate' however, gdal_vrtmerge.py fails saying:

$ gdal_vrtmerge.py -o tm2.vrt *.tif

Traceback (most recent call last):
  File "/home/shoofi/bin/gdal_vrtmerge.py", line 294, in <module>
    file_infos[0].nodata[band])
TypeError: float argument required

Not an issue for me currently as the '-separate' mode I the exact thing I need, but I thought I'd report for the record.

Anyway - great tool! Thanks!

  Changed 2 years ago by Blackhex

Hello. I added a little patch that allows you to pass a very big list of input files in a text file. Futhermore, this patch adds a <SourceProperties> tag for each <Source>, so they don't have to be opened at VRT file openning to get needed informations. It's not bulletproof but it works well in my case.

Changed 2 years ago by Blackhex

Input file list and SourceProperties? patch.

  Changed 2 years ago by rouault

gdal_vrtmerge.py.diff applied in r17881 with a minor modification to use characterestics of band s_band instead of always band 1.

  Changed 7 months ago by rouault

  • status changed from new to closed
  • resolution set to fixed
Note: See TracTickets for help on using tickets.