TransWikia.com

Reading Gdal VRT format

Geographic Information Systems Asked by Majid Hojati on June 29, 2021

How can I read a gdal vrt file with GDALOpen function?

I have a vrt file built with gdalbuildvrt and I want to read it using GDALOpen but It returns a null dataset, Is it even possible?
In this code poDataset is null

GDALDataset  *poDataset;
        GDALAllRegister();

           poDataset = (GDALDataset *) GDALOpen( "home/m/3857/srtm_merged.vrt", GA_ReadOnly );
        if( poDataset != NULL )
        {

}

It seems vrt files are ony supported in a few gdals tools.

Here is VRT:

<VRTDataset rasterXSize="21746" rasterYSize="17369">
  <SRS>PROJCS["WGS 84 / Pseudo-Mercator",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]],PROJECTION["Mercator_1SP"],PARAMETER["central_meridian",0],PARAMETER["scale_factor",1],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["X",EAST],AXIS["Y",NORTH],EXTENSION["PROJ4","+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs"],AUTHORITY["EPSG","3857"]]</SRS>
  <GeoTransform>  5.0093307430080175e+06,  5.1196462744776348e+01,  0.0000000000000000e+00,  4.3927264476078171e+06,  0.0000000000000000e+00, -5.1196462744776348e+01</GeoTransform>
  <VRTRasterBand dataType="Int32" band="1">
    <NoDataValue>-9999</NoDataValue>
    <ColorInterp>Gray</ColorInterp>
    <ComplexSource>
      <SourceFilename relativeToVRT="1">1.tif</SourceFilename>
      <SourceBand>1</SourceBand>
      <SourceProperties RasterXSize="5344" RasterYSize="6593" DataType="Int32" BlockXSize="5344" BlockYSize="1" />
      <SrcRect xOff="0" yOff="0" xSize="5344" ySize="6593" />
      <DstRect xOff="0" yOff="0" xSize="3624.28574350654" ySize="4471.35402450199" />
      <NODATA>-9999</NODATA>
    </ComplexSource>
    <ComplexSource>
      <SourceFilename relativeToVRT="1">2.tif</SourceFilename>
      <SourceBand>1</SourceBand>
      <SourceProperties RasterXSize="5529" RasterYSize="6439" DataType="Int32" BlockXSize="5529" BlockYSize="1" />
      <SrcRect xOff="0" yOff="0" xSize="5529" ySize="6439" />
      <DstRect xOff="0" yOff="13147.5894347461" xSize="3624.84957383552" ySize="4221.45169215535" />
      <NODATA>-9999</NODATA>
    </ComplexSource>
    <ComplexSource>
      <SourceFilename relativeToVRT="1">3.tif</SourceFilename>
      <SourceBand>1</SourceBand>
      <SourceProperties RasterXSize="5470" RasterYSize="6489" DataType="Int32" BlockXSize="5470" BlockYSize="1" />
      <SrcRect xOff="0" yOff="0" xSize="5470" ySize="6489" />
      <DstRect xOff="10871.7953859191" yOff="4468.83771045391" xSize="10874.354045833" ySize="12900.1249366381" />
      <NODATA>-9999</NODATA>
    </ComplexSource>
    <ComplexSource>
      <SourceFilename relativeToVRT="1">4.tif</SourceFilename>
      <SourceBand>1</SourceBand>
      <SourceProperties RasterXSize="5344" RasterYSize="6593" DataType="Int32" BlockXSize="5344" BlockYSize="1" />
      <SrcRect xOff="0" yOff="0" xSize="5344" ySize="6593" />
      <DstRect xOff="10871.7953859191" yOff="0" xSize="3624.28574350655" ySize="4471.354024502" />
      <NODATA>-9999</NODATA>
    </ComplexSource>
  </VRTRasterBand>
</VRTDataset>

well to others may face the same problem, there must be a / at the beginning of vrt path

GDALDataset  *poDataset;
        GDALAllRegister();

           poDataset = (GDALDataset *) GDALOpen( "/home/m/3857/srtm_merged.vrt", GA_ReadOnly );
        if( poDataset != NULL )
        {

}

One Answer

well to others may face the same problem, there must be a / at the beginning of vrt path

    GDALDataset  *poDataset;
    GDALAllRegister();
            
    poDataset = (GDALDataset *) GDALOpen("/home/m/3857/srtm_merged.vrt",GA_ReadOnly );
    if( poDataset != NULL )
        {
        //Valid
        }

Correct answer by Majid Hojati on June 29, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP