Ejemplo n.º 1
0
        public void RasterBand()
        {
            int nBlockXSize, nBlockYSize;
            var band = dataSet.GetRasterBand(1);

            band.GetBlockSize(out nBlockXSize, out nBlockYSize);
            var type        = Gdal.GetDataTypeName(band.DataType);
            var colorInterp = Gdal.GetColorInterpretationName(band.GetColorInterpretation());

            Console.WriteLine("Block={0}x{1} Type={2}, ColorInterp={3}",
                              nBlockXSize, nBlockYSize, type, colorInterp
                              );

            Assert.AreEqual(512, nBlockXSize);
            Assert.AreEqual(16, nBlockYSize);
            Assert.AreEqual("Byte", type);
            Assert.AreEqual("Gray", colorInterp);

            int bGotMin, bGotMax;

            double[] adfMinMax = new double[2];

            band.GetMinimum(out adfMinMax [0], out bGotMin);
            band.GetMaximum(out adfMinMax [1], out bGotMax);
            if (!(bGotMin != 0 && bGotMax != 0))
            {
                band.ComputeRasterMinMax(adfMinMax, 1);
            }

            Console.WriteLine("Min={0}, Max={1}", adfMinMax[0], adfMinMax[1]);
            Assert.AreEqual(0, adfMinMax [0]);
            Assert.AreEqual(255, adfMinMax [1]);

            var overviewCount = band.GetOverviewCount();

            if (overviewCount > 0)
            {
                Console.WriteLine("Band has {0} overviews.", overviewCount);
            }
            Assert.AreEqual(0, overviewCount);

            var colorTable = band.GetColorTable();

            if (colorTable != null)
            {
                Console.WriteLine("Band has a color table with {0} entries.",
                                  colorTable.GetCount());
            }
            Assert.AreEqual(null, colorTable);
        }
Ejemplo n.º 2
0
        /**
         * 헤더 생성
         */
        public HeaderInfo GetHeaderInfo()
        {
            HeaderInfo headerInfo = new HeaderInfo();

            headerInfo.FileName = Path.GetFileName(filePath);
            headerInfo.FileType = dataset.GetDriver().ShortName + "/" + dataset.GetDriver().LongName;
            headerInfo.Band     = dataset.RasterCount;
            headerInfo.Width    = dataset.RasterXSize;
            headerInfo.Height   = dataset.RasterYSize;

            headerInfo.DataType    = Gdal.GetDataTypeName(dataset.GetRasterBand(1).DataType);
            headerInfo.Description = dataset.GetDescription();

            SetMapInfo(headerInfo);

            return(headerInfo);
        }
Ejemplo n.º 3
0
        /**
         * 헤더 생성
         */
        public ImageInfo GetImageInfo()
        {
            ImageInfo imageInfo = new ImageInfo();

            imageInfo.FileName = Path.GetFileName(FileName);
            imageInfo.FileType = dataset.GetDriver().ShortName + "/" + dataset.GetDriver().LongName;
            imageInfo.Band     = dataset.RasterCount;

            imageInfo.DataType     = Gdal.GetDataTypeName(dataset.GetRasterBand(1).DataType);
            imageInfo.Description  = dataset.GetDescription();
            imageInfo.ImageWidth   = dataset.RasterXSize;
            imageInfo.ImageHeight  = dataset.RasterYSize;
            imageInfo.ViewerWidth  = dataset.RasterXSize;
            imageInfo.ViewerHeight = dataset.RasterYSize;
            imageInfo.Interleave   = GdalUtil.ReportImageStructureMetadata(dataset);

            Boundary ImageBoundary = null;

            if (GeometryControl.GetImageBoundary(dataset, out double minX, out double minY, out double maxX, out double maxY))
            {
                ImageBoundary = new Boundary(minX, minY, maxX, maxY, 0, 0);
            }

            imageInfo.ImageBoundary = ImageBoundary;

            ImageFormat imageFormat = ImageFormat.Bmp;

            if (FileName.ToLower().Contains(".png") || FileName.ToLower().Contains(".tif"))
            {
                imageFormat = ImageFormat.Png;
            }
            else if (FileName.ToLower().Contains(".jpg") || FileName.ToLower().Contains(".jpeg"))
            {
                imageFormat = ImageFormat.Jpeg;
            }

            imageInfo.ImageFormat = imageFormat;

            SetMapInfo(imageInfo);

            return(imageInfo);
        }
Ejemplo n.º 4
0
    public static void Main(string[] args)
    {
        if (args.Length != 1)
        {
            usage();
        }

        Console.WriteLine("");
        try
        {
            /* -------------------------------------------------------------------- */
            /*      Register driver(s).                                             */
            /* -------------------------------------------------------------------- */
            Gdal.AllRegister();

            /* -------------------------------------------------------------------- */
            /*      Open dataset.                                                   */
            /* -------------------------------------------------------------------- */
            Dataset ds = Gdal.Open(args[0], Access.GA_ReadOnly);

            if (ds == null)
            {
                Console.WriteLine("Can't open " + args[0]);
                Environment.Exit(-1);
            }

            Console.WriteLine("Raster dataset parameters:");
            Console.WriteLine("  Projection: " + ds.GetProjectionRef());
            Console.WriteLine("  RasterCount: " + ds.RasterCount);
            Console.WriteLine("  RasterSize (" + ds.RasterXSize + "," + ds.RasterYSize + ")");

            /* -------------------------------------------------------------------- */
            /*      Get driver                                                      */
            /* -------------------------------------------------------------------- */
            Driver drv = ds.GetDriver();

            if (drv == null)
            {
                Console.WriteLine("Can't get driver.");
                Environment.Exit(-1);
            }

            Console.WriteLine("Using driver " + drv.LongName);

            /* -------------------------------------------------------------------- */
            /*      Get metadata                                                    */
            /* -------------------------------------------------------------------- */
            string[] metadata = ds.GetMetadata("");
            if (metadata.Length > 0)
            {
                Console.WriteLine("  Metadata:");
                for (int iMeta = 0; iMeta < metadata.Length; iMeta++)
                {
                    Console.WriteLine("    " + iMeta + ":  " + metadata[iMeta]);
                }
                Console.WriteLine("");
            }

            /* -------------------------------------------------------------------- */
            /*      Report "IMAGE_STRUCTURE" metadata.                              */
            /* -------------------------------------------------------------------- */
            metadata = ds.GetMetadata("IMAGE_STRUCTURE");
            if (metadata.Length > 0)
            {
                Console.WriteLine("  Image Structure Metadata:");
                for (int iMeta = 0; iMeta < metadata.Length; iMeta++)
                {
                    Console.WriteLine("    " + iMeta + ":  " + metadata[iMeta]);
                }
                Console.WriteLine("");
            }

            /* -------------------------------------------------------------------- */
            /*      Report subdatasets.                                             */
            /* -------------------------------------------------------------------- */
            metadata = ds.GetMetadata("SUBDATASETS");
            if (metadata.Length > 0)
            {
                Console.WriteLine("  Subdatasets:");
                for (int iMeta = 0; iMeta < metadata.Length; iMeta++)
                {
                    Console.WriteLine("    " + iMeta + ":  " + metadata[iMeta]);
                }
                Console.WriteLine("");
            }

            /* -------------------------------------------------------------------- */
            /*      Report geolocation.                                             */
            /* -------------------------------------------------------------------- */
            metadata = ds.GetMetadata("GEOLOCATION");
            if (metadata.Length > 0)
            {
                Console.WriteLine("  Geolocation:");
                for (int iMeta = 0; iMeta < metadata.Length; iMeta++)
                {
                    Console.WriteLine("    " + iMeta + ":  " + metadata[iMeta]);
                }
                Console.WriteLine("");
            }

            /* -------------------------------------------------------------------- */
            /*      Report corners.                                                 */
            /* -------------------------------------------------------------------- */
            Console.WriteLine("Corner Coordinates:");
            Console.WriteLine("  Upper Left (" + GDALInfoGetPosition(ds, 0.0, 0.0) + ")");
            Console.WriteLine("  Lower Left (" + GDALInfoGetPosition(ds, 0.0, ds.RasterYSize) + ")");
            Console.WriteLine("  Upper Right (" + GDALInfoGetPosition(ds, ds.RasterXSize, 0.0) + ")");
            Console.WriteLine("  Lower Right (" + GDALInfoGetPosition(ds, ds.RasterXSize, ds.RasterYSize) + ")");
            Console.WriteLine("  Center (" + GDALInfoGetPosition(ds, ds.RasterXSize / 2, ds.RasterYSize / 2) + ")");
            Console.WriteLine("");

            /* -------------------------------------------------------------------- */
            /*      Report projection.                                              */
            /* -------------------------------------------------------------------- */
            string projection = ds.GetProjectionRef();
            if (projection != null)
            {
                SpatialReference srs = new SpatialReference(null);
                if (srs.ImportFromWkt(ref projection) == 0)
                {
                    string wkt;
                    srs.ExportToPrettyWkt(out wkt, 0);
                    Console.WriteLine("Coordinate System is:");
                    Console.WriteLine(wkt);
                }
                else
                {
                    Console.WriteLine("Coordinate System is:");
                    Console.WriteLine(projection);
                }
            }

            /* -------------------------------------------------------------------- */
            /*      Report GCPs.                                                    */
            /* -------------------------------------------------------------------- */
            if (ds.GetGCPCount() > 0)
            {
                Console.WriteLine("GCP Projection: ", ds.GetGCPProjection());
                GCP[] GCPs = ds.GetGCPs();
                for (int i = 0; i < ds.GetGCPCount(); i++)
                {
                    Console.WriteLine("GCP[" + i + "]: Id=" + GCPs[i].Id + ", Info=" + GCPs[i].Info);
                    Console.WriteLine("          (" + GCPs[i].GCPPixel + "," + GCPs[i].GCPLine + ") -> ("
                                      + GCPs[i].GCPX + "," + GCPs[i].GCPY + "," + GCPs[i].GCPZ + ")");
                    Console.WriteLine("");
                }
                Console.WriteLine("");

                double[] transform = new double[6];
                Gdal.GCPsToGeoTransform(GCPs, transform, 0);
                Console.WriteLine("GCP Equivalent geotransformation parameters: ", ds.GetGCPProjection());
                for (int i = 0; i < 6; i++)
                {
                    Console.WriteLine("t[" + i + "] = " + transform[i].ToString());
                }
                Console.WriteLine("");
            }

            /* -------------------------------------------------------------------- */
            /*      Get raster band                                                 */
            /* -------------------------------------------------------------------- */
            for (int iBand = 1; iBand <= ds.RasterCount; iBand++)
            {
                Band band = ds.GetRasterBand(iBand);
                Console.WriteLine("Band " + iBand + " :");
                Console.WriteLine("   DataType: " + Gdal.GetDataTypeName(band.DataType));
                Console.WriteLine("   ColorInterpretation: " + Gdal.GetColorInterpretationName(band.GetRasterColorInterpretation()));
                ColorTable ct = band.GetRasterColorTable();
                if (ct != null)
                {
                    Console.WriteLine("   Band has a color table with " + ct.GetCount() + " entries.");
                }

                Console.WriteLine("   Description: " + band.GetDescription());
                Console.WriteLine("   Size (" + band.XSize + "," + band.YSize + ")");
                int BlockXSize, BlockYSize;
                band.GetBlockSize(out BlockXSize, out BlockYSize);
                Console.WriteLine("   BlockSize (" + BlockXSize + "," + BlockYSize + ")");
                double val;
                int    hasval;
                band.GetMinimum(out val, out hasval);
                if (hasval != 0)
                {
                    Console.WriteLine("   Minimum: " + val.ToString());
                }
                band.GetMaximum(out val, out hasval);
                if (hasval != 0)
                {
                    Console.WriteLine("   Maximum: " + val.ToString());
                }
                band.GetNoDataValue(out val, out hasval);
                if (hasval != 0)
                {
                    Console.WriteLine("   NoDataValue: " + val.ToString());
                }
                band.GetOffset(out val, out hasval);
                if (hasval != 0)
                {
                    Console.WriteLine("   Offset: " + val.ToString());
                }
                band.GetScale(out val, out hasval);
                if (hasval != 0)
                {
                    Console.WriteLine("   Scale: " + val.ToString());
                }

                for (int iOver = 0; iOver < band.GetOverviewCount(); iOver++)
                {
                    Band over = band.GetOverview(iOver);
                    Console.WriteLine("      OverView " + iOver + " :");
                    Console.WriteLine("         DataType: " + over.DataType);
                    Console.WriteLine("         Size (" + over.XSize + "," + over.YSize + ")");
                    Console.WriteLine("         PaletteInterp: " + over.GetRasterColorInterpretation().ToString());
                }
            }

            Console.ReadLine();
        }
        catch (Exception e)
        {
            Console.WriteLine("Application error: " + e.Message);
        }
    }
Ejemplo n.º 5
0
        public static String GetInfo(Dataset ds)
        {
            StringBuilder builder = new StringBuilder();

            try
            {
                if (ds == null)
                {
                    return("");
                }

                //builder.AppendLine("  Projection: " + ds.GetProjectionRef());


                /* -------------------------------------------------------------------- */
                /*      Get driver                                                      */
                /* -------------------------------------------------------------------- */
                Driver drv = ds.GetDriver();

                if (drv == null)
                {
                    return("Can't get driver.");
                }

                builder.AppendLine("Driver " + drv.ShortName + "/" + drv.LongName);

                string[] fileList = ds.GetFileList();
                if (fileList.Length > 0)
                {
                    builder.AppendLine("Files:");
                    for (int iMeta = 0; iMeta < fileList.Length; iMeta++)
                    {
                        byte[] bytes    = Encoding.Default.GetBytes(fileList[iMeta]);
                        String fileName = Encoding.UTF8.GetString(bytes);
                        builder.AppendLine("      " + fileName);
                    }
                }
                builder.AppendLine("BandCount: " + ds.RasterCount);
                builder.AppendLine("Size is " + ds.RasterXSize + ", " + ds.RasterYSize);

                /* -------------------------------------------------------------------- */
                /*      Report projection.                                              */
                /* -------------------------------------------------------------------- */
                string projection = ds.GetProjectionRef();
                if (projection != null)
                {
                    SpatialReference srs = new SpatialReference(null);
                    if (srs.ImportFromWkt(ref projection) == 0)
                    {
                        string wkt;
                        srs.ExportToPrettyWkt(out wkt, 0);
                        builder.AppendLine("Coordinate System is:");
                        builder.AppendLine(wkt);
                    }
                    else
                    {
                        builder.AppendLine("Coordinate System is:");
                        builder.AppendLine(projection);
                    }
                }

                /* -------------------------------------------------------------------- */
                /*      Report GCPs.                                                    */
                /* -------------------------------------------------------------------- */
                if (ds.GetGCPCount() > 0)
                {
                    builder.AppendLine("GCP Projection: " + ds.GetGCPProjection());
                    GCP[] GCPs = ds.GetGCPs();
                    for (int i = 0; i < ds.GetGCPCount(); i++)
                    {
                        builder.AppendLine("GCP[" + i + "]: Id=" + GCPs[i].Id + ", Info=" + GCPs[i].Info);
                        builder.AppendLine("          (" + GCPs[i].GCPPixel + "," + GCPs[i].GCPLine + ") -> ("
                                           + GCPs[i].GCPX + "," + GCPs[i].GCPY + "," + GCPs[i].GCPZ + ")");
                        builder.AppendLine("");
                    }
                    builder.AppendLine("");

                    double[] geotransform = new double[6];
                    Gdal.GCPsToGeoTransform(GCPs, geotransform, 0);
                    builder.AppendLine("GCP Equivalent geotransformation parameters: " + ds.GetGCPProjection());
                    for (int i = 0; i < 6; i++)
                    {
                        builder.AppendLine("t[" + i + "] = " + geotransform[i].ToString());
                    }
                    builder.AppendLine("");
                }

                double[] transform = GetGeoTransform(ds);
                builder.AppendLine("Origin = (" + GDALInfoGetPosition(transform, 0.0, 0.0) + ")");
                builder.AppendLine("Pixel Size = (" + transform[1].ToString("f16") + "," + transform[5].ToString("f16") + ")");

                /* -------------------------------------------------------------------- */
                /*      Get metadata                                                    */
                /* -------------------------------------------------------------------- */
                string[] metadata = ds.GetMetadata("");
                if (metadata.Length > 0)
                {
                    builder.AppendLine("Metadata:");
                    for (int iMeta = 0; iMeta < metadata.Length; iMeta++)
                    {
                        builder.AppendLine("  " + metadata[iMeta]);
                    }
                }

                /* -------------------------------------------------------------------- */
                /*      Report "IMAGE_STRUCTURE" metadata.                              */
                /* -------------------------------------------------------------------- */
                metadata = ds.GetMetadata("IMAGE_STRUCTURE");
                if (metadata.Length > 0)
                {
                    builder.AppendLine("Image Structure Metadata:");
                    for (int iMeta = 0; iMeta < metadata.Length; iMeta++)
                    {
                        builder.AppendLine("  " + metadata[iMeta]);
                    }
                }

                /* -------------------------------------------------------------------- */
                /*      Report subdatasets.                                             */
                /* -------------------------------------------------------------------- */
                metadata = ds.GetMetadata("SUBDATASETS");
                if (metadata.Length > 0)
                {
                    builder.AppendLine("  Subdatasets:");
                    for (int iMeta = 0; iMeta < metadata.Length; iMeta++)
                    {
                        builder.AppendLine("    " + metadata[iMeta]);
                    }
                    builder.AppendLine("");
                }

                /* -------------------------------------------------------------------- */
                /*      Report geolocation.                                             */
                /* -------------------------------------------------------------------- */
                metadata = ds.GetMetadata("GEOLOCATION");
                if (metadata.Length > 0)
                {
                    builder.AppendLine("  Geolocation:");
                    for (int iMeta = 0; iMeta < metadata.Length; iMeta++)
                    {
                        builder.AppendLine("    " + metadata[iMeta]);
                    }
                    builder.AppendLine("");
                }

                /* -------------------------------------------------------------------- */
                /*      Report corners.                                                 */
                /* -------------------------------------------------------------------- */
                builder.AppendLine("Corner Coordinates:");
                builder.AppendLine("  Upper Left (" + GDALInfoGetPosition(transform, 0.0, 0.0) + ")");
                builder.AppendLine("  Lower Left (" + GDALInfoGetPosition(transform, 0.0, ds.RasterYSize) + ")");
                builder.AppendLine("  Upper Right (" + GDALInfoGetPosition(transform, ds.RasterXSize, 0.0) + ")");
                builder.AppendLine("  Lower Right (" + GDALInfoGetPosition(transform, ds.RasterXSize, ds.RasterYSize) + ")");
                builder.AppendLine("  Center (" + GDALInfoGetPosition(transform, ds.RasterXSize / 2, ds.RasterYSize / 2) + ")");
                builder.AppendLine("");



                /* -------------------------------------------------------------------- */
                /*      Get raster band                                                 */
                /* -------------------------------------------------------------------- */
                for (int iBand = 1; iBand <= ds.RasterCount; iBand++)
                {
                    Band band = ds.GetRasterBand(iBand);
                    int  blockXSize, blockYSize;
                    band.GetBlockSize(out blockXSize, out blockYSize);

                    builder.Append("Band ");
                    builder.Append(iBand);
                    builder.Append(" Block=");
                    builder.Append(blockXSize);
                    builder.Append("x");
                    builder.Append(blockYSize);
                    builder.Append(", Type=");
                    builder.Append(Gdal.GetDataTypeName(band.DataType));
                    builder.Append(", ColorInterp=");
                    builder.Append(Gdal.GetColorInterpretationName(band.GetRasterColorInterpretation()));

                    double val;
                    int    hasval;
                    band.GetMinimum(out val, out hasval);
                    if (hasval != 0)
                    {
                        builder.Append(", Minimum=" + val.ToString());
                    }
                    band.GetMaximum(out val, out hasval);
                    if (hasval != 0)
                    {
                        builder.Append(", Maximum=" + val.ToString());
                    }
                    band.GetNoDataValue(out val, out hasval);
                    if (hasval != 0)
                    {
                        builder.Append(", NoDataValue=" + val.ToString());
                    }
                    band.GetOffset(out val, out hasval);
                    if (hasval != 0)
                    {
                        builder.Append(", Offset=" + val.ToString());
                    }
                    band.GetScale(out val, out hasval);
                    if (hasval != 0)
                    {
                        builder.Append(", Scale=" + val.ToString());
                    }
                    builder.AppendLine("");

                    if (band.GetOverviewCount() > 0)
                    {
                        builder.Append(" OverViews: ");
                        for (int iOver = 0; iOver < band.GetOverviewCount(); iOver++)
                        {
                            Band over = band.GetOverview(iOver);
                            builder.Append(over.XSize + "x" + over.YSize + ", ");
                            // builder.AppendLine("         DataType: " + over.DataType);
                            // builder.AppendLine("         Size (" + over.XSize + "," + over.YSize + ")");
                            //builder.AppendLine("         PaletteInterp: " + over.GetRasterColorInterpretation().ToString());
                        }
                        builder.AppendLine("");
                    }

                    ColorTable ct = band.GetRasterColorTable();
                    if (ct != null)
                    {
                        builder.AppendLine(" Band has a color table with " + ct.GetCount() + " entries.");
                    }

                    String des = band.GetDescription();
                    if (des != null && !String.IsNullOrWhiteSpace(des))
                    {
                        builder.AppendLine(" Description: " + band.GetDescription());
                    }
                }
            }
            catch (Exception e)
            {
                return("Application error: " + e.Message);
            }

            return(builder.ToString());
        }
Ejemplo n.º 6
0
        public GDAL_Info(Dataset ds)
        {
            Projection = ds.GetProjectionRef();
            Resolution = new Size(ds.RasterXSize, ds.RasterYSize);
            Bands      = new DataBandInfo[ds.RasterCount];
            for (int i = 0; i < ds.RasterCount; i++)
            {
                Band band = ds.GetRasterBand(i + 1);
                Bands[i] = new DataBandInfo();
                int temp;
                band.GetMaximum(out Bands[i].MaxValue, out temp);
                band.GetMaximum(out Bands[i].MinValue, out temp);
                band.GetNoDataValue(out Bands[i].NODATAValue, out temp);
                ColorInterp clr = band.GetRasterColorInterpretation();
                switch (clr)
                {
                case ColorInterp.GCI_RedBand:
                    Bands[i].Name  = "RedBand";
                    Bands[i].Image = Resource1.red_layer;
                    BppType       += "R";
                    break;

                case ColorInterp.GCI_GreenBand:
                    Bands[i].Name  = "GreenBand";
                    Bands[i].Image = Resource1.green_layer;
                    BppType       += "G";
                    break;

                case ColorInterp.GCI_BlueBand:
                    Bands[i].Name  = "BlueBand";
                    Bands[i].Image = Resource1.blue_layer;
                    BppType       += "B";
                    break;

                default:
                    Bands[i].Name  = clr.ToString();
                    Bands[i].Image = null;
                    BppType       += "?";
                    break;
                }
                BppType += "[" + Gdal.GetDataTypeName(band.DataType) + "]";
                Bpp     += (ushort)Gdal.GetDataTypeSize(band.DataType);

                if (i + 1 < ds.RasterCount)
                {
                    BppType += ",";
                }
            }
            BppType += " (" + Bpp + ")";

            Driver = ds.GetDriver().LongName;

            Metadata       = ds.GetMetadata("");
            ImgMetadata    = ds.GetMetadata("IMAGE_STRUCTURE");
            SubDSMetadata  = ds.GetMetadata("SUBDATASETS");
            GeoLocMetadata = ds.GetMetadata("GEOLOCATION");

            GDALInfoGetPosition(ds, 0.0, 0.0, out UpperLeftX, out UpperLeftY);
            GDALInfoGetPosition(ds, 0.0, ds.RasterYSize, out UpperRightX, out UpperRightY);
            GDALInfoGetPosition(ds, ds.RasterXSize, 0.0, out LowerLeftX, out LowerLeftY);
            GDALInfoGetPosition(ds, ds.RasterXSize, ds.RasterYSize, out LowerRightX, out LowerRightY);
            GDALInfoGetPosition(ds, ds.RasterXSize / 2, ds.RasterYSize / 2, out CenterX, out CenterY);
        }
Ejemplo n.º 7
0
        private void getGdalinfo()
        {
            //================================================================
            // Initialize
            //================================================================
            reset();

            //================================================================
            // Get gdal info
            //================================================================
            try {
                //------------------------------------------------------------
                // Open dataset
                //------------------------------------------------------------
                m_tGdalDs = Gdal.Open(m_strGeoTiffPath, Access.GA_ReadOnly);

                if (m_tGdalDs == null)
                {
                    m_ctrlLogger.FatalFormat("Can't open {0}", m_strGeoTiffPath);
                    throw new ArgumentException("Parameter cannot be null", "original");
                }
                m_strGdalInfoTxt.AppendLine("GeoTIFF file path:");
                m_strGdalInfoTxt.AppendFormat("  {0}", m_strGeoTiffPath).AppendLine();
                m_strGdalInfoTxt.AppendLine("Raster dataset parameters:");
                m_strGdalInfoTxt.AppendFormat("  Projection: {0}",
                                              m_tGdalDs.GetProjectionRef()).AppendLine();
                m_strGdalInfoTxt.AppendFormat("  RasterCount: {0}",
                                              m_tGdalDs.RasterCount).AppendLine();
                m_strGdalInfoTxt.AppendFormat("  RasterSize ({0},{1})",
                                              m_tGdalDs.RasterXSize, m_tGdalDs.RasterYSize).AppendLine();

                //------------------------------------------------------------
                // Get driver
                //------------------------------------------------------------
                m_tGdalDriver = m_tGdalDs.GetDriver();

                if (m_tGdalDriver == null)
                {
                    m_ctrlLogger.Fatal("Can't get driver.");
                    throw new ArgumentException("Parameter cannot be null", "original");
                }

                m_strGdalInfoTxt.AppendFormat("Using driver {0}",
                                              m_tGdalDriver.LongName).AppendLine();

                //------------------------------------------------------------
                // Get meta data
                //------------------------------------------------------------
                string[] metadata = m_tGdalDs.GetMetadata(string.Empty);
                if (metadata.Length > 0)
                {
                    m_strGdalInfoTxt.AppendLine("  Metadata:");
                    for (int iMeta = 0; iMeta < metadata.Length; iMeta++)
                    {
                        m_strGdalInfoTxt.AppendFormat("    {0}: {1}",
                                                      iMeta, metadata[iMeta]).AppendLine();
                    }
                    m_strGdalInfoTxt.AppendLine();
                }

                //------------------------------------------------------------
                // Report "IMAGE_STRUCTURE" metadata
                //------------------------------------------------------------
                metadata = m_tGdalDs.GetMetadata("IMAGE_STRUCTURE");
                if (metadata.Length > 0)
                {
                    m_strGdalInfoTxt.AppendLine("  Image Structure Metadata:");
                    for (int iMeta = 0; iMeta < metadata.Length; iMeta++)
                    {
                        m_strGdalInfoTxt.AppendFormat("    {0}: {1}",
                                                      iMeta, metadata[iMeta]).AppendLine();
                    }
                    m_strGdalInfoTxt.AppendLine();
                }

                //------------------------------------------------------------
                // Report subdatasets
                //------------------------------------------------------------
                metadata = m_tGdalDs.GetMetadata("SUBDATASETS");
                if (metadata.Length > 0)
                {
                    m_strGdalInfoTxt.AppendLine("  Subdatasets:");
                    for (int iMeta = 0; iMeta < metadata.Length; iMeta++)
                    {
                        m_strGdalInfoTxt.AppendFormat("    {0}: {1}",
                                                      iMeta, metadata[iMeta]).AppendLine();
                    }
                    m_strGdalInfoTxt.AppendLine();
                }

                //------------------------------------------------------------
                // Report geolocation
                //------------------------------------------------------------
                metadata = m_tGdalDs.GetMetadata("GEOLOCATION");
                if (metadata.Length > 0)
                {
                    m_strGdalInfoTxt.AppendLine("  Geolocation:");
                    for (int iMeta = 0; iMeta < metadata.Length; iMeta++)
                    {
                        m_strGdalInfoTxt.AppendFormat("    {0}: {1}",
                                                      iMeta, metadata[iMeta]).AppendLine();
                    }
                    m_strGdalInfoTxt.AppendLine();
                }

                //------------------------------------------------------------
                // Report corners
                //------------------------------------------------------------
                m_strGdalInfoTxt.AppendLine("Corner Coordinates:");
                m_strGdalInfoTxt.AppendFormat("  Upper Left ({0})",
                                              GDALInfoGetPosition(0.0, 0.0)).AppendLine();
                m_strGdalInfoTxt.AppendFormat("  Lower Left ({0})",
                                              GDALInfoGetPosition(0.0, m_tGdalDs.RasterYSize)).AppendLine();
                m_strGdalInfoTxt.AppendFormat("  Upper Right ({0})",
                                              GDALInfoGetPosition(m_tGdalDs.RasterXSize, 0.0)).AppendLine();
                m_strGdalInfoTxt.AppendFormat("  Lower Right ({0})",
                                              GDALInfoGetPosition(m_tGdalDs.RasterXSize, m_tGdalDs.RasterYSize)).AppendLine();
                m_strGdalInfoTxt.AppendFormat("  Center ({0})",
                                              GDALInfoGetPosition(m_tGdalDs.RasterXSize / 2, m_tGdalDs.RasterYSize / 2)).AppendLine();
                m_strGdalInfoTxt.AppendLine();

                //------------------------------------------------------------
                // Report projection
                //------------------------------------------------------------
                string projection = m_tGdalDs.GetProjectionRef();
                if (projection != null)
                {
                    SpatialReference srs = new SpatialReference(null);
                    if (srs.ImportFromWkt(ref projection) == 0)
                    {
                        string wkt;
                        srs.ExportToPrettyWkt(out wkt, 0);
                        m_strGdalInfoTxt.AppendLine("Coordinate System is:");
                        m_strGdalInfoTxt.AppendLine(wkt);
                    }
                    else
                    {
                        m_strGdalInfoTxt.AppendLine("Coordinate System is:");
                        m_strGdalInfoTxt.AppendLine(projection);
                    }
                }

                //------------------------------------------------------------
                // Report GCPs
                //------------------------------------------------------------
                if (m_tGdalDs.GetGCPCount() > 0)
                {
                    m_strGdalInfoTxt.AppendFormat("GCP Projection: {0}",
                                                  m_tGdalDs.GetGCPProjection()).AppendLine();
                    GCP[] GCPs = m_tGdalDs.GetGCPs();
                    for (int i = 0; i < m_tGdalDs.GetGCPCount(); i++)
                    {
                        m_strGdalInfoTxt.AppendFormat("GCP[{0}]: Id={1}, Info={2}",
                                                      i, GCPs[i].Id, GCPs[i].Info).AppendLine();
                        m_strGdalInfoTxt.AppendFormat("          ({0},{1})->({2},{3},{4})",
                                                      GCPs[i].GCPPixel, GCPs[i].GCPLine, GCPs[i].GCPX, GCPs[i].GCPY, GCPs[i].GCPZ);
                        m_strGdalInfoTxt.AppendLine();
                    }
                    m_strGdalInfoTxt.AppendLine();

                    double[] transform = new double[6];
                    Gdal.GCPsToGeoTransform(GCPs, transform, 0);
                    m_strGdalInfoTxt.AppendFormat("GCP Equivalent geotransformation parameters: {0}",
                                                  m_tGdalDs.GetGCPProjection());
                    for (int i = 0; i < 6; i++)
                    {
                        m_strGdalInfoTxt.AppendFormat("[{0}]= {1}", i, transform[i].ToString());
                    }
                    m_strGdalInfoTxt.AppendLine();
                }

                //------------------------------------------------------------
                // Get raster band
                //------------------------------------------------------------
                for (int iBand = 1; iBand <= m_tGdalDs.RasterCount; iBand++)
                {
                    Band band = m_tGdalDs.GetRasterBand(iBand);
                    m_strGdalInfoTxt.AppendFormat("Band {0} :",
                                                  iBand).AppendLine();
                    m_strGdalInfoTxt.AppendFormat("   DataType: {0}",
                                                  Gdal.GetDataTypeName(band.DataType)).AppendLine();
                    m_strGdalInfoTxt.AppendFormat("   ColorInterpretation: {0}",
                                                  Gdal.GetColorInterpretationName(band.GetRasterColorInterpretation())).AppendLine();
                    ColorTable ct = band.GetRasterColorTable();
                    if (ct != null)
                    {
                        m_strGdalInfoTxt.AppendFormat("   Band has a color table with {0} entries.",
                                                      ct.GetCount()).AppendLine();
                    }

                    m_strGdalInfoTxt.AppendFormat("   Description: {0}",
                                                  band.GetDescription()).AppendLine();
                    m_strGdalInfoTxt.AppendFormat("   Size ({0},{1})",
                                                  band.XSize, band.YSize).AppendLine();
                    int BlockXSize, BlockYSize;
                    band.GetBlockSize(out BlockXSize, out BlockYSize);
                    m_strGdalInfoTxt.AppendFormat("   BlockSize ({0},{1})",
                                                  BlockXSize, BlockYSize).AppendLine();
                    double val;
                    int    hasval;
                    band.GetMinimum(out val, out hasval);
                    if (hasval != 0)
                    {
                        m_strGdalInfoTxt.AppendFormat("   Minimum: {0}",
                                                      val.ToString()).AppendLine();
                    }
                    band.GetMaximum(out val, out hasval);
                    if (hasval != 0)
                    {
                        m_strGdalInfoTxt.AppendFormat("   Maximum: {0}",
                                                      val.ToString()).AppendLine();
                    }
                    band.GetNoDataValue(out val, out hasval);
                    if (hasval != 0)
                    {
                        m_strGdalInfoTxt.AppendFormat("   NoDataValue: {0}",
                                                      val.ToString()).AppendLine();
                    }
                    band.GetOffset(out val, out hasval);
                    if (hasval != 0)
                    {
                        m_strGdalInfoTxt.AppendFormat("   Offset: {0}",
                                                      val.ToString()).AppendLine();
                    }
                    band.GetScale(out val, out hasval);
                    if (hasval != 0)
                    {
                        m_strGdalInfoTxt.AppendFormat("   Scale: {0}",
                                                      val.ToString()).AppendLine();
                    }

                    for (int iOver = 0; iOver < band.GetOverviewCount(); iOver++)
                    {
                        Band over = band.GetOverview(iOver);
                        m_strGdalInfoTxt.AppendFormat("      OverView {0}:",
                                                      iOver).AppendLine();
                        m_strGdalInfoTxt.AppendFormat("         DataType: {0}",
                                                      over.DataType).AppendLine();
                        m_strGdalInfoTxt.AppendFormat("         Size ({0},{1})",
                                                      over.XSize, over.YSize).AppendLine();
                        m_strGdalInfoTxt.AppendFormat("         PaletteInterp: {0}",
                                                      over.GetRasterColorInterpretation().ToString()).AppendLine();
                    }
                }
            } catch (Exception ex) {
                m_ctrlLogger.FatalFormat("Application error: {0}", ex.Message);
            }
        }
        public static String DumpDatasetInfo(Dataset ds)
        {
            var sb = new StringBuilder();

            sb.AppendLine("Raster dataset parameters:");
            sb.AppendLine("  Projection: " + ds.GetProjectionRef());
            sb.AppendLine("  RasterCount: " + ds.RasterCount);
            sb.AppendLine("  RasterSize (" + ds.RasterXSize + "," + ds.RasterYSize + ")");

            /* -------------------------------------------------------------------- */
            /*      Get driver                                                      */
            /* -------------------------------------------------------------------- */
            var drv = ds.GetDriver();

            if (drv == null)
            {
                sb.AppendLine("Can't get driver.");
                return(sb.ToString());
            }

            sb.AppendLine("Using driver " + drv.LongName);

            /* -------------------------------------------------------------------- */
            /*      Get metadata                                                    */
            /* -------------------------------------------------------------------- */
            string[] metadata = ds.GetMetadata("");
            if (metadata.Length > 0)
            {
                sb.AppendLine("  Metadata:");
                for (int iMeta = 0; iMeta < metadata.Length; iMeta++)
                {
                    sb.AppendLine("    " + iMeta + ":  " + metadata[iMeta]);
                }
                sb.AppendLine("");
            }

            /* -------------------------------------------------------------------- */
            /*      Report "IMAGE_STRUCTURE" metadata.                              */
            /* -------------------------------------------------------------------- */
            metadata = ds.GetMetadata("IMAGE_STRUCTURE");
            if (metadata.Length > 0)
            {
                sb.AppendLine("  Image Structure Metadata:");
                for (int iMeta = 0; iMeta < metadata.Length; iMeta++)
                {
                    sb.AppendLine("    " + iMeta + ":  " + metadata[iMeta]);
                }
                sb.AppendLine("");
            }

            /* -------------------------------------------------------------------- */
            /*      Report subdatasets.                                             */
            /* -------------------------------------------------------------------- */
            metadata = ds.GetMetadata("SUBDATASETS");
            if (metadata.Length > 0)
            {
                sb.AppendLine("  Subdatasets:");
                for (int iMeta = 0; iMeta < metadata.Length; iMeta++)
                {
                    sb.AppendLine("    " + iMeta + ":  " + metadata[iMeta]);
                }
                sb.AppendLine("");
            }

            /* -------------------------------------------------------------------- */
            /*      Report geolocation.                                             */
            /* -------------------------------------------------------------------- */
            metadata = ds.GetMetadata("GEOLOCATION");
            if (metadata.Length > 0)
            {
                sb.AppendLine("  Geolocation:");
                for (int iMeta = 0; iMeta < metadata.Length; iMeta++)
                {
                    sb.AppendLine("    " + iMeta + ":  " + metadata[iMeta]);
                }
                sb.AppendLine("");
            }

            /* -------------------------------------------------------------------- */
            /*      Report corners.                                                 */
            /* -------------------------------------------------------------------- */
            sb.AppendLine("Corner Coordinates:");
            sb.AppendLine("  Upper Left (" + GdalInfoGetPosition(ds, 0.0, 0.0) + ")");
            sb.AppendLine("  Lower Left (" + GdalInfoGetPosition(ds, 0.0, ds.RasterYSize) + ")");
            sb.AppendLine("  Upper Right (" + GdalInfoGetPosition(ds, ds.RasterXSize, 0.0) + ")");
            sb.AppendLine("  Lower Right (" + GdalInfoGetPosition(ds, ds.RasterXSize, ds.RasterYSize) + ")");
            sb.AppendLine("  Center (" + GdalInfoGetPosition(ds, ds.RasterXSize / 2.0, ds.RasterYSize / 2.0) + ")");
            sb.AppendLine("");

            /* -------------------------------------------------------------------- */
            /*      Report projection.                                              */
            /* -------------------------------------------------------------------- */
            string projection = ds.GetProjectionRef();

            if (projection != null)
            {
                SpatialReference srs = new SpatialReference(null);
                if (srs.ImportFromWkt(ref projection) == 0)
                {
                    srs.ExportToPrettyWkt(out var wkt, 0);
                    sb.AppendLine("Coordinate System is:");
                    sb.AppendLine(wkt);
                }
                else
                {
                    sb.AppendLine("Coordinate System is:");
                    sb.AppendLine(projection);
                }
            }

            /* -------------------------------------------------------------------- */
            /*      Report GCPs.                                                    */
            /* -------------------------------------------------------------------- */
            if (ds.GetGCPCount() > 0)
            {
                sb.AppendLine("GCP Projection: " + ds.GetGCPProjection());
                GCP[] gcps = ds.GetGCPs();
                for (int i = 0; i < ds.GetGCPCount(); i++)
                {
                    sb.AppendLine("GCP[" + i + "]: Id=" + gcps[i].Id + ", Info=" + gcps[i].Info);
                    sb.AppendLine("          (" + gcps[i].GCPPixel + "," + gcps[i].GCPLine + ") -> ("
                                  + gcps[i].GCPX + "," + gcps[i].GCPY + "," + gcps[i].GCPZ + ")");
                    sb.AppendLine("");
                }
                sb.AppendLine("");

                double[] transform = new double[6];
                Gdal.GCPsToGeoTransform(gcps, transform, 0);
                sb.AppendLine("GCP Equivalent geotransformation parameters: " + ds.GetGCPProjection());
                for (int i = 0; i < 6; i++)
                {
                    sb.AppendLine("t[" + i + "] = " + transform[i]);
                }
                sb.AppendLine("");
            }

            /* -------------------------------------------------------------------- */
            /*      Get raster band                                                 */
            /* -------------------------------------------------------------------- */
            for (int iBand = 1; iBand <= ds.RasterCount; iBand++)
            {
                Band band = ds.GetRasterBand(iBand);
                sb.AppendLine("Band " + iBand + " :");
                sb.AppendLine("   DataType: " + Gdal.GetDataTypeName(band.DataType));
                sb.AppendLine("   ColorInterpretation: " + Gdal.GetColorInterpretationName(band.GetRasterColorInterpretation()));
                ColorTable ct = band.GetRasterColorTable();
                if (ct != null)
                {
                    sb.AppendLine("   Band has a color table with " + ct.GetCount() + " entries.");
                }

                sb.AppendLine("   Description: " + band.GetDescription());
                sb.AppendLine("   Size (" + band.XSize + "," + band.YSize + ")");
                band.GetBlockSize(out var blockXSize, out var blockYSize);
                sb.AppendLine("   BlockSize (" + blockXSize + "," + blockYSize + ")");
                band.GetMinimum(out var val, out var hasVal);
                if (hasVal != 0)
                {
                    sb.AppendLine("   Minimum: " + val);
                }
                band.GetMaximum(out val, out hasVal);
                if (hasVal != 0)
                {
                    sb.AppendLine("   Maximum: " + val);
                }
                band.GetNoDataValue(out val, out hasVal);
                if (hasVal != 0)
                {
                    sb.AppendLine("   NoDataValue: " + val);
                }
                band.GetOffset(out val, out hasVal);
                if (hasVal != 0)
                {
                    sb.AppendLine("   Offset: " + val);
                }
                band.GetScale(out val, out hasVal);
                if (hasVal != 0)
                {
                    sb.AppendLine("   Scale: " + val);
                }

                for (int iOver = 0; iOver < band.GetOverviewCount(); iOver++)
                {
                    Band over = band.GetOverview(iOver);
                    sb.AppendLine("      OverView " + iOver + " :");
                    sb.AppendLine("         DataType: " + over.DataType);
                    sb.AppendLine("         Size (" + over.XSize + "," + over.YSize + ")");
                    sb.AppendLine("         PaletteInterpretation: " + over.GetRasterColorInterpretation());
                }
            }

            return(sb.ToString());
        }