0

I'm trying to set geolocation metadata in a gdal vrt with python bindings.

ds = gdal.Open('foo')
ds.SetMetadata ({'X_BAND' : '1'})
gdal.BuildVRT('bar', ds)

Results in a vrt with the following metadata

<Metadata>
<MDI key="X_BAND">1</MDI>
</Metadata>

However, I need the metadata to read:

<Metadata domain="GEOLOCATION">
<MDI key="X_BAND">1</MDI>
</Metadata>

I'm able to accomplish this using ds.SetMetaDataItem("X_BAND", "1", "geolocation") but would like to know how to do it with gdal.SetMetadata

I know the problem is with my failure to understand how swig is translating the python to the C++ so hopefully someone can quickly fix my syntax. From http://gdal.org/python/

SetMetadata(self, *args)
SetMetadata(self, char papszMetadata, char pszDomain = "") -> CPLErr   
SetMetadata(self, char pszMetadataString, char pszDomain = "") -> CPLErr
  • Try passing a dict - ds.SetMetadata({"X_BAND": 1}, "GEOLOCATION") – user2856 Mar 19 '18 at 9:04
  • Yes! That did it (as long as the "1" is in quotes). If you post this as an answer I will accept, thanks. – bbuzz31 Mar 19 '18 at 20:44
0

You can do this by passing a dict:

ds.SetMetadata({"X_BAND": "1" }, "GEOLOCATION")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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