Exemplo n.º 1
0
        private IExtractResult ASTATAlgorithm(Action <int, string> progressTracker, IContextMessage contextMessage)
        {
            _contextMessage = contextMessage;
            if (_argumentProvider == null)
            {
                return(null);
            }
            string[] fname = GetStringArray("SelectedPrimaryFiles");
            if (fname == null || fname.Length <= 0)
            {
                PrintInfo("请选择统计文件!");
                return(null);
            }
            foreach (string name in fname)
            {
                if (!File.Exists(name))
                {
                    PrintInfo("需要统计的文件不存在!");
                    return(null);
                }
            }
            if (_argumentProvider.GetArg("UCRegionSnowDepth") == null)
            {
                PrintInfo("请设置需要统计的指数分段值!");
                return(null);
            }
            SortedDictionary <float, float> sdRegions = _argumentProvider.GetArg("UCRegionSnowDepth") as SortedDictionary <float, float>;

            if (sdRegions == null || sdRegions.Count == 0)
            {
                return(null);
            }

            if (_argumentProvider.GetArg("AlgorithmName") == null)
            {
                PrintInfo("参数\"AlgorithmName\"为空。");
                return(null);
            }

            string outId     = _argumentProvider.GetArg("OutFileIdentify") as string;
            string outFileId = CreatTitleByFileName(fname[0], outId);

            SubProductInstanceDef instance = FindSubProductInstanceDefs(outId);

            if (instance == null)
            {
                return(AreaStatResult <Int16>("雪深", "MWS", (v) => { return v == 1; }));
            }
            else
            {
                _argumentProvider.SetArg("OutFileIdentify", outFileId);
                Dictionary <string, Func <float, bool> > filters = new Dictionary <string, Func <float, bool> >();
                foreach (float key in sdRegions.Keys)
                {
                    float  min       = key;
                    float  max       = sdRegions[key];
                    string filterKey = min + "—" + max + "厘米 " + "覆盖面积(平方公里)";
                    filters.Add(filterKey, (v) =>
                    {
                        double value = v;
                        return(value >= min && value < max);
                    });
                }
                string fieldName;
                string shapeFilename;
                int    fieldIndex = -1;
                if (instance.AOIProvider == "当前区域" || instance.AOIProvider == "土地利用类型")
                {
                    return(StatRaster <float>(instance, filters, progressTracker));
                }
                else
                {
                    if (instance.AOIProvider == "县级行政区划")
                    {
                        using (frmStatSXRegionTemplates frm = new frmStatSXRegionTemplates())
                        {
                            if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                            {
                                Feature[] fets = frm.GetSelectedFeatures();
                                fets = frm.GetStatFeatures(out fieldName, out shapeFilename, out fieldIndex);
                                if (fets == null)
                                {
                                    PrintInfo("未选择任何地区");
                                }
                                fieldValues.Clear();
                                foreach (Feature fet in fets)
                                {
                                    fieldValues.Add(fet.GetFieldValue(fieldIndex));     //获得选择区域名称
                                }
                            }
                        }
                        string statString = AreaStatProvider.GetAreaStatItemFileName("县级行政区划");
                        return(StatRasterByVector(instance.Name, statString, filters, progressTracker));
                    }
                    else
                    {
                        if (instance.AOIProvider == "省级行政区划")
                        {
                            using (frmStatProvinceRegionTemplates frm = new frmStatProvinceRegionTemplates())
                            {
                                if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                                {
                                    Feature[] fets = frm.GetSelectedFeatures();
                                    fets = frm.GetStatFeatures(out fieldName, out shapeFilename, out fieldIndex);
                                    if (fets == null)
                                    {
                                        PrintInfo("未选择任何地区");
                                    }
                                    fieldValues.Clear();
                                    foreach (Feature fet in fets)
                                    {
                                        fieldValues.Add(fet.GetFieldValue(fieldIndex));     //获得选择区域名称
                                    }
                                }
                            }
                            string statString = AreaStatProvider.GetAreaStatItemFileName("行政区划");
                            return(StatRasterByVector(instance.Name, statString, filters, progressTracker));
                        }
                    }
                }
            }

            return(null);
        }
Exemplo n.º 2
0
        public override IExtractResult Make(Action <int, string> progressTracker, IContextMessage contextMessage)
        {
            if (_argumentProvider == null)
            {
                return(null);
            }
            if (_argumentProvider.GetArg("AlgorithmName") == null)
            {
                return(null);
            }
            if (_argumentProvider.GetArg("AlgorithmName").ToString() == "VSTATAlgorithm")
            {
                string[] fname = GetStringArray("SelectedPrimaryFiles");

                //按照Instance执行统计操作
                string instanceIdentify = _argumentProvider.GetArg("OutFileIdentify") as string;
                string fieldName;
                string shapeFilename;
                int    fieldIndex = -1;
                if (instanceIdentify != null)
                {
                    SubProductInstanceDef instance = FindSubProductInstanceDefs(instanceIdentify);
                    if (instance.OutFileIdentify == "VCBP")
                    {
                        using (frmStatProvinceRegionTemplates frm = new frmStatProvinceRegionTemplates())
                        {
                            if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                            {
                                Feature[] fets = frm.GetSelectedFeatures();
                                fets = frm.GetStatFeatures(out fieldName, out shapeFilename, out fieldIndex);
                                fieldValues.Clear();
                                foreach (Feature fet in fets)
                                {
                                    fieldValues.Add(fet.GetFieldValue(fieldIndex)); //获得选择区域名称
                                }
                            }
                        }
                        string aoiprovider = "省级行政区域_面.shp";
                        string keyname     = "NAME";
                        string sweVolFile  = fname[0].Replace("MSWE", "SVOL");
                        if (!File.Exists(sweVolFile))
                        {
                            IFileExtractResult sweVolResult = ComputeSnowSWEVOL(fname[0]);
                            sweVolFile = sweVolResult.FileName;
                        }
                        return(VSTATAlgorithm(sweVolFile, aoiprovider, keyname));
                    }
                    if (instance.OutFileIdentify == "VCBC")
                    {
                        using (frmStatSXRegionTemplates frm = new frmStatSXRegionTemplates())
                        {
                            if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                            {
                                Feature[] fets = frm.GetSelectedFeatures();
                                fets = frm.GetStatFeatures(out fieldName, out shapeFilename, out fieldIndex);
                                fieldValues.Clear();
                                foreach (Feature fet in fets)
                                {
                                    fieldValues.Add(fet.GetFieldValue(fieldIndex)); //获得选择区域名称
                                }
                            }
                        }
                        string aoiprovider = "县级行政区域_面.shp";
                        string keyname     = "NAME";
                        string sweVolFile  = fname[0].Replace("MSWE", "SVOL");
                        if (!File.Exists(sweVolFile))
                        {
                            IFileExtractResult sweVolResult = ComputeSnowSWEVOL(fname[0]);
                            sweVolFile = sweVolResult.FileName;
                        }
                        return(VSTATAlgorithm(sweVolFile, aoiprovider, keyname));
                    }
                    if (instance.OutFileIdentify == "VLUT")
                    {
                        string aoiprovider = "土地利用类型_合并.shp";
                        string keyname     = "NAME";
                        string sweVolFile  = fname[0].Replace("MSWE", "SVOL");
                        if (!File.Exists(sweVolFile))
                        {
                            IFileExtractResult sweVolResult = ComputeSnowSWEVOL(fname[0]);
                            sweVolFile = sweVolResult.FileName;
                        }
                        return(VSTATAlgorithm(sweVolFile, aoiprovider, keyname));
                    }

                    if (instance.OutFileIdentify == "VCAR")
                    {
                        string aoiprovider = "";
                        string keyname     = "";
                        string sweVolFile  = fname[0].Replace("MSWE", "SVOL");
                        if (!File.Exists(sweVolFile))
                        {
                            IFileExtractResult sweVolResult = ComputeSnowSWEVOL(fname[0]);
                            sweVolFile = sweVolResult.FileName;
                        }
                        return(VSTATAlgorithm(sweVolFile, aoiprovider, keyname));
                    }
                }
            }
            return(null);
        }