Repository: rasterio/rasterio

Issue:
Add `GetMetadataItem` like method 
Ref: https://github.com/mapbox/rasterio/issues/1077, 

I'm proposing to add a new method in https://github.com/mapbox/rasterio/blob/master/rasterio/_base.pyx to replicate GDAL GetMetadataItem


**Method Name:** `get_metadata_item` or `get_metadata`
**Why:** I need to be able to get TIFF metadata like `band.GetMetadataItem('IFD_OFFSET', 'TIFF')`

**Code:**

```cython
    def get_metadata(self, bidx, ns, dm=None, ovr=None):
        """Returns metadata item

        Parameters
        ----------
        bidx: int
            Band index, starting with 1.
        name: str
            The key for the metadata item to fetch.
        domain: str
            The domain to fetch for.
        ovr: int
            Overview level

        Returns
        -------
        str
        """
        cdef GDALMajorObjectH b = NULL
        cdef GDALMajorObjectH obj = NULL
        cdef char *value = NULL
        cdef const char *name = NULL
        cdef const char *domain = NULL

        ns = ns.encode('utf-8')
        name = ns

        if dm:
            dm = dm.encode('utf-8')
            domain = dm

        b = self.band(bidx)
        if ovr:
            b = GDALGetOverview(b, ovr)

        obj = b

        value = GDALGetMetadataItem(obj, name, domain)
        if value == NULL:
            return None
        else:
            return value
```

@sgillies I'm happy to submit a PR for that :-) 


Discussion:

Resolving patch:
diff --git a/rasterio/errors.py b/rasterio/errors.py
--- a/rasterio/errors.py
+++ b/rasterio/errors.py
@@ -86,3 +86,7 @@ class RasterioDeprecationWarning(UserWarning):
 
 class RasterBlockError(RasterioError):
     """Raised when raster block access fails"""
+
+
+class BandOverviewError(UserWarning):
+    """Raised when a band overview access fails."""


Test patch:
diff --git a/tests/data/cogeo.tif b/tests/data/cogeo.tif
new file mode 100644
Binary files /dev/null and b/tests/data/cogeo.tif differ
diff --git a/tests/test_tag_item.py b/tests/test_tag_item.py
new file mode 100644
--- /dev/null
+++ b/tests/test_tag_item.py
@@ -0,0 +1,34 @@
+#-*- coding: utf-8 -*-
+import logging
+import sys
+
+import pytest
+
+from .conftest import requires_gdal22
+
+import rasterio
+from rasterio.errors import BandOverviewError
+
+logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
+
+
+def test_get_tag_item():
+    with rasterio.open('tests/data/cogeo.tif') as src:
+        assert src.get_tag_item('INTERLEAVE', 'IMAGE_STRUCTURE') == 'PIXEL'
+
+
+@requires_gdal22(reason="Access to IFD tags requires GDAL 2.2+")
+def test_get_tag_item_Tiff():
+    with rasterio.open('tests/data/cogeo.tif') as src:
+        assert src.get_tag_item('IFD_OFFSET', 'TIFF', bidx=1) == '8'
+        assert src.get_tag_item('IFD_OFFSET', 'TIFF', bidx=1, ovr=1) == '1504'
+        assert not src.get_tag_item('IF', 'TIFF', bidx=1)
+        with pytest.raises(Exception):
+            src.get_tag_item('IFD_OFFSET', 'TIFF', ovr=1)
+
+
+@requires_gdal22(reason="Access to IFD tags requires GDAL 2.2+")
+def test_get_tag_item_noOverview():
+    with rasterio.open('tests/data/rgb3.tif') as src:
+        with pytest.raises(BandOverviewError):
+            src.get_tag_item('IFD_OFFSET', 'TIFF', bidx=1, ovr=1)