예제 #1
0
 protected override void ReadLocations(IRasterDataProvider srcRaster, out double[] longitudes, out double[] latitudes, out Size locationSize)
 {
     try
     {
         IBandProvider srcbandpro = srcRaster.BandProvider as IBandProvider;
         {
             locationSize = new Size(srcRaster.Width, srcRaster.Height);
             longitudes   = new Double[srcRaster.Width * srcRaster.Height];
             latitudes    = new Double[srcRaster.Width * srcRaster.Height];
             using (IRasterBand lonBand = srcbandpro.GetBands(Longitude)[0])
             {
                 using (IRasterBand latBand = srcbandpro.GetBands(Latitude)[0])
                 {
                     unsafe
                     {
                         fixed(Double *ptrLong = longitudes)
                         fixed(Double * ptrLat = latitudes)
                         {
                             {
                                 IntPtr bufferPtrLat  = new IntPtr(ptrLat);
                                 IntPtr bufferPtrLong = new IntPtr(ptrLong);
                                 latBand.Read(0, 0, locationSize.Width, locationSize.Height, bufferPtrLat, enumDataType.Double, locationSize.Width, locationSize.Height);
                                 lonBand.Read(0, 0, locationSize.Width, locationSize.Height, bufferPtrLong, enumDataType.Double, locationSize.Width, locationSize.Height);
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         throw new Exception("读取经纬度数据集失败:" + ex.Message, ex);
     }
 }
예제 #2
0
파일: Form1.cs 프로젝트: configare/hispeed
 private void ReadLatLong(IRasterDataProvider srcRaster, out double[] longitudes, out double[] latitudes)
 {
     try
     {
         IBandProvider srcbandpro = srcRaster.BandProvider as IBandProvider;
         {
             Size srSize = new System.Drawing.Size(srcRaster.Width, srcRaster.Height);
             longitudes = new Double[srcRaster.Width * srcRaster.Height];
             latitudes  = new Double[srcRaster.Width * srcRaster.Height];
             using (IRasterBand lonBand = srcbandpro.GetBands("Longitude")[0])
             {
                 using (IRasterBand latBand = srcbandpro.GetBands("Latitude")[0])
                 {
                     unsafe
                     {
                         fixed(Double *ptrLong = longitudes)
                         fixed(Double * ptrLat = latitudes)
                         {
                             {
                                 IntPtr bufferPtrLat  = new IntPtr(ptrLat);
                                 IntPtr bufferPtrLong = new IntPtr(ptrLong);
                                 latBand.Read(0, 0, srSize.Width, srSize.Height, bufferPtrLat, enumDataType.Double, srSize.Width, srSize.Height);
                                 lonBand.Read(0, 0, srSize.Width, srSize.Height, bufferPtrLong, enumDataType.Double, srSize.Width, srSize.Height);
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         throw new Exception("获取经纬度数据集失败:" + ex.Message, ex);
     }
 }
예제 #3
0
 //读取定位信息(经纬度数据集)
 private void ReadLongitudeLatitude(IRasterDataProvider srcRaster, out double[] longitudes, out double[] latitudes)
 {
     IBandProvider srcbandpro = srcRaster.BandProvider as IBandProvider;
     {
         Size srSize = new System.Drawing.Size(srcRaster.Width, srcRaster.Height);
         longitudes = new Double[srcRaster.Width * srcRaster.Height];
         latitudes  = new Double[srcRaster.Width * srcRaster.Height];
         using (IRasterBand lonsBand = srcbandpro.GetBands(Longitude)[0])
         {
             using (IRasterBand latBand = srcbandpro.GetBands(Latitude)[0])
             {
                 unsafe
                 {
                     fixed(Double *ptrLong = longitudes)
                     fixed(Double * ptrLat = latitudes)
                     {
                         {
                             IntPtr bufferPtrLat  = new IntPtr(ptrLat);
                             IntPtr bufferPtrLong = new IntPtr(ptrLong);
                             latBand.Read(0, 0, srSize.Width, srSize.Height, bufferPtrLat, enumDataType.Double, srSize.Width, srSize.Height);
                             lonsBand.Read(0, 0, srSize.Width, srSize.Height, bufferPtrLong, enumDataType.Double, srSize.Width, srSize.Height);
                         }
                     }
                 }
             }
         }
     }
 }
예제 #4
0
        private void ReadLocations(IRasterDataProvider srcRaster, out IRasterBand longitudeBand, out IRasterBand latitudeBand)
        {
            IBandProvider srcbandpro = srcRaster.BandProvider as IBandProvider;

            IRasterBand[] lonsBands = srcbandpro.GetBands("Longitude");
            IRasterBand[] latBands  = srcbandpro.GetBands("Latitude");
            if (lonsBands == null || latBands == null || lonsBands.Length == 0 || latBands.Length == 0 || lonsBands[0] == null || latBands[0] == null)
            {
                throw new Exception("获取经纬度数据失败");
            }
            longitudeBand = lonsBands[0];
            latitudeBand  = latBands[0];
        }
예제 #5
0
        //准备[太阳高度角订正]参数,目前还没有太阳高度角订正的公式。
        private void ReadySolarZenithArgs(IRasterDataProvider srcRaster)
        {
            IBandProvider bandPrd = srcRaster.BandProvider;

            IRasterBand[] bands = bandPrd.GetBands("SolarZenith");
            if (bands == null || bands.Length == 0 || bands[0] == null)
            {
                throw new Exception("读取Noaa 1BD太阳天顶角失败:无法获取到SolarZenith波段信息");//读取天顶角数值
            }
            try
            {
                using (IRasterBand band = bands[0])
                {
                    double[] data = new double[band.Width * band.Height];
                    unsafe
                    {
                        fixed(Double *ptr = data)
                        {
                            IntPtr bufferPtr = new IntPtr(ptr);

                            band.Write(0, 0, band.Width, band.Height, bufferPtr, enumDataType.Double, band.Width, band.Height);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("读取Noaa 1BD太阳天顶角失败:" + ex.Message, ex);
            }
        }
예제 #6
0
        private Int16[] ReadBandByNameToInt16(IRasterDataProvider srcRaster, string bandName)
        {
            IBandProvider bandPrd = srcRaster.BandProvider;

            IRasterBand[] bands = bandPrd.GetBands(bandName);
            if (bands == null || bands.Length == 0 || bands[0] == null)
            {
                throw new Exception("读取波段" + bandName + "失败:无法获取该通道信息");
            }
            try
            {
                using (IRasterBand band = bands[0])
                {
                    Int16[] data = new Int16[band.Width * band.Height];
                    unsafe
                    {
                        fixed(Int16 *ptr = data)
                        {
                            IntPtr bufferPtr = new IntPtr(ptr);

                            band.Read(0, 0, band.Width, band.Height, bufferPtr, enumDataType.Int16, band.Width, band.Height);
                        }
                    }
                    return(data);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("读取波段" + bandName + "失败:" + ex.Message, ex);
            }
        }
예제 #7
0
        protected override void ReadLocations(IRasterDataProvider geoRaster, out double[] longitudes, out double[] latitudes, out Size lonSize)
        {
            IBandProvider srcbandpro = geoRaster.BandProvider as IBandProvider;
            {
                IRasterBand[] lonsBands = srcbandpro.GetBands("Longitude");
                using (IRasterBand lonsBand = lonsBands[0])
                {
                    lonSize    = new Size(lonsBand.Width, lonsBand.Height);
                    longitudes = new Double[lonsBand.Width * lonsBand.Height];
                    unsafe
                    {
                        fixed(Double *ptrLong = longitudes)
                        {
                            IntPtr bufferPtrLong = new IntPtr(ptrLong);

                            lonsBand.Read(0, 0, lonsBand.Width, lonsBand.Height, bufferPtrLong, enumDataType.Double, lonsBand.Width, lonsBand.Height);
                        }
                    }
                }
                IRasterBand[] latBands = srcbandpro.GetBands("Latitude");
                using (IRasterBand latBand = latBands[0])
                {
                    latitudes = new Double[lonSize.Width * lonSize.Height];
                    unsafe
                    {
                        fixed(Double *ptrLat = latitudes)
                        {
                            {
                                IntPtr bufferPtrLat = new IntPtr(ptrLat);
                                latBand.Read(0, 0, latBand.Width, latBand.Height, bufferPtrLat, enumDataType.Double, latBand.Width, latBand.Height);
                            }
                        }
                    }
                }
            }
        }
예제 #8
0
        private float[] ReadDataSetToSingle(IBandProvider srcbandpro, Size srcSize, string dataSetName, int bandIndex)
        {
            Single[] data = new Single[srcSize.Width * srcSize.Height];
            using (IRasterBand rasterBand = srcbandpro.GetBands(dataSetName)[0])
            {
                unsafe
                {
                    fixed(Single *ptr = data)
                    {
                        IntPtr bufferPtr = new IntPtr(ptr);

                        rasterBand.Read(0, 0, srcSize.Width, srcSize.Height, bufferPtr, enumDataType.Float, srcSize.Width, srcSize.Height);
                    }
                }
            }
            return(data);
        }
예제 #9
0
        unsafe public void SetBandProvider()
        {
            string fname            = "d:\\0111d2.n16.1bd";
            IRasterDataProvider prd = GeoDataDriver.Open(fname) as IRasterDataProvider;
            IBandProvider       bp  = prd.BandProvider;

            IRasterBand[] rb = bp.GetBands("Longitude");
            Console.WriteLine(rb);
            Assert.NotNull(rb);
            UInt16[] buffer = new UInt16[4];
            fixed(UInt16 *ptr = buffer)
            {
                IntPtr bufferPtr = new IntPtr(ptr);

                rb[0].Read(0, 0, 2, 2, bufferPtr, enumDataType.UInt16, 2, 2);
            }
        }
예제 #10
0
        private Int16[] ReadDataSetToInt16(IBandProvider srcbandpro, Size srcSize, string dataSetName, int bandIndex)
        {
            Int16[]       data        = new Int16[srcSize.Width * srcSize.Height];
            IRasterBand[] rasterBands = srcbandpro.GetBands(dataSetName);
            using (IRasterBand rasterBand = rasterBands[0])
            {
                unsafe
                {
                    fixed(Int16 *ptr = data)
                    {
                        IntPtr bufferPtr = new IntPtr(ptr);

                        rasterBand.Read(0, 0, srcSize.Width, srcSize.Height, bufferPtr, enumDataType.Int16, srcSize.Width, srcSize.Height);
                    }
                }
            }
            return(data);
        }
예제 #11
0
        private IRasterBand[] TryCreateRasterDataBands(IRasterDataProvider srcRaster, FY3_MERSI_PrjSettings fy3prjSettings, Action <int, string> progressCallback)
        {
            IBandProvider      srcbandpro  = srcRaster.BandProvider as IBandProvider;
            List <IRasterBand> rasterBands = new List <IRasterBand>();

            for (int i = 0; i < _prjBands.Length; i++)
            {
                if (progressCallback != null)
                {
                    progressCallback(_readyProgress++, "准备第" + i + "个输入数据通道");
                }
                PrjBand       bandMap  = _prjBands[i];
                IRasterBand[] latBands = srcbandpro.GetBands(bandMap.DataSetName);
                IRasterBand   band     = latBands[bandMap.DataSetIndex];
                rasterBands.Add(band);
            }
            return(rasterBands.ToArray());
        }
예제 #12
0
        /// <summary> 读取通道值</summary>
        private void ReadBandData(UInt16[] bandData, IRasterDataProvider srcRaster, string bandName, int bandNumber, Size srcSize)
        {
            IBandProvider srcbandpro = srcRaster.BandProvider as IBandProvider;
            {
                using (IRasterBand latBand = srcbandpro.GetBands(bandName)[bandNumber])
                {
                    unsafe
                    {
                        fixed(UInt16 *ptr = bandData)
                        {
                            IntPtr bufferptr = new IntPtr(ptr);

                            latBand.Read(0, 0, srcSize.Width, srcSize.Height, bufferptr, enumDataType.UInt16, srcSize.Width, srcSize.Height);
                        }
                    }
                }
            }
        }
예제 #13
0
        public void TestReadHDF()//持续运行多次后,自动退出
        {
            IRasterDataProvider srcPrd = GetReader();

            MessageBox.Show("创建provider成功");
            try
            {
                for (int i = 0; i < 10; i++)
                {
                    IBandProvider srcbandpro = srcPrd.BandProvider as IBandProvider;
                    {
                        IRasterBand[] latBands = srcbandpro.GetBands("EV_1KM_RefSB");
                        IRasterBand   latBand  = latBands[0];
                        {
                            Size     srSize = new Size(latBand.Width / 2, latBand.Height / 2);
                            UInt16[] lats   = new UInt16[srSize.Width * srSize.Height];
                            unsafe
                            {
                                fixed(UInt16 *ptrLat = lats)
                                {
                                    IntPtr bufferPtrLat = new IntPtr(ptrLat);

                                    latBand.Read(0, 0, srSize.Width, srSize.Height, bufferPtrLat, enumDataType.UInt16, srSize.Width, srSize.Height);
                                }
                            }
                        }
                    }
                    MessageBox.Show("读取通道数据成功");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                srcPrd.Dispose();
                GC.SuppressFinalize(false);
            }
        }
예제 #14
0
 private void ReadDnIS(IRasterDataProvider srcImgRaster, string dsName)
 {
     if (srcImgRaster == null)
     {
         throw new ArgumentNullException("srcRaster", "获取亮温转换参数失败:参数srcRaster为空");
     }
     if (dsName == null)
     {
         throw new ArgumentNullException("dataSetName", "获取亮温转换参数失败:参数srcRaster为空");
     }
     try
     {
         IBandProvider srcbandpro = srcImgRaster.BandProvider as IBandProvider;
         int           count      = srcbandpro.GetBands(dsName).Length;
         _dsIntercept = ReadDataSetAttrToFloat(srcbandpro, dsName, "Intercept", count);
         _dsSlope     = ReadDataSetAttrToFloat(srcbandpro, dsName, "Slope", count);
     }
     catch (Exception ex)
     {
         throw new Exception("获取亮温转换参数失败:" + ex.Message, ex.InnerException);
     }
 }
예제 #15
0
        public unsafe void OpenFile()
        {
            string fname = "d:\\NOAA18_AVHRR_CHINA_L1_20090806_N3_1000M.1bd";
            //GeoDataDriver.Open(fname) as IRasterDataProvider;// ;
            IRasterDataDriver driver = GeoDataDriver.GetDriverByName("NOAA_1BD") as IRasterDataDriver;
            //Assert.NotNull(driver);
            IRasterDataProvider prd = GeoDataDriver.Open(fname) as IRasterDataProvider;

            //GeoDataDriver.Open(fname) as IRasterDataProvider;
            Assert.NotNull(prd);
            Console.WriteLine(prd.BandCount.ToString());
            IBandProvider bp = prd.BandProvider;

            IRasterBand[] rb = bp.GetBands("SolarZenith");
            Assert.NotNull(rb);


            double[]  buffer = new double[10004480];
            Stopwatch sw     = new Stopwatch();

            fixed(double *ptr = buffer)
            {
                IntPtr bufferPtr = new IntPtr(ptr);

                sw.Start();
                rb[0].Read(0, 0, 2048, 4885, bufferPtr, enumDataType.Double, 2048, 4885);
                sw.Stop();
                //SecondaryBand_1BD sb = rb[0] as SecondaryBand_1BD;
                //sb.DirectReadGeo(0, 0, 2048, 4885, bufferPtr, enumDataType.Double, 2048, 4885, true);
                //Console.WriteLine(sb.time);
                //Console.WriteLine(sw.ElapsedMilliseconds);
            }

            Console.WriteLine(sw.ElapsedMilliseconds);
            //for (int i = 0; i < 5000; i++)
            //{
            //    Console.WriteLine(buffer[i]);
            //}
        }
예제 #16
0
        public unsafe void TestBandProvider()
        {
            string fname            = "d:\\NOAA18_AVHRR_CHINA_L1_20090806_N3_1000M.1bd";
            IRasterDataProvider prd = GeoDataDriver.Open(fname) as IRasterDataProvider;
            IBandProvider       bp  = prd.BandProvider;

            IRasterBand[] rb = bp.GetBands("SolarZenith");
            Assert.NotNull(rb);
            SecondaryBand_1BD sb = rb[0] as SecondaryBand_1BD;

            //double[] buffer = new double[4096];

            //fixed (double* ptr = buffer)
            //{
            //    IntPtr bufferPtr = new IntPtr(ptr);
            //    sb.Read(0, 6000, 2048, 1, bufferPtr, enumDataType.Double, 2048, 1);
            //}
            //for (int i = 0; i < 2048; i++)
            //{
            //    Console.WriteLine(buffer[i]);
            //}

            //Console.WriteLine(rb);
            //List<Int16[]> ta = sb.ReadAngleInfo(200, 1, 0);
            //for (int i = 0; i < 51; i++)
            //{
            //    Console.WriteLine(ta[0][i]);
            //}
            //Int16[] buffer = new Int16[prd.Width * prd.Height];
            //unsafe
            //{
            //    fixed (Int16* ptr = buffer)
            //    {
            //        IntPtr bufferPtr = new IntPtr(ptr);
            //        rb[0].Read(0, 0, prd.Width, prd.Height, bufferPtr, enumDataType.Int16, prd.Width, prd.Height);
            //    }
            //}
        }
예제 #17
0
        protected override void ReadLocations(IRasterDataProvider locationRaster, out double[] xs, out double[] ys, out System.Drawing.Size locationSize)
        {
            IBandProvider srcbandpro = locationRaster.BandProvider as IBandProvider;

            {
                IRasterBand[] lonsBands = srcbandpro.GetBands("Longitude");
                using (IRasterBand lonsBand = lonsBands[0])
                {
                    locationSize = new Size(lonsBand.Width, lonsBand.Height);
                    xs           = new Double[lonsBand.Width * lonsBand.Height];
                    unsafe
                    {
                        fixed(Double *ptrLong = xs)
                        {
                            IntPtr bufferPtrLong = new IntPtr(ptrLong);

                            lonsBand.Read(0, 0, lonsBand.Width, lonsBand.Height, bufferPtrLong, enumDataType.Double, lonsBand.Width, lonsBand.Height);
                        }
                    }
                }
                IRasterBand[] latBands = srcbandpro.GetBands("Latitude");
                using (IRasterBand latBand = latBands[0])
                {
                    ys = new Double[locationSize.Width * locationSize.Height];
                    unsafe
                    {
                        fixed(Double *ptrLat = ys)
                        {
                            {
                                IntPtr bufferPtrLat = new IntPtr(ptrLat);
                                latBand.Read(0, 0, latBand.Width, latBand.Height, bufferPtrLat, enumDataType.Double, latBand.Width, latBand.Height);
                            }
                        }
                    }
                }
            }
            if (_xzoom != 1d)
            {
                for (int i = 0; i < xs.Length; i++)
                {
                    xs[i] = xs[i] * _xzoom;
                }
            }
            if (_xzoom != 1d)
            {
                for (int i = 0; i < ys.Length; i++)
                {
                    ys[i] = ys[i] * _yzoom;
                }
            }
            if (_prjSettings != null && _prjSettings.ExtArgs != null && _prjSettings.ExtArgs.Contains("360"))
            {
                for (int i = 0; i < xs.Length; i++)
                {
                    if (xs[i] > 180)
                    {
                        xs[i] = xs[i] - 360d;
                    }
                }
            }
        }
예제 #18
0
        private void TestProj()
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            Size srSize = Size.Empty;

            Double[] lats  = null;
            Double[] longs = null;
            using (IRasterDataProvider srcPrd = GeoDataDriver.Open(@"D:\masData\FY3A_VIRRX_GBAL_L1_20110322_0525_1000M_MS.HDF") as IRasterDataProvider)
            {
                using (IBandProvider srcbandpro = srcPrd.BandProvider as IBandProvider)
                {
                    srSize = new System.Drawing.Size(srcPrd.Width, srcPrd.Height);
                    lats   = new Double[srcPrd.Width * srcPrd.Height];
                    longs  = new Double[srcPrd.Width * srcPrd.Height];
                    using (IRasterBand latBand = srcbandpro.GetBands("Latitude")[0])
                    {
                        using (IRasterBand lonsBand = srcbandpro.GetBands("Longitude")[0])
                        {
                            unsafe
                            {
                                fixed(Double *ptrLat = lats)
                                {
                                    fixed(Double *ptrLong = longs)
                                    {
                                        IntPtr bufferPtrLat  = new IntPtr(ptrLat);
                                        IntPtr bufferPtrLong = new IntPtr(ptrLong);

                                        latBand.Read(0, 0, srcPrd.Width, srcPrd.Height, bufferPtrLat, enumDataType.Double, srcPrd.Width, srcPrd.Height);
                                        lonsBand.Read(0, 0, srcPrd.Width, srcPrd.Height, bufferPtrLong, enumDataType.Double, srcPrd.Width, srcPrd.Height);
                                    }
                                }
                            }
                        }
                    }
                    stopwatch.Stop();
                    WriteLine("读取经纬度{0}ms", stopwatch.ElapsedMilliseconds);
                    stopwatch.Restart();
                    IRasterProjector     raster = new RasterProjector();
                    PrjEnvelope          destEnvelope;
                    Action <int, string> progressCallback = new Action <int, string>(OutProgress);
                    //progressCallback = null;  //测试不用进度条的情况
                    ISpatialReference srcSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile("WGS 1984.prj");
                    ISpatialReference dstSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByPrjFile("ChinaBoundary.prj");
                    raster.ComputeDstEnvelope(srcSpatialRef, longs, lats, srSize, dstSpatialRef, out destEnvelope, progressCallback);
                    stopwatch.Stop();
                    WriteLine("计算范围{0}ms", stopwatch.ElapsedMilliseconds);
                    WriteLine("范围{0}", destEnvelope.ToString());

                    Size     dstSize           = new Size((int)(destEnvelope.Width / 0.01), (int)(destEnvelope.Height / 0.01));
                    UInt16[] dstRowLookUpTable = new UInt16[dstSize.Width * dstSize.Height];
                    UInt16[] dstColLookUpTable = new UInt16[dstSize.Width * dstSize.Height];
                    raster.ComputeIndexMapTable(srcSpatialRef, longs, lats, srSize, dstSpatialRef, dstSize, destEnvelope,
                                                out dstRowLookUpTable, out dstColLookUpTable, progressCallback);

                    stopwatch.Stop();
                    WriteLine("计算投影查找表{0}ms", stopwatch.ElapsedMilliseconds);
                    stopwatch.Restart();

                    int srcBandCount = srcPrd.BandCount;
                    using (IRasterDataDriver drv = GeoDataDriver.GetDriverByName("LDF") as IRasterDataDriver)
                    {
                        string proj4 = dstSpatialRef.ToProj4String();
                        using (IRasterDataProvider prdWriter = drv.Create(@"d:\Myproj4LutX.ldf", dstSize.Width, dstSize.Height, srcBandCount,
                                                                          enumDataType.UInt16, "INTERLEAVE=BSQ", "VERSION=LDF", "SPATIALREF=" + proj4) as IRasterDataProvider)
                        {
                            UInt16[] dstData = new UInt16[dstSize.Width * dstSize.Height];
                            UInt16[] srcData = new UInt16[srSize.Width * srSize.Height];
                            //int perProgress = 0;
                            //int curProgress = 0;
                            for (int i = 0; i < srcBandCount; i++)
                            {
                                using (IRasterBand latBand = srcPrd.GetRasterBand(i + 1))
                                {
                                    unsafe
                                    {
                                        fixed(UInt16 *ptr = srcData)
                                        {
                                            IntPtr bufferptr = new IntPtr(ptr);

                                            latBand.Read(0, 0, srSize.Width, srSize.Height, bufferptr, enumDataType.UInt16, srSize.Width, srSize.Height);
                                        }
                                    }
                                }
                                //stopwatch.Stop();
                                //WriteLine("读取一个通道{0}ms,通道索引{1}", stopwatch.ElapsedMilliseconds, i + 1);
                                //stopwatch.Restart();
                                raster.Project <UInt16>(srcData, srSize, dstRowLookUpTable, dstColLookUpTable, dstSize, dstData, 0, progressCallback);
                                //stopwatch.Stop();
                                //WriteLine("投影一个通道{0}ms,通道索引{1}", stopwatch.ElapsedMilliseconds, i + 1);
                                //stopwatch.Restart();

                                using (IRasterBand band = prdWriter.GetRasterBand(i + 1))
                                {
                                    unsafe
                                    {
                                        fixed(UInt16 *ptr = dstData)
                                        {
                                            IntPtr bufferPtr = new IntPtr(ptr);

                                            band.Write(0, 0, band.Width, band.Height, bufferPtr, enumDataType.UInt16, band.Width, band.Height);
                                        }
                                    }
                                }
                                //curProgress = (i+1) * 100 / srcBandCount;
                                //if (progressCallback != null && curProgress > perProgress)
                                //{
                                //    progressCallback(curProgress, "");
                                //    perProgress = curProgress;
                                //}
                                //stopwatch.Stop();
                                //WriteLine("写出一个通道{0}ms", stopwatch.ElapsedMilliseconds);
                                //stopwatch.Restart();
                            }
                        }
                    }
                    stopwatch.Stop();
                    WriteLine("投影完所有通道{0}ms", stopwatch.ElapsedMilliseconds);
                    stopwatch.Restart();
                }
            }
        }
예제 #19
0
        void BuildOrbitPrjTransoform(object sender, EventArgs e)
        {
            IRasterBand lonBand, latBand;

            IRasterBand[] bs = _bandProvider.GetBands("Longitude");
            if (bs == null)
            {
                return;
            }
            lonBand = bs[0];
            bs      = _bandProvider.GetBands("Latitude");
            if (bs == null)
            {
                return;
            }
            latBand = bs[0];

            float[] lonBuffer = null;
            float[] latBuffer = null;
            //
            switch (lonBand.DataType)
            {
            case enumDataType.Float:
                lonBuffer = new float[lonBand.Width * lonBand.Height];
                latBuffer = new float[latBand.Width * latBand.Height];
                fixed(float *lonPtr = lonBuffer, latPtr = latBuffer)
                {
                    IntPtr lonIntPtr = new IntPtr(lonPtr);
                    IntPtr latIntPtr = new IntPtr(latPtr);

                    lonBand.Read(0, 0, lonBand.Width, lonBand.Height, lonIntPtr, enumDataType.Float, lonBand.Width, latBand.Height);
                    latBand.Read(0, 0, latBand.Width, latBand.Height, latIntPtr, enumDataType.Float, latBand.Width, latBand.Height);
                }

                break;

            case enumDataType.Double:
                double[] lonBufferDouble = new double[lonBand.Width * lonBand.Height];
                double[] latBufferDouble = new double[latBand.Width * latBand.Height];
                fixed(double *lonPtrd = lonBufferDouble, latPtrd = latBufferDouble)
                {
                    IntPtr lonIntPtr = new IntPtr(lonPtrd);
                    IntPtr latIntPtr = new IntPtr(latPtrd);

                    lonBand.Read(0, 0, lonBand.Width, lonBand.Height, lonIntPtr, enumDataType.Double, lonBand.Width, latBand.Height);
                    latBand.Read(0, 0, latBand.Width, latBand.Height, latIntPtr, enumDataType.Double, latBand.Width, latBand.Height);
                }

                lonBuffer = new float[lonBand.Width * lonBand.Height];
                latBuffer = new float[latBand.Width * latBand.Height];
                for (int i = 0; i < lonBuffer.Length; i++)
                {
                    lonBuffer[i] = (float)lonBufferDouble[i];
                    latBuffer[i] = (float)latBufferDouble[i];
                }
                break;
            }
            if (lonBuffer != null && latBuffer != null)
            {
                int     lonsWidth  = lonBand.Width;
                int     latsHeight = latBand.Height;
                float[] retLonBuffer, retLatBuffer;
                int     retWidth, retHeight;
                int     sample = 4;//经纬度数据集缩小4倍
                SampleMatrix(sample, lonBuffer, latBuffer, lonsWidth, latsHeight,
                             out retLonBuffer, out retLatBuffer, out retWidth, out retHeight);
                _orbitProjectionTransform = new OrbitProjectionTransform(retLonBuffer, retLatBuffer,
                                                                         new Size(retWidth, retHeight),
                                                                         _width / retWidth);
            }
        }