I have two files. One is PNG and the other is TIFF (or .jp2). I want to read geospatial data from the satellite image (.jp2 or .tif) and "put it in" the png file, then save it as a new tif.
I'm very new to working with raster data. I'm using rasterio and so far I've managed to get the meta of a tif file:
import rasterio as rio
tif = rio.open("TIFFile.tif")
png = rio.open("PNGFile.png")
tif_read = tif.read()
png_read = png.read()
tif_width = tif.width
tif_height = tif.height
tif_dim = (tif_width, tif_height)
png_width = png.width
png_height = png.height
png_dim = (png_width, png_height)
tif_meta = tif.meta
png_meta = png.meta
print("TIF META: ", tif_meta)
print("PNG META: ", png_meta)
Output:
TIF META: {'driver': 'GTiff', 'dtype': 'float32', 'nodata': None, 'width': 10980, 'height': 10980, 'count': 4, 'crs': CRS.from_epsg(32635), 'transform': Affine(10.0, 0.0, 699965.0,
0.0, -10.0, 4100035.0)}
PNG META: {'driver': 'GTiff', 'dtype': 'float32', 'nodata': None, 'width': 5490, 'height': 5490, 'count': 1, 'crs': None, 'transform': Affine(1.0, 0.0, 0.0,
0.0, 1.0, 0.0)}
I know I can create a new tif file using original tif's meta like this:
with rio.open('NEWTIF.tif', 'w', **tif_meta) as dst:
dst.write(tif_read.astype(rio.float32))
In light of this, basically, I'd like to know how to create a new tif file adding another tif's meta into a png file - merging png's raster data with tif's geospatial data.
I've been searching for this but couldn't understood what I've found in SO:
How to convert png files to geotiff https://gis.stackexchange.com/questions/371065/apply-same-coordinate-system-to-raster-image-and-geojson-with-rasterio https://gis.stackexchange.com/questions/379027/georeferencing-of-png-and-convert-to-tiff-using-python
How to achieve this?