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


C# OSGeo.GetGeoTransform方法代码示例

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


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

示例1: GeoTransform

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="gdalDataset">The gdal dataset</param>
        public GeoTransform(OSGeo.GDAL.Dataset gdalDataset)
        {
            if (gdalDataset == null)
                throw new ArgumentException("GeoTransform constructor invoked with null dataset.", "gdalDataset");

            var array = new double[6];
            gdalDataset.GetGeoTransform(array);
            _transform = array;
            ComputeInverse();
        }
开发者ID:PedroMaitan,项目名称:sharpmap,代码行数:14,代码来源:GeoTransform.cs

示例2: GetPreview

        private void GetPreview(OSGeo.GDAL.Dataset dataset, System.Drawing.Size size, Graphics g, IEnvelope bbox)
        {
            double[] geoTrans = new double[6];
            dataset.GetGeoTransform(geoTrans);
            GeoTransform GT = new GeoTransform(geoTrans);

            int DsWidth = dataset.RasterXSize;
            int DsHeight = dataset.RasterYSize;

            Bitmap bitmap = new Bitmap(size.Width, size.Height, PixelFormat.Format24bppRgb);
            int iPixelSize = 3; //Format24bppRgb = byte[b,g,r]

            if (dataset != null)
            {
                /*
                if ((float)size.Width / (float)size.Height > (float)DsWidth / (float)DsHeight)
                    size.Width = size.Height * DsWidth / DsHeight;
                else
                    size.Height = size.Width * DsHeight / DsWidth;
                */


                double left = Math.Max(bbox.MinX, _Envelope.MinX);
                double top = Math.Min(bbox.MaxY, _Envelope.MaxY);
                double right = Math.Min(bbox.MaxX, _Envelope.MaxX);
                double bottom = Math.Max(bbox.MinY, _Envelope.MinY);


                int x1 = (int)GT.PixelX(left);
                int y1 = (int)GT.PixelY(top);
                int x1width = (int)GT.PixelXwidth(right - left);

                int y1height = (int)GT.PixelYwidth(bottom - top);


                bitmap = new Bitmap(size.Width, size.Height, PixelFormat.Format24bppRgb);
                BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, size.Width, size.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat);

                try
                {
                    unsafe
                    {
                        for (int i = 1; i <= (dataset.RasterCount > 3 ? 3 : dataset.RasterCount); ++i)
                        {
                            byte[] buffer = new byte[size.Width * size.Height];
                            OSGeo.GDAL.Band band = dataset.GetRasterBand(i);

                            //band.ReadRaster(x1, y1, x1width, y1height, buffer, size.Width, size.Height, (int)GT.HorizontalPixelResolution, (int)GT.VerticalPixelResolution);
                            band.ReadRaster(x1, y1, x1width, y1height, buffer, size.Width, size.Height, 0, 0);

                            int p_indx = 0;
                            int ch = 0;

                            //#warning Check correspondance between enum and integer values
                            if (band.GetRasterColorInterpretation() == OSGeo.GDAL.ColorInterp.GCI_BlueBand) ch = 0;
                            if (band.GetRasterColorInterpretation() == OSGeo.GDAL.ColorInterp.GCI_GreenBand) ch = 1;
                            if (band.GetRasterColorInterpretation() == OSGeo.GDAL.ColorInterp.GCI_RedBand) ch = 2;
                            if (band.GetRasterColorInterpretation() != OSGeo.GDAL.ColorInterp.GCI_PaletteIndex)
                            {
                                for (int y = 0; y < size.Height; y++)
                                {
                                    byte* row = (byte*)bitmapData.Scan0 + (y * bitmapData.Stride);
                                    for (int x = 0; x < size.Width; x++, p_indx++)
                                    {
                                        row[x * iPixelSize + ch] = buffer[p_indx];
                                    }
                                }
                            }
                            else //8bit Grayscale
                            {
                                for (int y = 0; y < size.Height; y++)
                                {
                                    byte* row = (byte*)bitmapData.Scan0 + (y * bitmapData.Stride);
                                    for (int x = 0; x < size.Width; x++, p_indx++)
                                    {
                                        row[x * iPixelSize] = buffer[p_indx];
                                        row[x * iPixelSize + 1] = buffer[p_indx];
                                        row[x * iPixelSize + 2] = buffer[p_indx];
                                    }
                                }
                            }
                        }
                    }
                }
                finally
                {
                    bitmap.UnlockBits(bitmapData);
                }
            }
            g.DrawImage(bitmap, new System.Drawing.Point(0, 0));
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:91,代码来源:GdalRasterLayer.cs


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