5

When I read a raster in with rasterio (version 0.36.0) in Python, I can call up the metadata in two ways:

src = rasterio.open(my_raster)

src.profile

{'affine': Affine(1.0, 0.0, 401900.0, 0.0, -1.0, 7620200.0),
'count': 1,  'crs': CRS({'init': 'epsg:32606'}),  'driver': 'GTiff',
'dtype': 'float32',  'height': 11100,  'interleave': 'band',
'nodata': -9999.0,  'tiled': False,
'transform': (401900.0, 1.0, 0.0, 7620200.0, 0.0, -1.0),  'width': 13750}

src.meta

{'affine': Affine(1.0, 0.0, 401900.0, 0.0, -1.0, 7620200.0),
'count': 1,  'crs': CRS({'init': 'epsg:32606'}),  'driver': 'GTiff',
'dtype': 'float32',  'height': 11100,  'nodata': -9999.0,
'transform': (401900.0, 1.0, 0.0, 7620200.0, 0.0, -1.0),  'width': 13750}

The results are quite similar, but profile stores a little more information such as the tiling and interleave information. Which of these methods is a better practice for retrieving metadata? Are there examples where one is better than the other? Both 'meta' and 'profile' seem to work fine right now for writing the single band float32 raster I am working with.

7

The meta property contains the basic raster metadata. The profile property is a super set of meta and dataset creation options (i.e inc. tiling, block size, compression etc...).

You would use src.profile when you want to ensure you create an exact (empty) clone of an existing dataset. And it is especially useful when you are reading in block windows from a very large raster, then writing the chunks back out to your new raster as it is a lot faster if the input and output rasters have the same block layout.

Further info:

  • thanks for the answer. I followed up on the links. I think I will make a habit of using the profile option from here on out. – Charlie Parr May 17 '18 at 8:17

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.