Extracting metadata from raster (tif) file using python in Knime
Hi,
I would like to extract all metadata from a raster tif file. I know this can be done with a python script in knime. I am using the custom conda environment with GDAL, GeoPandas and pySAL packages installed. I am unsure how to adapt the below script so that I can extract the data in knime and get on with it to get round the fact that raster files are currently not supported in Knime. I have used this script below but could extract the data. Can anyone help with this? Thanks
import knime.scripting.io as knio
from osgeo import gdal
import pandas as pd
Open the raster file
raster = gdal.Open(r"C:\Users\XXXXXXXXXXX\Downloads\Panagos (2022) Soil erosion 2050\2050\RCP85.tif")
Check type of the variable ‘raster’
type(raster)
Projection
raster.GetProjection()
Dimensions
raster.RasterXSize
raster.RasterYSize
Number of bands
raster.RasterCount
Get the metadata
Get the metadata
raster.GetMetadata()
metadata = raster.GetMetadata()
Output the metadata as a pandas DataFrame
raster_df = pd.DataFrame(list(metadata.items()), columns=[‘Key’, ‘Value’])
Output the DataFrame to the output table
knio.outputtables[0] = knio.Table.frompandas(raster_df)