6

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
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Mar 18, 2018 at 18:35
1
  • Yes! That did it (as long as the "1" is in quotes). If you post this as an answer I will accept, thanks. Commented Mar 19, 2018 at 20:44

1 Answer 1

7

You can do this by passing a dict:

ds.SetMetadata({"X_BAND": "1" }, "GEOLOCATION")
answered Mar 19, 2018 at 21:04

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.