Opened 7 years ago

Closed 7 years ago

#6766 closed defect (wontfix)

gdalbuildvrt doesn't work from command line, only in qgis

Reported by: saultdon Owned by: warmerdam
Priority: normal Milestone:
Component: Utilities Version: 2.1.2
Severity: blocker Keywords:
Cc:

Description

Getting some odd behaviour merging some dems with gdalbuildvrt.

From the command line on Linux or Windows I use:

gdalbuildvrt output/cded_dem.vrt input/*.dem

The output vrt on both systems only contain NaN values (all black raster).

If I use QGIS through Raster > Miscellaneous > Build Virtal Raster (Catalog) tool, and select either option Use visible raster layers as input or Choose input directory instead of files then it works with expected output.

DEMs I'm using are available as open data at https://pub.data.gov.bc.ca/datasets/175624/ so feel free to download any amount required for testing.

Running GDAL 2.1.r37067 built from source code at github based on current release.

Change History (4)

comment:1 by Even Rouault, 7 years ago

I cannot reproduce on Linux with latest 2.1:

wget https://pub.data.gov.bc.ca/datasets/175624/102i/102i08_e.dem.zip 
wget https://pub.data.gov.bc.ca/datasets/175624/102i/102i08_w.dem.zip
unzip 102i08_e.dem.zip
unzip 102i08_w.dem.zip
mkdir input
mv *.dem input
mkdir output
gdalbuildvrt output/cded_dem.vrt input/*.dem
$ gdalinfo -mm output/cded_dem.vrt
Driver: VRT/Virtual Raster
Files: output/cded_dem.vrt
       input/102i08_e.dem
       input/102i08_w.dem
Size is 2401, 1201
Coordinate System is:
GEOGCS["NAD83",
    DATUM["North_American_Datum_1983",
        SPHEROID["GRS 1980",6378137,298.257222101,
            AUTHORITY["EPSG","7019"]],
        TOWGS84[0,0,0,0,0,0,0],
        AUTHORITY["EPSG","6269"]],
    PRIMEM["Greenwich",0,
        AUTHORITY["EPSG","8901"]],
    UNIT["degree",0.0174532925199433,
        AUTHORITY["EPSG","9108"]],
    AUTHORITY["EPSG","4269"]]
Origin = (-128.500104166666659,50.500104166666667)
Pixel Size = (0.000208333333333,-0.000208333333333)
Corner Coordinates:
Upper Left  (-128.5001042,  50.5001042) (128d30' 0.37"W, 50d30' 0.37"N)
Lower Left  (-128.5001042,  50.2498958) (128d30' 0.37"W, 50d14'59.63"N)
Upper Right (-127.9998958,  50.5001042) (127d59'59.63"W, 50d30' 0.37"N)
Lower Right (-127.9998958,  50.2498958) (127d59'59.63"W, 50d14'59.63"N)
Center      (-128.2500000,  50.3750000) (128d15' 0.00"W, 50d22'30.00"N)
Band 1 Block=128x128 Type=Int16, ColorInterp=Undefined
    Computed Min/Max=0.000,406.000
  NoData Value=-32767

comment:2 by saultdon, 7 years ago

Maybe this is a QGIS issue...

WIth GDAL at command line:

saultdon@archasus ~/GIS/Data/bcgov/cded/250k % gdalbuildvrt _results/cded_102i08.vrt _extracted/102i08*.dem
saultdon@archasus ~/GIS/Data/bcgov/cded/250k % gdalinfo -mm _results/cded_102i08.vrt
Driver: VRT/Virtual Raster
Files: _results/cded_102i08.vrt
       _extracted/102i08_e.dem
       _extracted/102i08_w.dem
Size is 2401, 1201
Coordinate System is:
GEOGCS["NAD83",
    DATUM["North_American_Datum_1983",
        SPHEROID["GRS 1980",6378137,298.257222101,
            AUTHORITY["EPSG","7019"]],
        TOWGS84[0,0,0,0,0,0,0],
        AUTHORITY["EPSG","6269"]],
    PRIMEM["Greenwich",0,
        AUTHORITY["EPSG","8901"]],
    UNIT["degree",0.0174532925199433,
        AUTHORITY["EPSG","9122"]],
    AUTHORITY["EPSG","4269"]]
Origin = (-128.500104166666659,50.500104166666667)
Pixel Size = (0.000208333333333,-0.000208333333333)
Corner Coordinates:
Upper Left  (-128.5001042,  50.5001042) (128d30' 0.37"W, 50d30' 0.37"N)
Lower Left  (-128.5001042,  50.2498958) (128d30' 0.37"W, 50d14'59.63"N)
Upper Right (-127.9998958,  50.5001042) (127d59'59.63"W, 50d30' 0.37"N)
Lower Right (-127.9998958,  50.2498958) (127d59'59.63"W, 50d14'59.63"N)
Center      (-128.2500000,  50.3750000) (128d15' 0.00"W, 50d22'30.00"N)
Band 1 Block=128x128 Type=Int16, ColorInterp=Undefined
    Computed Min/Max=0.000,406.000
  NoData Value=-32767

From QGIS GUI:

saultdon@archasus ~/GIS/Data/bcgov/cded/250k % gdalinfo -mm _results/cded_102i08_qgis.vrt
Driver: VRT/Virtual Raster
Files: _results/cded_102i08_qgis.vrt
       /home/saultdon/GIS/Data/bcgov/cded/250k/_extracted/102i08_w.dem
       /home/saultdon/GIS/Data/bcgov/cded/250k/_extracted/102i08_e.dem
Size is 2401, 1201
Coordinate System is:
GEOGCS["NAD83",
    DATUM["North_American_Datum_1983",
        SPHEROID["GRS 1980",6378137,298.257222101,
            AUTHORITY["EPSG","7019"]],
        TOWGS84[0,0,0,0,0,0,0],
        AUTHORITY["EPSG","6269"]],
    PRIMEM["Greenwich",0,
        AUTHORITY["EPSG","8901"]],
    UNIT["degree",0.0174532925199433,
        AUTHORITY["EPSG","9122"]],
    AUTHORITY["EPSG","4269"]]
Origin = (-128.500104166666659,50.500104166666667)
Pixel Size = (0.000208333333333,-0.000208333333333)
Corner Coordinates:
Upper Left  (-128.5001042,  50.5001042) (128d30' 0.37"W, 50d30' 0.37"N)
Lower Left  (-128.5001042,  50.2498958) (128d30' 0.37"W, 50d14'59.63"N)
Upper Right (-127.9998958,  50.5001042) (127d59'59.63"W, 50d30' 0.37"N)
Lower Right (-127.9998958,  50.2498958) (127d59'59.63"W, 50d14'59.63"N)
Center      (-128.2500000,  50.3750000) (128d15' 0.00"W, 50d22'30.00"N)
Band 1 Block=128x128 Type=Int16, ColorInterp=Undefined
    Computed Min/Max=0.000,406.000
  NoData Value=-32767

Do you have time to test what the GDAL built vrt displays as in QGIS? Mine comes up all black.

Also noticed that if I try to compute the histogram in QGIS for the vrt built with GDAL, an error window pops up:

Exception
std::bad_array_new_length

Also notice the difference in the "Files:" portion where the GDAL generated VRT has relative paths, but the QGIS ones uses Absolute Paths.

They both contain the tag relativeToVRT="0" so I tried changing the GDAL one to relativeToVRT="1" and re-save then it works!

Last edited 7 years ago by saultdon (previous) (diff)

comment:3 by saultdon, 7 years ago

I also had to prefix the source file path with ../ along with relativeToVRT="1"

So in the end I had to modify the .vrt to go from:

<SourceFilename relativeToVRT="0">_extracted/102i08_e.dem</SourceFilename>

to:

<SourceFilename relativeToVRT="1">../_extracted/102i08_e.dem</SourceFilename>

comment:4 by Even Rouault, 7 years ago

Resolution: wontfix
Status: newclosed

OK, I see. As output/ and input/ have no direct hierarchical relationship, gdalbuildvrt use the paths directly. Technically this is correct if the output/cded_dem.vrt is opened from the directory where the gdalbuildvrt command line has been invoked, but this will not be the case from QGIS.

A solution is to force the use of absolute paths with:

gdalbuildvrt $PWD/output/cded_dem.vrt $PWD/input/*.dem

Note: See TracTickets for help on using tickets.