コード例 #1
0
        private static short[] readSDS(string sdsName, int[] start, int[] count, CloudsatDataProvider raster)
        {
            int    width      = count[0];
            int    height     = count[1];
            int    buffersize = width * height;
            int    typesize   = 2;
            IntPtr ptr        = Marshal.AllocHGlobal(buffersize * typesize);

            try
            {
                bool stat = raster.ReadSDS(sdsName, start, count, ptr);
                if (stat)
                {
                    short[] buffer = new short[buffersize];
                    Marshal.Copy(ptr, buffer, 0, buffersize);
                    return(buffer);
                }
                else
                {
                    return(null);
                }
            }
            finally
            {
                Marshal.FreeHGlobal(ptr);
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: configare/hispeed
        static void Main(string[] args)
        {
            string fullfilename       = @"E:\Smart\CloudArgs\cloudsat\2007101034511_05065_CS_2B-GEOPROF_GRANULE_P_R04_E02.hdf";
            CloudsatDataProvider data = new CloudsatDataProvider(fullfilename, null, null);

            data.Test();
        }
コード例 #3
0
        public static void GetCoverPtCount(object paras)
        {
            cloudsatF            cloudsatFg = paras as cloudsatF;
            string               file       = cloudsatFg.filename;
            double               minX       = cloudsatFg.minX;
            double               maxX       = cloudsatFg.maxX;
            double               minY       = cloudsatFg.minY;
            double               maxY       = cloudsatFg.maxY;
            CloudsatDataProvider locRst     = null;
            int inCount = 0;

            float[] lats, lons;
            using (locRst = GeoDataDriver.Open(file) as CloudsatDataProvider)
            {
                lats = locRst.ReadVdata("Latitude", null, 0, locRst.Height) as float[];
                lons = locRst.ReadVdata("Longitude", null, 0, locRst.Height) as float[];
            }
            for (int i = 0; i < lats.Length; i++)
            {
                if (lats[i] >= (double)minY && lats[i] <= (double)maxY && lons[i] >= (double)minY && lons[i] <= (double)maxY)
                {
                    inCount++;
                }
            }
            //return new int[] { lats.Length,inCount };
        }
コード例 #4
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();
            }
        }
コード例 #5
0
 protected override bool FileHeaderIsOK(string fname, string extName)
 {
     return(CloudsatDataProvider.IsSupport(fname, null));
 }
コード例 #6
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();
            //}
        }
コード例 #7
0
        public void Compute(Action <string> ProBack)
        {
            float[] lats = null, lons = null;
            double  minX, maxX, minY, maxY;

            foreach (long regionid in _allRegions.Keys)
            {
                PrjEnvelopeItem item = _allRegions[regionid];
                minX = item.PrjEnvelope.MinX; //10
                maxX = item.PrjEnvelope.MaxX; //60
                minY = item.PrjEnvelope.MinY; //65
                maxY = item.PrjEnvelope.MaxY; //145
                ProBack("\t开始进行CloudSAT数据与" + item.Name + "区域的关联计算...");
                Dictionary <Int32, double> granuleNOPct      = new Dictionary <Int32, double>();
                Dictionary <long, Double>  filePct           = new Dictionary <long, Double>();
                Dictionary <Int32, Int32>  granuleNOAllCount = new Dictionary <Int32, Int32>();
                string[] fNameParts;
                //string fName;
                int   granuleNO;
                float uplat, uplon, downlat, downlon;
                foreach (string file in _file2ID.Keys)
                {
                    try
                    {
                        //2007101052404_05066_CS_MODIS-AUX_GRANULE_P_R04_E02.hdf
                        string fname = Path.GetFileName(file);
                        ProBack("\t\t开始进行" + file + "与" + item.Name + "区域的关联计算...");
                        fNameParts = Path.GetFileNameWithoutExtension(file).Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
                        if (fNameParts.Length != 8)
                        {
                            continue;
                        }
                        if (fNameParts[2] != "CS")
                        {
                            continue;
                        }
                        granuleNO = int.Parse(fNameParts[1]);
                        if (!granuleNOPct.ContainsKey(granuleNO) && fNameParts[3].ToUpper() != "MODIS-AUX")//每个轨道号数据具有同一个覆盖度
                        {
                            int inCount = 0;
                            CloudsatDataProvider locRst = null;
                            ProBack("\t\t\t读取" + fname + "的经纬度数据集...");
                            using (locRst = GeoDataDriver.Open(file) as CloudsatDataProvider)
                            {
                                lats = locRst.ReadVdata("Latitude", null, 0, locRst.Height) as float[];
                                lons = locRst.ReadVdata("Longitude", null, 0, locRst.Height) as float[];
                            }
                            ProBack("\t\t\t开始计算" + fname + "与区域的相交...");
                            int firstpt = -1, lastpt = -1;
                            for (int i = 0; i < lats.Length; i++)
                            {
                                if (lats[i] >= minY && lats[i] <= maxY && lons[i] >= minX && lons[i] <= maxX)
                                {
                                    if (firstpt == -1)
                                    {
                                        firstpt = i;
                                    }
                                    lastpt = i;
                                    inCount++;
                                }
                            }
                            if (firstpt != -1)//存在覆盖该区域的点
                            {
                                #region 计算南点和北点的经纬度
                                if (firstpt != lastpt)//多于一个点
                                {
                                    if (lats[firstpt] > lats[lastpt])
                                    {
                                        uplat   = lats[firstpt];
                                        uplon   = lons[firstpt];
                                        downlat = lats[lastpt];
                                        downlon = lons[lastpt];
                                    }
                                    else
                                    {
                                        uplat   = lats[lastpt];
                                        uplon   = lons[lastpt];
                                        downlat = lats[firstpt];
                                        downlon = lons[firstpt];
                                    }
                                }
                                else
                                {
                                    uplat   = lats[firstpt];
                                    uplon   = lons[firstpt];
                                    downlat = lats[firstpt];
                                    downlon = lons[firstpt];
                                }
                                #endregion
                                #region 入库
                                //granuleNO,regionid,uplat,uplon,downlat,downlon,firstpt,lastpt
                                if (!_con.IshasRecord("cp_cloudsatinregionlatlon_tb", "GranuleNumber", granuleNO))
                                {
                                    _con.InsertCloudsatGranule2Region(granuleNO, regionid, uplat, uplon, downlat, downlon, firstpt, lastpt);
                                }
                                ProBack("\t\t\t将" + granuleNO + "起始范围计算结果入库成功!");
                                #endregion
                            }
                            granuleNOPct.Add(granuleNO, inCount / (lats.Length * 1.0) * 100.0);
                            granuleNOAllCount.Add(granuleNO, lats.Length);
                        }
                        if (granuleNOAllCount.ContainsKey(granuleNO))
                        {
                            if (!_con.IshasRecord("cp_cloudsat2region_tb", "CloudSatID", _file2ID[file]))
                            {
                                _con.InsertCloudsat2RegionTable(_file2ID[file], granuleNOAllCount[granuleNO], regionid, granuleNOPct[granuleNO]);
                            }
                            ProBack("\t\t将" + fname + "计算结果入库成功!");
                        }
                    }
                    catch (System.Exception ex)
                    {
                        ProBack("\t" + file + "处理出错!" + ex.Message);
                    }
                }
            }
        }