7

I once have used gdalbuildvrt on georeferenced images. That was okay when images did not overlap, It was also time efficient compared to gdal_merge or gdal_warp. Now I have overlapping images and gdalbuildvrt is a little problematic to me. Let me explain: For the testing purposes I have one image named 0.jpg(1600*900). I use the following command to georeference 0.jpg.

gdal_translate -a_srs EPSG:4326 -co interleave=pixel -a_ullr -180.0 90.0 180.0 -90.0 0.jpg ONE.tif

To see how it will merge overlapping areas I type the following:

gdal_translate -a_srs EPSG:4326 -co interleave=pixel -a_ullr -90.0 90.0 90.0 -90.0 0.jpg TWO.tif

So what I expect when I merge ONE.tif and TWO.tif is TWO.tif fills the center of the picture. Finally, I use gdalbuildvrt on these two:gdalbuildvrt -input_file_list LIST.txt ONETWO.vrt, and then gdal_translate ONETWO.vrt ONETWO.tif

My LIST.txt consists of two lines: first ONE.tif then TWO.tif. The problem is here. 0.jpg was 1600*900 pixels. So I expect ONETWO.tif to be 1600*900 pixels-- ONE.tif covering from -180 to +180, and TWO.tif overwriting from -90 to +90. Although TWO.tif covers the center in the result, the final image is 2133*900 pixels. Why is this happening? Of course, I can use -outsize on gdal_translate to restore the original resolution but I am not sure if it is the right way to solve this.

On the other hand, gdal_merge is also an alternative, giving me what I want(not changing the original resolution) but it is likely that it will take longer compared to gdalbuildvrt.

I use GDAL 2.2.0, released on 2017/04/28 on OSGeo4W64. Below is an example information stored in ONETWO.vrt. It is probably this area that needs to get modified.

<VRTRasterBand dataType="Byte" band="1"> <ColorInterp>Red</ColorInterp> <SimpleSource> <SourceFilename relativeToVRT="1">ONE.tif</SourceFilename> <SourceBand>1</SourceBand> <SourceProperties RasterXSize="1600" RasterYSize="900" DataType="Byte" BlockXSize="1600" BlockYSize="1" /> <SrcRect xOff="0" yOff="0" xSize="1600" ySize="900" /> <DstRect xOff="0" yOff="0" xSize="2133.33333333333" ySize="900" /> </SimpleSource> <SimpleSource> <SourceFilename relativeToVRT="1">TWO.tif</SourceFilename> <SourceBand>1</SourceBand> <SourceProperties RasterXSize="1600" RasterYSize="900" DataType="Byte" BlockXSize="1600" BlockYSize="1" /> <SrcRect xOff="0" yOff="0" xSize="1600" ySize="900" /> <DstRect xOff="533.333333333333" yOff="0" xSize="1066.66666666667" ySize="900" /> </SimpleSource> </VRTRasterBand>

Why are the destination coordinates messed up like 533.3333 or 2133.3333? And, is there a way to use gdalbuildvrt on overlapping images just like gdal_merge?

1
  • Sounds like a bug to me. Which gdal version? What if you change ONE.tif>DstRect>xSize from 2133.33333333333 to 1600. And TWO.tif>DstRect>xOff from 533.3333 to 400 and xSize from 1066.66666666667 to 800?
    – pLumo
    Jun 26, 2017 at 7:27

1 Answer 1

4

You should read again the document page or gdalbuildvrt http://www.gdal.org/gdalbuildvrt.html. Pay attention to parameter called "resolution"

-resolution {highest|lowest|average|user}:

In case the resolution of all input files is not the same, the -resolution flag enables the user to control the way the output resolution is computed. 'average' is the default. 'highest' will pick the smallest values of pixel dimensions within the set of source rasters. 'lowest' will pick the largest values of pixel dimensions within the set of source rasters. 'average' will compute an average of pixel dimensions within the set of source rasters. 'user' is new in GDAL 1.7.0 and must be used in combination with the -tr option to specify the target resolution.

With your workflow you can verify with gdalinfo that the image ONE.tif has pixel size

Pixel Size = (0.2250,-0.2000)

and TWO.tif has pixel size

Pixel Size = (0.1125,-0.2000)

By running gdalbuildvrt with setting -resolution parameter either to "average" which is the default, "highest", or "lowest", you will get a .vrt file with pixel size of the first axis either 0.16875, 0.1125, or 0.2250, respectively.

You wrote "giving me what I want(not changing the original resolution)" but it is not possible because you have two different original resolutions in your source data.

2
  • Thanks, you are right. What I meant by "original resolution" should have been "size". In my case "-resolution lowest" has worked if anyone wonders . Jun 26, 2017 at 16:34
  • Also, I always took resolution as in "screen resolution", like 1600*900--just two numbers denoting how many pixels there are. With that in my mind I thought my input files had the same resolution, and I had nothing to do with -resolution flag. But georeferencing affects the resolution after all, I understand that now, thanks. Jun 26, 2017 at 16:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.