[gdal-dev] Issue with using GDAL warp

Andrew C Aitchison andrew at aitchison.me.uk
Sun Mar 24 12:33:04 PDT 2024


On Sun, 24 Mar 2024, Ian Hannah via gdal-dev wrote:

> Hi,
>
> I am using 3.8.4  of GDAL .NET and running this code:
>
>                    string[] warpOptions =
>                    {
>                        "outputType", GdalConst.GDT_Byte.ToString(),
>                        "srcSRS", projectionWKT,
>                        "dstSRS", "EPSG:3857",
>                        "accessMode", "overwrite"
>                    };
>
>                    string geoTiffOutputFileName = Path.GetTempFileName();
>                    string pngOutputFileName = convertToImage ? Path.GetTempFileName() : null;
>
>                    try
>                    {
>                        GDALVectorTranslateOptions gdalWarpOptions = new GDALVectorTranslateOptions(warpOptions);
>
>                        using (Dataset outputDataset = Gdal.wrapper_GDALVectorTranslateDestName(geoTiffOutputFileName, dataset, gdalWarpOptions, null, null))
>                        {
>                            if (convertToImage)
>                            {
>                                string[] translateOptions = { "-of", "PNG" };
>                                using (Gdal.wrapper_GDALTranslate(pngOutputFileName, outputDataset, new GDALTranslateOptions(translateOptions), null, null)) { }
>                            }
>                        }
>                  }
>
> And on the call to Gdal.wrapper_GDALVectorTranslateDestName I get the following error:
>
> System.ApplicationException: 'Cannot guess driver for F:\Temp\2\tmp7A67.tmp'
>
> This is in the generation of the geoTiffOutputFileName file.
>
> Does anyone know why I am getting this error?

You are trying to overwrite the file, which often means to put new data
into an existing file. But since it is a tmp file I guess that it does not 
yet exist, so GDAL cannot read it to work out what format it is in.

Nowhere do you say what format outputDataset should have.

Maybe declaring the output file format would stop this error.

Unless you actual want a tiff and a png of the result,
maybe you don't actually need the call to Gdal.wrapper_GDALTranslate ?

-- 
Andrew C. Aitchison                      Kendal, UK
                    andrew at aitchison.me.uk


More information about the gdal-dev mailing list