Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#6767 closed defect (fixed)

VRT XML in xml:VRT metadata recurses

Reported by: warmerdam Owned by: Even Rouault
Priority: normal Milestone: 2.2.0
Component: GDAL_Raster Version: unspecified
Severity: normal Keywords: VRT
Cc:

Description

#!/usr/bin/env python

import sys

from osgeo import gdal


def auto_wrap(src_filename):
    ds = gdal.Open(src_filename)
    vrt_ds = gdal.GetDriverByName('VRT').CreateCopy('/vsimem/x.vrt', ds)
    print vrt_ds.GetMetadata('xml:VRT')[0]


if __name__ == '__main__':
    print auto_wrap(sys.argv[1])

Gives the following. Note the entire extra copy of the VRT XML within the xml:VRT domain. This appears to be because the VRTDataset::GetMetadata() method inserts it's xml:VRT results into the metadata cache. So this gets populated when GetMetadata() is first called (in CreateCopy()), and then later requests result in this problem. I'd suggest GetMetadata() not cache the result in the parent object, but generate generate it on each call (I'm not sure if this complicates the lifetime for the returned string list).

<VRTDataset rasterXSize="512" rasterYSize="512">
  <SRS>PROJCS["NAD27 / UTM zone 11N",GEOGCS["NAD27",DATUM["North_American_Datum_1927",SPHEROID["Clarke 1866",6378206.4,294.9786982138982,AUTHORITY["EPSG","7008"]],AUTHORITY["EPSG","6267"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4267"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-117],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","26711"]]</SRS>
  <GeoTransform>  4.4072000000000000e+05,  6.0000000000000000e+01,  0.0000000000000000e+00,  3.7513200000000000e+06,  0.0000000000000000e+00, -6.0000000000000000e+01</GeoTransform>
  <Metadata>
    <MDI key="AREA_OR_POINT">Area</MDI>
    <MDI key="COLORSPACE">GREYSCALE</MDI>
    <MDI key="COMPRESSION_RATE_TARGET">4</MDI>
    <MDI key="VERSION">1</MDI>
  </Metadata>
  <Metadata domain="xml:VRT" format="xml">
    <VRTDataset rasterXSize="512" rasterYSize="512">
      <SRS>PROJCS["NAD27 / UTM zone 11N",GEOGCS["NAD27",DATUM["North_American_Datum_1927",SPHEROID["Clarke 1866",6378206.4,294.9786982138982,AUTHORITY["EPSG","7008"]],AUTHORITY["EPSG","6267"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4267"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-117],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","26711"]]</SRS>
      <GeoTransform>4.4072000000000000e+05,  6.0000000000000000e+01,  0.0000000000000000e+00,  3.7513200000000000e+06,  0.0000000000000000e+00, -6.0000000000000000e+01</GeoTransform>
      <Metadata>
        <MDI key="AREA_OR_POINT">Area</MDI>
        <MDI key="COLORSPACE">GREYSCALE</MDI>
        <MDI key="COMPRESSION_RATE_TARGET">4</MDI>
        <MDI key="VERSION">1</MDI>
      </Metadata>
      <VRTRasterBand dataType="Byte" band="1">
        <Description>Grayscale</Description>
        <ColorInterp>Gray</ColorInterp>
        <SimpleSource>
          <SourceFilename relativeToVRT="0">utm.tif</SourceFilename>
          <SourceBand>1</SourceBand>
          <SourceProperties RasterXSize="512" RasterYSize="512" DataType="Byte" BlockXSize="512" BlockYSize="16" />
          <SrcRect xOff="0" yOff="0" xSize="512" ySize="512" />
          <DstRect xOff="0" yOff="0" xSize="512" ySize="512" />
        </SimpleSource>
      </VRTRasterBand>
    </VRTDataset>
  </Metadata>
  <VRTRasterBand dataType="Byte" band="1">
    <Description>Grayscale</Description>
    <ColorInterp>Gray</ColorInterp>
    <SimpleSource>
      <SourceFilename relativeToVRT="0">utm.tif</SourceFilename>
      <SourceBand>1</SourceBand>
      <SourceProperties RasterXSize="512" RasterYSize="512" DataType="Byte" BlockXSize="512" BlockYSize="16" />
      <SrcRect xOff="0" yOff="0" xSize="512" ySize="512" />
      <DstRect xOff="0" yOff="0" xSize="512" ySize="512" />
    </SimpleSource>
  </VRTRasterBand>
</VRTDataset>

Change History (2)

comment:1 by Even Rouault, 7 years ago

Resolution: fixed
Status: newclosed

In 37069:

VRT: avoid recursion in xml:VRT metadata (fixes #6767)

comment:2 by Even Rouault, 7 years ago

Milestone: 2.2.0

Note: not appropriate as such for backport as it has a potential ABI impact

Note: See TracTickets for help on using tickets.