C#和GDAL实现-数据集未返回值

我正在尝试使用GDAL和C#将一个简单的geotiff自动化到KMZ过程

我编写的代码有点漏洞,在确定如何使用API​​时遇到很多麻烦。我希望这是更高级的开发人员的简单解决方案。

我的代码如下:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OSGeo.GDAL;

namespace TestingTIFFtoKMZ
{
    class Program
    {
        static void Main(string[] args)
        {


            string outputName = Environment.CurrentDirectory + @"\BR01899_Mackenzie_09_EXPORT";
            string vrtfile = outputName + @"\tempMosaic.vrt";
            string filenameKMZ = outputName + @"\" + Environment.CurrentDirectory + ".kmz";
            string[] tiffFiles = Directory.GetFiles(outputName,"*.tif");

            var vrtOptions = new GDALBuildVRTOptions(new[] { "-overwrite" });

            GDALTranslateOptions transOptions = new GDALTranslateOptions(new[] { "-of","KMLSUPEROVERLAY","-co","format=png" });

            Dataset vrtdataset = Gdal.wrapper_GDALBuildVRT_names(vrtfile,tiffFiles,vrtOptions,null,null);
            // vrtdataset.Dispose();

            Gdal.wrapper_GDALTranslate(filenameKMZ,vrtdataset,transOptions,null);


        }
    }
}

我在vrtdataset变量上获得了一个空返回值,并且(我认为)结果是,当我调用Gdal.wrapperGDALTranslate方法时,我得到了一个空引用错误。

任何帮助表示赞赏。谢谢。

tc8030 回答:C#和GDAL实现-数据集未返回值

需要,

Gdal.AllRegister();

以及要创建的VRT文件的绝对路径。

本文链接:https://www.f2er.com/3153749.html

大家都在问