Skip to content

Commit

Permalink
catch and explain GDAL calc errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sllynn committed Nov 29, 2024
1 parent 58c3ba5 commit ccc98c8
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import com.databricks.labs.mosaic.core.raster.gdal.{MosaicRasterGDAL, MosaicRast
import com.databricks.labs.mosaic.utils.SysUtils
import org.gdal.gdal.gdal

import java.nio.file.{Files, Paths}
import scala.util.Try

/** GDALCalc is a helper object for executing GDAL Calc commands. */
object GDALCalc {

Expand Down Expand Up @@ -35,6 +38,14 @@ object GDALCalc {
val toRun = effectiveCommand.replace("gdal_calc", gdal_calc)
val commandRes = SysUtils.runCommand(s"python3 $toRun")
val errorMsg = gdal.GetLastErrorMsg
val size = Try(Files.size(Paths.get(resultPath))).getOrElse(
{
val msg = "Error during GDAL calc operation: " +
s"file $resultPath " +
s"with command '$effectiveCommand'. GDAL returned error: $errorMsg"
throw new Exception(msg)
}
)
val result = GDAL.raster(resultPath, resultPath, None)
val createInfo = Map(
"path" -> resultPath,
Expand Down

0 comments on commit ccc98c8

Please sign in to comment.