Пример #1
0
 public static Dictionary <string, SortedDictionary <string, double> > Stat <T>(
     string rasterFile,
     string templateName,
     Dictionary <string, Func <T, bool> > multiFilter,
     Action <int, string> progressTracker, bool weight, float weightZoom, string vectorTemplate) where T : struct, IConvertible
 {
     if (string.IsNullOrWhiteSpace(templateName))
     {
         RasterStatByRaster stat = new RasterStatByRaster(progressTracker);
         return(stat.Stat <T>(rasterFile, null, multiFilter, weight, weightZoom));
     }
     else if (templateName.Contains("vector"))
     {
         string[] split           = templateName.Split(':');
         string   key             = split[0];
         string   shpFilename     = split[1];
         string   fieldName       = split[2];
         RasterStatByVector <T> v = new RasterStatByVector <T>(progressTracker);
         return(v.CountByVector(rasterFile, shpFilename, fieldName, multiFilter));
     }
     else if (templateName.Contains("raster"))
     {
         string tmpValue = templateName;
         if (templateName.Contains("raster"))
         {
             string[] split = templateName.Split(':');
             tmpValue = split[1];
         }
         RasterStatByRaster stat = new RasterStatByRaster(progressTracker);
         return(stat.Stat <T>(rasterFile, tmpValue, multiFilter, weight, weightZoom, vectorTemplate));
     }
     return(null);
 }
Пример #2
0
 /// <summary>
 /// 单条件
 /// 分类面积及面积百分比统计
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="rasterFiles"></param>
 /// <param name="templateName"></param>
 /// <param name="func"></param>
 /// <param name="progressTracker"></param>
 /// <returns></returns>
 public static Dictionary <string, double[]> StatPercent <T>(string[] rasterFiles, string templateName, Func <T, bool> func, Action <int, string> progressTracker)
 {
     if (templateName.Contains("vector"))
     {
         string[] split           = templateName.Split(':');
         string   key             = split[0];
         string   shpFilename     = split[1];
         string   fieldName       = split[2];
         RasterStatByVector <T> v = new RasterStatByVector <T>(progressTracker);
         return(v.MaxCountByVector(rasterFiles, shpFilename, fieldName, func));
     }
     return(null);
 }
Пример #3
0
 /// <summary>
 ///  平均值统计(分行政区域或其他):
 ///  =行政区划内各像元值相加/行政区划像素个数
 /// </summary>
 /// <param name="rasterFilename"></param>
 /// <param name="templateName"></param>
 /// <param name="func"></param>
 /// <param name="progressTracker"></param>
 /// <returns>
 /// SortedDictionary<string, double[3]>
 /// key:各矢量名字
 /// value:double[0],满足条件的像元和,double[1],满足条件的像元个数,double[2],当前矢量面的像元个数。
 /// </returns>
 public static SortedDictionary <string, double[]> SumAndCountByVector <T>(string rasterFile, string templateName, Func <T, bool> func, Action <int, string> progressTracker)
 {
     if (templateName.Contains("vector"))
     {
         string[] split           = templateName.Split(':');
         string   key             = split[0];
         string   shpFilename     = split[1];
         string   shpFieldName    = split[2];
         RasterStatByVector <T> v = new RasterStatByVector <T>(progressTracker);
         return(v.SumAndCountByVector(rasterFile, shpFilename, shpFieldName, func));
     }
     else
     {
         throw new NotSupportedException("暂未实现除基于矢量面的分段面积百分比统计");
     }
 }
Пример #4
0
        private IExtractResult StatFirePoint(string rasterFileName)
        {
            IRasterDataProvider inRaster = RasterDataDriver.Open(rasterFileName) as IRasterDataProvider;

            if (inRaster == null)
            {
                PrintInfo("读取栅格文件失败:" + inRaster);
                return(null);
            }
            SortedDictionary <string, StatAreaItem> result;
            RasterStatByVector <Int16> stat = new RasterStatByVector <Int16>(null);

            result = stat.CountByVector(inRaster, "大洲.shp", "CONTINENT",
                                        (cur, cursum) =>
            {
                return(cursum += cur);
            });
            if (result.Count == 0)
            {
                return(null);
            }
            List <string[]> resultList = new List <string[]>();

            foreach (string key in result.Keys)
            {
                resultList.Add(new string[] { key, result[key].GrandTotal.ToString() });
            }
            string         sentitle = "统计日期:" + DateTime.Now.ToShortDateString();
            RasterIdentify id       = new RasterIdentify(rasterFileName);

            id.ProductIdentify    = "FIR";
            id.SubProductIdentify = "GFCF";
            if (id.OrbitDateTime != null)
            {
                sentitle += "    轨道日期:" + id.OrbitDateTime.ToShortDateString();
            }
            string[]    columns        = new string[] { "大洲", "累计火点数" };
            IStatResult fresult        = new StatResult(sentitle, columns, resultList.ToArray());
            string      outputIdentify = _argumentProvider.GetArg("OutFileIdentify").ToString();
            string      title          = "全球火点大洲统计";
            string      filename       = StatResultToFile(new string[] { rasterFileName }, fresult, "FIR", outputIdentify, title, null, 1, true, 1);

            return(new FileExtractResult(outputIdentify, filename));
        }
Пример #5
0
 /// <summary>
 /// 单条件,面积及覆盖面积统计
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="rasterFiles"></param>
 /// <param name="templateName">
 /// 如果是矢量:
 /// vector:省级行政区.shp:Name
 /// 如果是栅格:
 /// 直接China_XjRaster|China_LandRaster
 /// 或者
 /// raster:China_XjRaster
 /// raster:China_LandRaster
 /// 如果是空,则代表统计当前区域面积。
 /// </param>
 /// <param name="func"></param>
 /// <param name="progressTracker"></param>
 /// <returns></returns>
 public static SortedDictionary <string, StatAreaItem> Stat <T>(string[] rasterFiles, string templateName, Func <T, bool> func, Action <int, string> progressTracker, bool isCombinSameDay)
 {
     if (templateName.Contains("vector"))
     {
         string[] split           = templateName.Split(':');
         string   key             = split[0];
         string   shpFilename     = split[1];
         string   fieldName       = split[2];
         RasterStatByVector <T> v = new RasterStatByVector <T>(progressTracker);
         return(v.CountByVector(rasterFiles, shpFilename, fieldName, func, isCombinSameDay));
     }
     else
     {
         string value = templateName;
         if (templateName.Contains("raster"))
         {
             string[] split = templateName.Split(':');
             value = split[1];
         }
         RasterStatByRaster rsm = new RasterStatByRaster(progressTracker);
         return(rsm.Stat <T>(rasterFiles, value, func, isCombinSameDay));
     }
 }
Пример #6
0
        internal IFileExtractResult GeneratorHB(IArgumentProvider argProvider, Dictionary <int, PixelFeature> features)
        {
            if (argProvider.DataProvider == null || features == null || features.Count == 0)
            {
                return(null);
            }
            DateTime      orbitDateTime = DateTime.MinValue;
            string        saveFilename = GetPLSFFilename(argProvider, out orbitDateTime);
            CoordEnvelope envelope = argProvider.DataProvider.CoordEnvelope;
            float         resolutionX = argProvider.DataProvider.ResolutionX;
            float         resolutionY = argProvider.DataProvider.ResolutionY;
            int           sample = argProvider.DataProvider.Width;
            int           line = argProvider.DataProvider.Height;
            int           row, col, index = 0;
            double        longitude, latitude;
            SortedDictionary <string, StatAreaItem> statResult;
            RasterStatByVector <Int16> stat = new RasterStatByVector <Int16>(null);
            List <int> inRegionIndex        = new List <int>();

            statResult = stat.CountByVector(argProvider.DataProvider, "禁烧区.shp", "JS",
                                            (cur, idx, cursum) =>
            {
                if (cur != 0)
                {
                    inRegionIndex.Add(idx);
                }
                return(cursum += cur);
            });
            using (StreamWriter sw = new StreamWriter(saveFilename, false, Encoding.Default))
            {
                foreach (int fet in features.Keys)
                {
                    if (features[fet].IsVertified)
                    {
                        row       = features[fet].PixelIndex / sample;
                        col       = features[fet].PixelIndex - row * sample;
                        longitude = envelope.MinX + col * resolutionX;
                        latitude  = envelope.MaxY - row * resolutionY;
                        //0
                        sw.Write((index++).ToString().PadLeft(7, ' '));
                        sw.Write("\t");
                        //1
                        sw.Write(latitude.ToString("0.00").PadLeft(6, ' '));
                        sw.Write("\t");
                        //2
                        sw.Write(longitude.ToString("0.00").PadLeft(7, ' '));
                        sw.Write("\t");
                        //3
                        sw.Write(features[fet].FireAreaNum.ToString().PadLeft(7, ' '));
                        sw.Write("\t");
                        //4
                        int xianJie = _xianJieDictionary.GetCode(longitude, latitude);
                        if (xianJie != default(int))
                        {
                            sw.Write(xianJie.ToString().PadLeft(6, ' '));
                        }
                        else
                        {
                            //sw.Write("-9999".PadLeft(6, ' '));
                            sw.Write("0".PadLeft(6, ' '));
                        }
                        sw.Write("\t");
                        //5
                        byte landUse = _landTypeDictionary.GetCode(longitude, latitude);
                        if (landUse != default(byte))
                        {
                            sw.Write(landUse.ToString().PadLeft(12, ' '));
                        }
                        else
                        {
                            //sw.Write("-9999".PadLeft(12, ' '));
                            sw.Write("0".PadLeft(12, ' '));
                        }
                        sw.Write("\t");
                        //6
                        sw.Write(features[fet].PixelArea.ToString("#0.000000").PadLeft(10, ' '));
                        sw.Write("\t");
                        //7
                        if (features[fet].PixelArea == 0)
                        {
                            sw.Write("0.0000".PadLeft(6, ' '));
                        }
                        else
                        {
                            sw.Write((features[fet].SecondPixelArea / (features[fet].PixelArea * 100) * 100).ToString("#0.0000").PadLeft(6, ' '));
                        }
                        sw.Write("\t");
                        //8
                        sw.Write("750.00".PadLeft(8, ' '));
                        sw.Write("\t");
                        //9
                        sw.Write(orbitDateTime.ToString("yyyy-MM-dd HH:mm").PadLeft(16, ' '));
                        sw.Write("\t");
                        //10
                        sw.Write(features[fet].FireIntensityGrade.ToString().PadLeft(8, ' '));
                        sw.Write("\t");
                        //11
                        //sw.Write(features[fet].FirIntensity.ToString("#.########").PadLeft(16, ' '));
                        sw.Write(features[fet].FirIntensity.ToString("0.0000000").PadLeft(16, ' '));
                        if (inRegionIndex.Contains(features[fet].PixelIndex))
                        {
                            sw.Write("是".PadLeft(16, ' '));
                        }
                        else
                        {
                            sw.Write(" ".PadLeft(16, ' '));
                        }
                        sw.WriteLine();
                    }
                }
            }
            if (File.Exists(saveFilename))
            {
                IFileExtractResult result = new FileExtractResult("PLSF", saveFilename);
                result.SetDispaly(false);
                return(result);
            }
            return(null);
        }
Пример #7
0
        private IExtractResult VSTATAlgorithm(string rasterFileName, string aoi, string keyName)
        {
            //IRasterDataProvider inRaster = RasterDataDriver.Open(rasterFileName) as IRasterDataProvider;
            RasterStatByVector <float> stat = new RasterStatByVector <float>(null);
            IStatResult     fresult         = null;
            string          filename        = "";
            List <string[]> resultList      = new List <string[]>();

            using (IRasterDataProvider inRaster = RasterDataDriver.Open(rasterFileName) as IRasterDataProvider)
            {
                if (aoi == "")
                {
                    double pixelSum = CompuCurPixel(rasterFileName);
                    resultList.Add(new string[] { "当前区域", pixelSum.ToString() });
                }
                else
                {
                    SortedDictionary <string, StatAreaItem> result;
                    result = stat.CountByVector(inRaster, aoi, keyName,
                                                (cur, cursum) =>
                    {
                        return(cursum += cur);
                    });
                    if (result.Count == 0)
                    {
                        return(null);
                    }
                    if (aoi == "土地利用类型_合并.shp")
                    {
                        foreach (string key in result.Keys)
                        {
                            resultList.Add(new string[] { key, result[key].GrandTotal.ToString() });
                        }
                    }
                    else
                    {
                        Dictionary <double, string> dic = new Dictionary <double, string>();
                        List <double> list = new List <double>();
                        foreach (string key in result.Keys)
                        {
                            foreach (string name in fieldValues)
                            {
                                if (key == name)
                                {
                                    dic.Add(result[key].GrandTotal, key);
                                    list.Add(result[key].GrandTotal);
                                }
                            }
                        }
                        list.Sort();
                        string   nam = null;
                        double[] ll  = list.ToArray();
                        for (int i = ll.Length - 1; i >= 0; i--)// 降序加入到resultList中
                        {
                            bool bb = dic.TryGetValue(ll[i], out nam);
                            resultList.Add(new string[] { nam, ll[i].ToString() });
                        }
                    }
                }
                string         sentitle = "统计日期:" + DateTime.Now.ToShortDateString();
                RasterIdentify id       = new RasterIdentify(rasterFileName);
                id.ProductIdentify    = "MWS";
                id.SubProductIdentify = "VSTA";
                if (id.OrbitDateTime != null)
                {
                    sentitle += "    轨道日期:" + id.OrbitDateTime.ToShortDateString();
                }
                string coluString = "";
                if (aoi == "省级行政区域_面.shp")
                {
                    coluString = "省界";
                }
                if (aoi == "县级行政区域_面.shp")
                {
                    coluString = "市县";
                }
                if (aoi == "土地利用类型_合并.shp")
                {
                    coluString = "土地利用类型";
                }
                if (aoi == "")
                {
                    coluString = "当前区域";
                }
                string[] columns = new string[] { coluString, "累计雪水当量体积(立方米)" };
                fresult = new StatResult(sentitle, columns, resultList.ToArray());
                string outputIdentify = _argumentProvider.GetArg("OutFileIdentify").ToString();
                string title          = coluString + "雪水当量体积统计";
                filename = StatResultToFile(new string[] { rasterFileName }, fresult, "MWS", outputIdentify, title, null, 1, true, 1);
                return(new FileExtractResult(outputIdentify, filename));
            }
        }
Пример #8
0
        /// <summary>
        /// 生成Excel环保部信息列表
        /// </summary>
        /// <param name="argProvider"></param>
        /// <param name="features"></param>
        /// <returns></returns>
        internal IFileExtractResult GeneratorHB(IArgumentProvider argProvider, Dictionary <int, FireAreaFeature> features)
        {
            DateTime        orbitDateTime = DateTime.MinValue;
            string          saveFilename  = GetFALTFilenameHB(argProvider, out orbitDateTime);
            List <string[]> excelInfos    = new List <string[]>();

            string[]      columns  = new string[] { "省", "地区", "县", "中心纬度", "中心经度", "火点像素数", "禁烧区", "明火面积(公顷)" };
            List <string> listTemp = new List <string>();

            SortedDictionary <string, StatAreaItem> statResult;
            RasterStatByVector <Int16> stat = new RasterStatByVector <Int16>(null);
            List <int> inRegionIndex        = new List <int>();

            statResult = stat.CountByVector(argProvider.DataProvider, "禁烧区.shp", "JS",
                                            (cur, idx, cursum) =>
            {
                if (cur != 0)
                {
                    inRegionIndex.Add(idx);
                }
                return(cursum += cur);
            });
            for (int i = 0; i < features.Count; i++)
            {
                if (features[i].FarmlandPercent == 0)
                {
                    continue;
                }
                listTemp.Add(string.IsNullOrEmpty(features[i].SJName) ? @"\" : features[i].SJName);
                listTemp.Add(string.IsNullOrEmpty(features[i].ShiName) ? @"\" : features[i].ShiName);
                if (string.IsNullOrEmpty(features[i].XJName))
                {
                    listTemp.Add(@"\");
                }
                else if (!string.IsNullOrEmpty(features[i].SJName + features[i].ShiName))
                {
                    listTemp.Add(features[i].XJName.Replace(features[i].SJName + features[i].ShiName, ""));
                }
                else
                {
                    listTemp.Add(features[i].XJName);
                }
                listTemp.Add(features[i].Latitude.ToString());
                listTemp.Add(features[i].Longitude.ToString());
                listTemp.Add(features[i].FireCount.ToString("#"));
                listTemp.Add(GetHBInfos(features[i].FireIndeies, inRegionIndex));
                listTemp.Add(features[i].SecondryFireArea.ToString("#0.000"));
                excelInfos.Add(listTemp.ToArray());
                listTemp.Clear();
            }
            IStatResult result = new StatResult("环保部信息统计结果", columns, excelInfos.ToArray());

            using (StatResultToExcelFile excelControl = new StatResultToExcelFile())
            {
                excelControl.Init();
                excelControl.Add(true, "环保部信息数据统计", result, false, 0);
                excelControl.SaveFile(saveFilename);
            }
            IFileExtractResult resultFile = new FileExtractResult("FRIH", saveFilename);

            resultFile.SetDispaly(false);
            return(resultFile);
        }