1

I'm trying a simple code to read a tif file using gdal in databricks but the output is NoneType. Is it dfbs limitation?

from osgeo import gdal

filepath = "dbfs:/FileStore/tables/myraster.tif"
raster = gdal.Open(filepath)

I get the below error:

RuntimeError: dbfs:/FileStore/tables/myraster.tif: No such file or directory

I have tested the file reading it as image and it works fine:

dfRaw = spark.read.format("image").load(filepath)
Rio
  • 398
  • 2
  • 15

1 Answers1

1

because gdal uses Python file API, it can't work with dbfs:/ URLs. Instead you need to replace dbfs: with /dbfs if you're on full Databricks workspace:

from osgeo import gdal

filepath = "/dbfs/FileStore/tables/myraster.tif"
raster = gdal.Open(filepath)

Or use dbutils.fs.cp on Community Edition (see this answer)

Alex Ott
  • 80,552
  • 8
  • 87
  • 132