public static void ConfigureGdal()
    {
        if (_configuredGdal)
        {
            return;
        }

        // Register drivers
        Gdal.AllRegister();
        _configuredGdal = true;
    }
예제 #2
0
    public static void ConfigureGdal()
    {
        MessageBox.Show("配置Gdal。。。。。");
        if (_configuredGdal)
        {
            return;
        }

        // Register drivers
        Gdal.AllRegister();
        _configuredGdal = true;
    }
예제 #3
0
        public void StartToProcess()
        {
            GdalConfiguration.ConfigureGdal();

            /* -------------------------------------------------------------------- */
            /*      Register driver(s).                                             */
            /* -------------------------------------------------------------------- */
            Gdal.AllRegister();

            /* -------------------------------------------------------------------- */
            /*      Open dataset.                                                   */
            /* -------------------------------------------------------------------- */


            List <string> tiffFiles = GetGeoTiffFiles();

            foreach (string servertiffFile in tiffFiles)
            {
                string localTiffFile = GetLocalTiffFileName(Path.GetFileNameWithoutExtension(servertiffFile));
                string localPngFile  = GetLocalPngFileName(Path.GetFileNameWithoutExtension(servertiffFile));
                string serverPngFile = servertiffFile.Replace(".tif", ".png");

                DownloadGeoTiffFile(servertiffFile, localTiffFile);

                Dataset ds = Gdal.Open(localTiffFile, Access.GA_Update);

                if (ds == null)
                {
                    Console.WriteLine("Can't open " + localTiffFile);
                    throw new Exception();
                }

                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.");
                    System.Environment.Exit(-1);
                }

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

                /* -------------------------------------------------------------------- */
                /*      Get raster band                                                 */
                /* -------------------------------------------------------------------- */
                for (int iBand = 1; iBand <= ds.RasterCount; iBand++)
                {
                    Band band = ds.GetRasterBand(iBand);
                    Console.WriteLine("Band " + iBand + " :");
                    Console.WriteLine("   DataType: " + band.DataType);
                    Console.WriteLine("   Size (" + band.XSize + "," + band.YSize + ")");
                    Console.WriteLine("   PaletteInterp: " + band.GetRasterColorInterpretation().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());
                    }
                }

                /* -------------------------------------------------------------------- */
                /*      Processing the raster                                           */
                /* -------------------------------------------------------------------- */
                //SaveBitmapBuffered(ds, localPngFile, -1);
                SaveBitmapGrayBuffered(ds, localPngFile, -1);

                UploadKmzFile(localPngFile, serverPngFile);
            }
            //string fileName = "cspp-viirs-flood-globally_20180815_080000.p153435116453720";
            //string geoTiffFileName = string.Format(@"D:\Repos\GmuGeo-bak\Resources\VIIRS_floodmap_Aug15_2018\{0}.tif", fileName);
            //string pngFileName = string.Format(@"D:\Repos\GmuGeo\Examples\png\{0}.png", fileName);
        }