简体   繁体   English

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

[英]C# and GDAL implementation - Dataset not returning a value

I am trying to automate a simple geotiff to KMZ process using GDAL and C#我正在尝试使用 GDAL 和 C# 自动化一个简单的 geotiff 到 KMZ 过程

The code I have written is a little buggy and I am having a lot of trouble working out how to use the API.我写的代码有点问题,我在弄清楚如何使用 API 时遇到了很多麻烦。 I am hoping this is a simple fix for more advanced developers.我希望这对更高级的开发人员来说是一个简单的修复。

My code is as follows:我的代码如下:

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, null);


        }
    }
}

I am getting a null return value on the vrtDataset variable and (i think) as a result, I am getting a null reference error when I call the Gdal.wrapperGDALTranslate method.我在 vrtDataset 变量上收到 null 返回值,并且(我认为)因此,当我调用 Gdal.wrapperGDALTranslate 方法时,我收到 null 参考错误。

Any help appreciated.任何帮助表示赞赏。 Thanks.谢谢。

It needed,它需要,

Gdal.AllRegister(); Gdal.AllRegister();

and an absolute path to the VRT file being created.以及正在创建的 VRT 文件的绝对路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM