コード例 #1
0
ファイル: CloudsatProjection.cs プロジェクト: windygu/hispeed
        public void ToRaster(string[] cloudsatfiles, int bandNo, int heightLevel, IRasterDataProvider oraster)
        {
            _cloudsatfiles = cloudsatfiles;
            _bandNo        = bandNo;
            _band          = oraster.GetRasterBand(1);
            _heightLevel   = heightLevel;
            int   ox          = oraster.Width;
            int   oy          = oraster.Height;
            float resolutionx = oraster.ResolutionX;
            float resolutiony = oraster.ResolutionY;
            Size  osize       = new Size(oraster.Width, oraster.Height);

            GeoDo.RSS.Core.DF.CoordEnvelope env = oraster.CoordEnvelope;
            short[] refValues = new short[ox * oy];
            for (int i = 0; i < _cloudsatfiles.Length; i++)
            {
                float[] latitudes;
                float[] longitudes;
                int     h;
                string  fullfilename = _cloudsatfiles[i];
                int     cou, minX, maxX;
                short[] datas = null;
                int     level = _heightLevel;//
                int     xn;
                using (CloudsatDataProvider raster = GeoDataDriver.Open(fullfilename) as CloudsatDataProvider)
                {
                    CloudSatRasterBand band = raster.GetRasterBand(_bandNo) as CloudSatRasterBand;
                    h          = band.Height;//37081
                    latitudes  = raster.ReadVdata("Latitude", null, 0, h) as float[];
                    longitudes = raster.ReadVdata("Longitude", null, 0, h) as float[];
                    cou        = 0;
                    minX       = 0;
                    maxX       = h;
                    IntersectEnvelope(latitudes, longitudes, env, ref cou, ref minX, ref maxX);
                    xn    = maxX - minX + 1;
                    datas = readData(new int[] { minX, level }, new int[] { xn, 1 }, band);
                }
                if (cou > 0 && (minX != 0 || maxX != h))
                {
                    float[] lats  = new float[xn];
                    float[] longs = new float[xn];
                    Buffer.BlockCopy(latitudes, minX * 4, lats, 0, xn * 4);
                    Buffer.BlockCopy(longitudes, minX * 4, longs, 0, xn * 4);
                    latitudes  = lats;
                    longitudes = longs;
                }
                PointProjection.PointToRasterInt16(longitudes, latitudes, datas, env, resolutionx, resolutiony, osize, ref refValues);
            }
            GCHandle handle = GCHandle.Alloc(refValues, GCHandleType.Pinned);

            try
            {
                _band.Write(0, 0, ox, oy, handle.AddrOfPinnedObject(), enumDataType.Int16, ox, oy);
            }
            finally
            {
                handle.Free();
            }
        }
コード例 #2
0
        public override void Execute(string argument)
        {
            if (string.IsNullOrWhiteSpace(argument) || !Directory.Exists(argument))
            {
                return;
            }
            string fullfilename;
            string maskpng = AppDomain.CurrentDomain.BaseDirectory + @"\SystemData\ProductArgs\CLD\Cloudsat_Overview_withcountry.png";

            fullfilename = argument;
            ICommand cmd = _smartSession.CommandEnvironment.Get(2000);

            if (cmd != null)
            {
                cmd.Execute(maskpng);
            }
            GeoDo.RSS.Core.DF.CoordEnvelope env = TryGetActiveViewerEnv();
            if (env == null)
            {
                env = new RSS.Core.DF.CoordEnvelope(65, 145, 10, 60);
            }
            //如果测试整个影像数据,则输出图像为:0,37081,37081
            int x1    = 0;
            int x2    = 37081;
            int outnx = 2000;
            int h1    = -1;      //# km
            int h2    = 21;      //# km
            int nz    = 400;     //# Number of pixels in the vertical.(这个偏移需要指定)
            int dtnx  = 0;       //125
            int dtny  = 0;       //13000
            int xn    = x2 - x1; //值从1700到2000,要读取的实际横轴方向数据。(最后这个偏移会通过地理范围,或者时间范围,计算出来)
            //return;
            CloudsatDataProvider raster = GeoDataDriver.Open(fullfilename) as CloudsatDataProvider;
            CloudSatRasterBand   band   = raster.GetRasterBand(1) as CloudSatRasterBand;

            dtnx = band.Width;  //层数
            dtny = band.Height; //点数
            sw.Start();
            float[] Latitude   = raster.ReadVdata("Latitude", null, x1, x2) as float[];
            float[] Longtitude = raster.ReadVdata("Longitude", null, x1, x2) as float[];
            sw.Stop();
            elapsed = sw.ElapsedMilliseconds;
            Console.WriteLine("ReadVdata" + elapsed + "毫秒");
            int cou      = 0;
            int minIndex = 0;
            int maxIndex = Latitude.Length;

            IntersectEnvelope(Latitude, Longtitude, env, ref cou, ref minIndex, ref maxIndex);

            Console.WriteLine(cou + "点在指定范围内");
            float[] times = raster.ReadVdata("Profile_time", null, x1, x2) as float[];
            if (cou > 0 && (x1 != minIndex || x2 != maxIndex))
            {
                x1 = minIndex;
                x2 = maxIndex;
                xn = x2 - x1 + 1;
                float[] lats  = new float[xn];
                float[] longs = new float[xn];
                float[] ts    = new float[xn];
                Buffer.BlockCopy(Latitude, x1 * 4, lats, 0, xn * 4);
                Buffer.BlockCopy(Longtitude, x1 * 4, longs, 0, xn * 4);
                Buffer.BlockCopy(times, x1 * 4, ts, 0, xn * 4);
                Latitude   = lats;
                Longtitude = longs;
                times      = ts;
            }
            string   start_time = raster.ReadAttribute("start_time") as string;
            DateTime dt_start_time;

            dt_start_time = DateTime.ParseExact(start_time, "yyyyMMddHHmmss", null);
            List <DateTime> dts = new List <DateTime>();

            foreach (float time in times)
            {
                dts.Add(dt_start_time.AddMinutes(time));                                              //应为AddSeconds()
            }
            short[] heights = readSDS("Height", new int[] { x1, 0 }, new int[] { xn, dtnx }, raster); //p1c1,p1c2,..,p1c125,p2c1,...
            short[] datas   = readData(new int[] { x1, 0 }, new int[] { xn, dtnx }, band);

            float[] X = new float[xn];//原始数据中的数据点号
            for (int i = 0; i < xn; i++)
            {
                X[i] = i + x1;
            }
            //heights数据是x=125,y=100=>Z[100,125]
            float[,] Z = new float[xn, dtnx];                 //每个点的高度xn = 100, dtnx =125;
            for (int i = 0; i < dtnx; i++)                    //heights的列,层数
            {
                for (int j = 0; j < xn; j++)                  //heights的行,点数
                {
                    Z[j, i] = heights[j * dtnx + i] * 0.001f; //m-->km
                }
            }

            short[,] newdata = new short[xn, dtnx];//点数,层数
            var dest = Marshal.UnsafeAddrOfPinnedArrayElement(newdata, 0);

            Marshal.Copy(datas, 0, dest, datas.Length);//将数据的一维数组变化为2维数组
            Marshal.Release(dest);

            short[,] dat = Rote <short>(newdata);//调换数组的行列,dat为层数×点数的数组;

            Bitmap bmp = null;
            IntPtr src;

            outnx             = xn < 4000 ? xn : 4000;
            float[,] dataf    = interp2d_12(newdata, X, Z, x1, x2, outnx, h2, h1, nz); //将数据进行插值
            float[,] newdataf = Rote <float>(dataf);                                   //调换数组的行列,dat为层数×点数的数组;
            int count = newdataf.Length;

            float[] datac = new float[count];
            src = Marshal.UnsafeAddrOfPinnedArrayElement(newdataf, 0);//
            Marshal.Copy(src, datac, 0, newdataf.Length);
            Marshal.Release(dest);
            DisplayLonLat(Latitude, Longtitude, fullfilename);
            //string[] dtimes = new string[dts.Count];
            //for(int i =0;i< dts.Count;i++)
            //{
            //    DateTime dt  = dts[i];
            //    dtimes[i] = dt.ToString("HH:mm:ss");
            //}
            //try
            //{
            //    bmp = ToBitmap(outnx, nz, datac);//点数(宽),层数(高)
            //    if (bmp != null)
            //    {
            //        string bmpfilename = MifEnvironment.GetFullFileName("2B-GEOPROF.Radar_Reflectivity.bmp");
            //        bmp.Save(bmpfilename);
            //        //OpenFileFactory.Open(bmpfilename);

            //        CloudsatPlotWnd wnd = _smartSession.SmartWindowManager.SmartToolWindowFactory.GetSmartToolWindow(_id) as CloudsatPlotWnd;
            //        if (wnd != null)
            //        {
            //            _smartSession.SmartWindowManager.DisplayWindow(wnd, new WindowPosition(System.Windows.Forms.DockStyle.Bottom, false));
            //            wnd.Reset(fullfilename, bmp, x1, x2, h1, h2, dtimes, null);
            //        }

            //        frmPlot frm = new frmPlot();
            //        ucCloudsatPlot plots = frm.plots;
            //        plots.AddYAxis(dtimes);
            //        plots.Reset(fullfilename, bmp, x1, x2, h1, h2, null);
            //        //plots.Rerender();
            //        //frm.Reset(fullfilename, bmp, x1, x2, h1, h2, dtimes, null);
            //        frm.Show();
            //    }
            //}
            //finally
            //{
            //    //if (bmp != null)
            //    //    bmp.Dispose();
            //}
        }