[gdal-dev] Issue with using GDAL warp

Ian Hannah Ian.Hannah at metasphere.co.uk
Sun Mar 24 13:23:49 PDT 2024


Hi,

If I change the options to this:

                    string[] warpOptions =
                    {
                        "srcSRS", projectionWKT,
                        "dstSRS", "EPSG:3857",
                        "format", "GTiff"
                    };

i.e. so specifying the output format and it still did not work (same error).

I do need to use the translate method because I trying to switch between 2 different projections.

Thanks
Ian

-----Original Message-----
From: Andrew C Aitchison <andrew at aitchison.me.uk> 
Sent: Sunday, March 24, 2024 7:33 PM
To: Ian Hannah <Ian.Hannah at metasphere.co.uk>
Cc: gdal-dev at lists.osgeo.org
Subject: Re: [gdal-dev] Issue with using GDAL warp

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