Re: How to specify the name of the input files with the geographical metadata?
On Tue, Feb 23, 2021 at 9:28 AM <juanjo.gomeznavarro@...> wrote:
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.
Opening your PNGs in "r+" mode and patching them, like
with rasterio.open("example.png", "r+") as dataset:
dataset.crs = rasterio.crs.CRS.from_epsg(3857)
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 https://gdal.org/drivers/raster/vrt.html. The XML string can then be opened by rasterio.
with rasterio.open("<VRTDataset>...</VRTDataset>") as dataset:
That's not a well known feature of GDAL/rasterio but I use it quite a bit.