2

Can you provide me with Python code to read metadata from a raster file?

3 Answers 3

6

Two options:

  1. Use GDAL Python bindings.
  2. Run GDALINFO from python and capture the stdout, to get a string with the metadata:

import os
metadata = os.popen('gdalinfo ../rasterfile.tiff').read()
print metadata
0
3

You could use gdalinfo: http://www.gdal.org/gdalinfo.html

0
from osgeo import gdal

filename=gdal.Open("file path")

metadata=filename.GetMetadata()

print(metadata)
1
  • Even if the answer is simple, coding answers should also contain words describing the solution (and, ideally, a documentation reference). "Wall of code" answers are likely to receive a similar response to "Wall of code" questions (down-voting and removal). Please take the Tour to get a better idea of how GIS SE operates.
    – Vince
    Jan 12, 2020 at 17:20

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