1

I have vrt files generated using gdalbuildvrt that reference GeoTiffs referenced using the NZTM coordinate system.

Is there an easy way to determine the bounds as WGS84 latitude longitude coordinates?

I assume this should be possible with a few GDAL commands from the command line prompt.

Example vrt file:

<?xml version="1.0" encoding="UTF-8"?>
    <VRTDataset rasterXSize="11340" rasterYSize="8505">
       <SRS>PROJCS["New Zealand Transverse Mercator 2000; NZGD 2000",GEOGCS["unknown",DATUM["unknown",SPHEROID["GRS 1980",6378137,298.2572221010002,AUTHORITY["EPSG","7019"]]],PRIMEM["Greenwich",0],UNIT[,0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",173],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",1600000],PARAMETER["false_northing",10000000],UNIT["metre",1,AUTHORITY["EPSG","9001"]]]</SRS>
       <GeoTransform>1.0839978833333333e+006, 4.2333333333333298e+000, 0.0000000000000000e+000, 4.9020021166666662e+006, 0.0000000000000000e+000,-4.2333333333333298e+000</GeoTransform>
       <VRTRasterBand dataType="Byte" band="1">
          <HideNoDataValue>1</HideNoDataValue>
          <ColorInterp>Red</ColorInterp>
          <SimpleSource>
             <SourceFilename relativeToVRT="1">CF04_GeoTifv1-02.tif</SourceFilename>
             <SourceBand>1</SourceBand>
             <SourceProperties RasterXSize="5671" RasterYSize="8505" DataType="Byte" BlockXSize="5671" BlockYSize="17" />
             <SrcRect xOff="0" yOff="0" xSize="5671" ySize="8505" />
             <DstRect xOff="0" yOff="0" xSize="5671" ySize="8505" />
          </SimpleSource>
          <SimpleSource>
             <SourceFilename relativeToVRT="1">CF05_GeoTifv1-01.tif</SourceFilename>
             <SourceBand>1</SourceBand>
             <SourceProperties RasterXSize="5671" RasterYSize="8505" DataType="Byte" BlockXSize="5671" BlockYSize="17" />
             <SrcRect xOff="0" yOff="0" xSize="5671" ySize="8505" />
             <DstRect xOff="5669" yOff="0" xSize="5671" ySize="8505" />
          </SimpleSource>
       </VRTRasterBand>
       <VRTRasterBand dataType="Byte" band="2">
          <HideNoDataValue>1</HideNoDataValue>
          <ColorInterp>Green</ColorInterp>
          <SimpleSource>
             <SourceFilename relativeToVRT="1">CF04_GeoTifv1-02.tif</SourceFilename>
             <SourceBand>2</SourceBand>
             <SourceProperties RasterXSize="5671" RasterYSize="8505" DataType="Byte" BlockXSize="5671" BlockYSize="17" />
             <SrcRect xOff="0" yOff="0" xSize="5671" ySize="8505" />
             <DstRect xOff="0" yOff="0" xSize="5671" ySize="8505" />
          </SimpleSource>
          <SimpleSource>
             <SourceFilename relativeToVRT="1">CF05_GeoTifv1-01.tif</SourceFilename>
             <SourceBand>2</SourceBand>
             <SourceProperties RasterXSize="5671" RasterYSize="8505" DataType="Byte" BlockXSize="5671" BlockYSize="17" />
             <SrcRect xOff="0" yOff="0" xSize="5671" ySize="8505" />
             <DstRect xOff="5669" yOff="0" xSize="5671" ySize="8505" />
          </SimpleSource>
       </VRTRasterBand>
       <VRTRasterBand dataType="Byte" band="3">
          <HideNoDataValue>1</HideNoDataValue>
          <ColorInterp>Blue</ColorInterp>
          <SimpleSource>
             <SourceFilename relativeToVRT="1">CF04_GeoTifv1-02.tif</SourceFilename>
             <SourceBand>3</SourceBand>
             <SourceProperties RasterXSize="5671" RasterYSize="8505" DataType="Byte" BlockXSize="5671" BlockYSize="17" />
             <SrcRect xOff="0" yOff="0" xSize="5671" ySize="8505" />
             <DstRect xOff="0" yOff="0" xSize="5671" ySize="8505" />
          </SimpleSource>
          <SimpleSource>
             <SourceFilename relativeToVRT="1">CF05_GeoTifv1-01.tif</SourceFilename>
             <SourceBand>3</SourceBand>
             <SourceProperties RasterXSize="5671" RasterYSize="8505" DataType="Byte" BlockXSize="5671" BlockYSize="17" />
             <SrcRect xOff="0" yOff="0" xSize="5671" ySize="8505" />
             <DstRect xOff="5669" yOff="0" xSize="5671" ySize="8505" />
          </SimpleSource>
       </VRTRasterBand>
       <VRTRasterBand dataType="Byte" band="4">
          <ColorInterp>Alpha</ColorInterp>
          <ComplexSource>
             <SourceFilename relativeToVRT="1">CF04_GeoTifv1-02.tif</SourceFilename>
             <SourceBand>1</SourceBand>
             <SourceProperties RasterXSize="5671" RasterYSize="8505" DataType="Byte" BlockXSize="5671" BlockYSize="17" />
             <SrcRect xOff="0" yOff="0" xSize="5671" ySize="8505" />
             <DstRect xOff="0" yOff="0" xSize="5671" ySize="8505" />
             <ScaleOffset>255</ScaleOffset>
             <ScaleRatio>0</ScaleRatio>
          </ComplexSource>
          <ComplexSource>
             <SourceFilename relativeToVRT="1">CF05_GeoTifv1-01.tif</SourceFilename>
             <SourceBand>1</SourceBand>
             <SourceProperties RasterXSize="5671" RasterYSize="8505" DataType="Byte" BlockXSize="5671" BlockYSize="17" />
             <SrcRect xOff="0" yOff="0" xSize="5671" ySize="8505" />
             <DstRect xOff="5669" yOff="0" xSize="5671" ySize="8505" />
             <ScaleOffset>255</ScaleOffset>
             <ScaleRatio>0</ScaleRatio>
          </ComplexSource>
       </VRTRasterBand>
    </VRTDataset>

1 Answer 1

5

Convert the file to WGS84

gdalwarp in_test.vrt out_test.vrt -t_srs "+proj=longlat +ellps=WGS84"

Calculate the bbox with GDAL in Python

import gdal
    
ds = gdal.Open('out_test.vrt')

cols = ds.RasterXSize
rows = ds.RasterYSize

geotransform = ds.GetGeoTransform()
bb1 = originX = geotransform[0]
bb4 = originY = geotransform[3]

pixelWidth = geotransform[1]
pixelHeight = geotransform[5]

Width = cols*pixelWidth
Height = rows*pixelHeight

bb3 = originX+Width
bb2 = originY+Height

print str(bb1) + ',' + str(bb2) + ',' + str(bb3) + ',' + str(bb4)

Which results in a bbox for your sample file

>>> 166.31571873,-46.1983972613,166.969160112,-45.841900527
0

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.