当前位置: 首页>>代码示例>>C#>>正文


C# OSGeo.Create方法代码示例

本文整理汇总了C#中OSGeo.Create方法的典型用法代码示例。如果您正苦于以下问题:C# OSGeo.Create方法的具体用法?C# OSGeo.Create怎么用?C# OSGeo.Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OSGeo的用法示例。


在下文中一共展示了OSGeo.Create方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessRasterGrid

        /// <summary>
        /// Processes a raster file stored as an ESRI Grid into an 8-bit RGB .tif file based on a value-color map. Pass the function the hdr.adf file.
        /// </summary>
        /// <param name="args"></param>
        /// <param name="colorRepo"></param>
        /// <param name="resultDir"></param>
        /// <param name="srcDrv"></param>
        /// <param name="fi">FileInfo of the hdr.adf file of the grid.</param>
        /// <param name="resultName"></param>
        private static void ProcessRasterGrid(string[] args, IColorRepository colorRepo, DirectoryInfo resultDir, OSGeo.GDAL.Driver srcDrv, FileInfo fi, string resultName)
        {
            Console.WriteLine(string.Format("Processing {0}.adf into {1}...", fi.Directory.Name, resultName));
            StringBuilder bldr = new StringBuilder();

            //read data from source raster
            Dataset src = Gdal.Open(fi.FullName, Access.GA_ReadOnly);
            Band band = src.GetRasterBand(1);
            double[] r = new double[band.XSize * band.YSize];
            byte[] red = new byte[band.XSize * band.YSize];
            byte[] green = new byte[band.XSize * band.YSize];
            byte[] blue = new byte[band.XSize * band.YSize];
            band.ReadRaster(0, 0, band.XSize, band.YSize, r, band.XSize, band.YSize, 0, 0);

            //assign values to rgb rasters to produce new raster with rgb bands matching color pattern
            for (int cell = 0; cell < r.Length; cell++)
            {
                RGBColors colors = colorRepo.ColorsOfValueInFile(fi.Directory.Name, resultName, r[cell]);
                red[cell] = (byte)colors.Red;
                green[cell] = (byte)colors.Green;
                blue[cell] = (byte)colors.Blue;
            }

            //write new output
            using (Dataset output = srcDrv.Create(resultDir + resultName, band.XSize, band.YSize, 3, DataType.GDT_Byte, null))
            {
                if (output == null)
                {
                    Console.WriteLine("Can't create " + args[0]);
                    System.Environment.Exit(-1);
                }
                //set metadata
                output.SetProjection(src.GetProjection());
                double[] geotransform = new double[0];
                src.GetGeoTransform(geotransform);
                output.SetGeoTransform(geotransform);

                //prepare data for write
                int[] colorData = new int[red.Length * 3];
                red.CopyTo(colorData, 0);
                green.CopyTo(colorData, red.Length);
                blue.CopyTo(colorData, red.Length + green.Length);

                //write data to disk
                output.WriteRaster(0, 0, band.XSize, band.YSize, colorData, band.XSize, band.YSize, 3, null, 0, 0, 0);
                output.FlushCache();
            }
        }
开发者ID:hydrojumbo,项目名称:quito-climate-study,代码行数:57,代码来源:Program.cs


注:本文中的OSGeo.Create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。