Opened 14 years ago

Closed 10 years ago

#1985 closed enhancement (fixed)

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 (2)

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

Download all attachments as: .zip

Change History (8)

Changed 14 years ago by vincentschut

Attachment: gdal_vrtmerge.py added

comment:1 Changed 14 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' %

comment:2 in reply to:  1 Changed 14 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.

comment:3 Changed 13 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!

comment:4 Changed 12 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 12 years ago by Blackhex

Attachment: gdal_vrtmerge.py.diff added

Input file list and SourceProperties? patch.

comment:5 Changed 12 years ago by Even Rouault

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

comment:6 Changed 10 years ago by Even Rouault

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.