Re: How to specify the name of the input files with the geographical metadata?

Sean Gillies


On Tue, Feb 23, 2021 at 9:28 AM <juanjo.gomeznavarro@...> wrote:
Good morning,

I'm working with PNG files, and the metadata is stored in two separate files: .pgw and .png.aux.xml. Currently I'm forced to use the same name for the three files, i.e. the image and the two auxiliary files with the geographical information. This is cumbersome and inconvenient, because I have a set of images that share the same georeferentiation and currently I'm forced to clone the .pgw and .png.aux.xml files in a somewhat silly way for introducing each image. Is there a way to tell that the two files with the metadata are named different from the PNG image?

Thanks a lot!

The naming of the auxiliary files is a GDAL convention and cannot, to my knowledge, be changed. Neither does rasterio allow a user to open an image in read only mode and add or replace the spatial referencing and other metadata. I agree that would be handy in your case. 

Workarounds include:

Opening your PNGs in "r+" mode and patching them, like

with"example.png", "r+") as dataset: =
    dataset.transform = rasterio.transform.Affine.translation(ulx, uly) * rasterio.transform.Affine.scale(dx, -dy)

Note that this would produce .pgw and .png.aux.xml files on your system.

Or you could make a generic VRT XML wrapper template and substitute PNG paths into it. See The XML string can then be opened by rasterio.

with"<VRTDataset>...</VRTDataset>") as dataset:

That's not a well known feature of GDAL/rasterio but I use it quite a bit.

Sean Gillies

Join to automatically receive all group messages.