Arshak
Arshak

Reputation: 726

How to convert png files to geotiff

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.

Upvotes: 2

Views: 1912

Answers (1)

Arshak
Arshak

Reputation: 726

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)

Upvotes: 5

Related Questions