2

I have set of png files and EPSG:3006 coordinates of the edges of each file. How can I convert those png files to geotiff files using Python so the tiff files would contain the geo metadata.
I guess it can be done with Rasterio lib, but I'm not sure how exactly.

Arshak
  • 716
  • 2
  • 7
  • 15

1 Answers1

5

found the solution:

dataset = rasterio.open(input_file_path, 'r')
bands = [1, 2, 3]
data = dataset.read(bands)
transform = rasterio.transform.from_bounds(west, south, east, north, data.shape[1], data.shape[2])
crs = {'init': 'epsg:3006'}

_, height, width = data.shape
with rasterio.open(output_file_path, 'w', driver='GTiff',
                   width=width, height=height,
                   count=3, dtype=data.dtype, nodata=0,
                   transform=transform, crs=crs) as dst:
    dst.write(data, indexes=bands)
patkru
  • 70
  • 7
Arshak
  • 716
  • 2
  • 7
  • 15
  • it should be `_, height, width` instead of `_, width, height`, here's explanation in [rasterio docs](https://rasterio.readthedocs.io/en/latest/topics/image_processing.html) – patkru Apr 10 '23 at 21:18