Exemplo n.º 1
0
        public static IArgumentProvider GetArgumentProvider(ExtractProductIdentify productIdentify, ExtractAlgorithmIdentify algorithmIdentify)
        {
            if (productIdentify == null || algorithmIdentify == null)
            {
                return(null);
            }
            ThemeDef theme = GetThemeDefByIdentify(productIdentify.ThemeIdentify);

            if (theme == null)
            {
                return(null);
            }
            ProductDef prd = theme.GetProductDefByIdentify(productIdentify.ProductIdentify);

            if (prd == null)
            {
                return(null);
            }
            SubProductDef subPrd = prd.GetSubProductDefByIdentify(productIdentify.SubProductIdentify);

            if (subPrd == null)
            {
                return(null);
            }
            AlgorithmDef      alg    = subPrd.GetAlgorithmDefByAlgorithmIdentify(algorithmIdentify);
            IArgumentProvider argprd = CreateArgumentProvider(alg, BandRefTableHelper.GetBandRefTable(algorithmIdentify.Satellite, algorithmIdentify.Sensor));

            if (argprd != null)
            {
                argprd.SetArg("AlgorithmName", alg.Identify);
            }
            return(argprd);
        }
Exemplo n.º 2
0
 private void TryHandleCustomArguments(IArgumentProvider argProvider, AlgorithmDef alg)
 {
     foreach (ArgumentDef arg in alg.Arguments.Where((a) => { return(a is ArgumentDef); }))
     {
         string uieditor = arg.EditorUiProvider;
         if (string.IsNullOrEmpty(uieditor))
         {
             continue;
         }
         var xElement = arg.DefaultValueElement;
         if (xElement == null)
         {
             continue;
         }
         if (!xElement.HasElements)
         {
             continue;
         }
         object v = TryGetValueUseUIEditor(uieditor, xElement);
         if (v != null)
         {
             argProvider.SetArg(arg.Name, v);
         }
     }
 }
Exemplo n.º 3
0
        public static IArgumentProvider GetArgumentProvider(ExtractProductIdentify productIdentify, string algorithmIdentify, string satellite, string sensor)
        {
            if (productIdentify == null || algorithmIdentify == null)
            {
                return(null);
            }
            ThemeDef theme = GetThemeDefByIdentify(productIdentify.ThemeIdentify);

            if (theme == null)
            {
                return(null);
            }
            ProductDef prd = theme.GetProductDefByIdentify(productIdentify.ProductIdentify);

            if (prd == null)
            {
                return(null);
            }
            SubProductDef subPrd = prd.GetSubProductDefByIdentify(productIdentify.SubProductIdentify);

            if (subPrd == null)
            {
                return(null);
            }
            AlgorithmDef alg = subPrd.GetAlgorithmDefByIdentify(algorithmIdentify);

            return(CreateArgumentProvider(alg, BandRefTableHelper.GetBandRefTable(satellite, sensor)));
        }
Exemplo n.º 4
0
        private void ParseBands(XElement ele, ref AlgorithmDef alg)
        {
            XElement subEle = ele.Element(XName.Get("Bands"));

            if (subEle == null)
            {
                return;
            }
            IEnumerable <XElement> eleBands = subEle.Elements();

            if (eleBands == null || eleBands.Count() == 0)
            {
                return;
            }
            BandDef        band;
            List <BandDef> bands = new List <BandDef>();

            foreach (XElement element in eleBands)
            {
                band = CreatBand(element);
                if (band != null)
                {
                    bands.Add(band);
                }
            }
            if (bands != null && bands.Count != 0)
            {
                alg.Bands = bands.ToArray();
            }
        }
Exemplo n.º 5
0
        private void ConvertBandCenterWaveNumToArg(ref AlgorithmDef alg)
        {
            if (alg.Bands == null || alg.Bands.Length == 0)
            {
                return;
            }
            ArgumentBase[] args = new ArgumentBase[alg.Arguments.Length + alg.Bands.Length];
            for (int i = 0; i < alg.Arguments.Length; i++)
            {
                args[i] = alg.Arguments[i];
            }
            int idx = alg.Arguments.Length;

            foreach (BandDef band in alg.Bands)
            {
                ArgumentDef arg = new ArgumentDef();
                arg.Name         = (band.Identify + "_CenterWaveNum");
                arg.Datatype     = "double";
                arg.Description  = arg.Name;
                arg.Visible      = false;
                arg.Defaultvalue = (band.CenterWaveNum).ToString();
                args[idx++]      = arg;
            }
            alg.Arguments = args;
        }
Exemplo n.º 6
0
        private AlgorithmDef CreatAlgorithm(XElement ele)
        {
            AlgorithmDef             alg   = new AlgorithmDef();
            IEnumerable <XAttribute> attrs = ele.Attributes();

            foreach (XAttribute att in attrs)
            {
                switch (att.Name.ToString().ToLower())
                {
                case "name":
                    if (!String.IsNullOrEmpty(att.Value))
                    {
                        alg.Name = att.Value;
                    }
                    break;

                case "identify":
                    if (!String.IsNullOrEmpty(att.Value))
                    {
                        alg.Identify = att.Value;
                    }
                    break;

                case "satellite":
                    alg.Satellites = AttributsToStrings(att.Value);
                    break;

                case "sensor":
                    alg.Sensors = AttributsToStrings(att.Value);
                    break;

                case "customidentify":
                    if (!String.IsNullOrEmpty(att.Value))
                    {
                        alg.CustomIdentify = att.Value;
                    }
                    break;

                case "grouptype":
                    if (!string.IsNullOrEmpty(att.Value))
                    {
                        alg.GroupTypeName = att.Value;
                    }
                    else
                    {
                        alg.GroupTypeName = "默认组";
                    }
                    break;
                }
            }

            ParseBands(ele, ref alg);
            ParseArguments(ele, ref alg);
            ConvertBandZoomToArg(ref alg);
            ConvertBandCenterWaveNumToArg(ref alg);
            return(alg);
        }
Exemplo n.º 7
0
 private void ResetFileVars(IArgumentProvider prd, AlgorithmDef alg)
 {
     foreach (ArgumentDef arg in alg.Arguments.Where((a) => { return(a is ArgumentDef); }))
     {
         if (arg.RefType == "file")
         {
             prd.SetArg(arg.Name, null);
         }
     }
 }
Exemplo n.º 8
0
        private void ParseArguments(XElement ele, ref AlgorithmDef alg)
        {
            XElement subXElement = ele.Element(XName.Get("Arguments"));

            if (subXElement == null)
            {
                return;
            }
            ArgumentBase[] args = ParseArguments(subXElement);
            if (args != null && args.Length != 0)
            {
                alg.Arguments = args;
            }
        }
Exemplo n.º 9
0
        private static IArgumentProvider CreateArgumentProvider(AlgorithmDef alg, BandnameRefTable bandRefTable)
        {
            if (alg == null)
            {
                return(null);
            }
            IArgumentProvider prd = new ArgumentProvider(alg);

            if (bandRefTable != null)
            {
                SetBands(prd, alg.Bands, bandRefTable);
            }
            SetArguments(prd, alg.Arguments);
            return(prd);
        }
Exemplo n.º 10
0
        public static IArgumentProvider GetArgumentProvider(ExtractProductIdentify productIdentify, string algorithmIdentify)
        {
            if (productIdentify == null || algorithmIdentify == null)
            {
                return(null);
            }
            ThemeDef theme = GetThemeDefByIdentify(productIdentify.ThemeIdentify);

            if (theme == null)
            {
                return(null);
            }
            ProductDef prd = theme.GetProductDefByIdentify(productIdentify.ProductIdentify);

            if (prd == null)
            {
                return(null);
            }
            SubProductDef subPrd = prd.GetSubProductDefByIdentify(productIdentify.SubProductIdentify);

            if (subPrd == null)
            {
                return(null);
            }
            AlgorithmDef      alg    = subPrd.GetAlgorithmDefByIdentify(algorithmIdentify);
            IArgumentProvider argPrd = CreateArgumentProvider(alg, null);

            if (alg.Bands != null)
            {
                foreach (BandDef b in alg.Bands)
                {
                    argPrd.SetArg(b.Identify, b.BandNo);
                }
            }
            return(argPrd);
        }
Exemplo n.º 11
0
 public static void FillDefaultArguments(IArgumentProvider argumentProvider, AlgorithmDef alg, string satellite, string sensor)
 {
     argumentProvider.Reset();
     SetBands(argumentProvider, alg.Bands, BandRefTableHelper.GetBandRefTable(satellite, sensor));
     SetArguments(argumentProvider, alg.Arguments);
 }
Exemplo n.º 12
0
        private void MakeSubProductUseInstances(string preBanks, IMonitoringSubProduct subprd, AlgorithmDef alg, IContextMessage contextMessage, IArgumentMissProcessor argumentMissProcessor, string executeGroup, Action <int, string> processTracker)
        {
            IArgumentProvider prd = subprd.ArgumentProvider;

            prd.SetArg("ThemeGraphyGenerator", _layoutGenerator);
            prd.SetArg("FileNameGenerator", _fileNameGenerator);
            foreach (SubProductInstanceDef ist in subprd.Definition.SubProductInstanceDefs)
            {
                if (!ist.isautogenerate)
                {
                    continue;
                }
                if (!string.IsNullOrEmpty(executeGroup) && ist.AutoGenerateGroup != null && !ist.AutoGenerateGroup.Contains(executeGroup))
                {
                    continue;
                }
                ResetFileVars(prd, alg);
                if (ist.FileProvider == null)
                {
                    if (contextMessage != null)
                    {
                        contextMessage.PrintMessage(preBanks + "参数\"FileProvider\"为空,子产品\"" + ist.Name + "\"过程终止!");
                    }
                    continue;
                }
                if (ist.AOIProvider != null)
                {
                    SetAOI(ist.AOIProvider, prd);
                }
                if (ist.FileProvider != null)
                {
                    if (!SetPrimaryFiles(preBanks, ist.FileProvider, ist.Argument, ref ist.extInfo, prd, contextMessage))
                    {
                        continue;
                    }
                }
                if (ist.OutFileIdentify != null)
                {
                    prd.SetArg("OutFileIdentify", ist.OutFileIdentify);
                }
                if (ist.LayoutName != null)
                {
                    prd.SetArg("ThemeGraphTemplateName", ist.LayoutName);
                }
                if (!string.IsNullOrEmpty(ist.ColorTableName))
                {
                    prd.SetArg("colortablename", "colortablename=" + ist.ColorTableName);
                }
                if (!string.IsNullOrEmpty(ist.extInfo))
                {
                    prd.SetArg("extinfo", ist.extInfo);
                }

                //多通道合成图需要使用Canverviewer中的数据。包括文件名,波段,图像增强方案等。
                prd.SetArg("SmartSession", _contextEnvironment.Session);

                //根据某个文件型参数生成AOI
                TryApplyAOITemplateBySeconaryArg(subprd);
                //
                IExtractResult result = subprd.Make(processTracker);
                if (result != null)
                {
                    if (_resultHandler != null)
                    {
                        _resultHandler.HandleResult(_contextEnvironment, _monitoringProduct, subprd, result);
                    }
                }
            }
        }
Exemplo n.º 13
0
 public ArgumentProvider(AlgorithmDef currentAlgorithm)
 {
     _currentAlgorithmDef = currentAlgorithm;
 }
Exemplo n.º 14
0
        public string[] GetNeedFirstSettedArguments(string beginSubProduct)
        {
            List <string> needFirstSettedArgs = new List <string>();
            List <string> initedArgs          = new List <string>();
            SubProductDef firstSubProduct     = _monitoringProduct.Definition.GetSubProductDefByIdentify(beginSubProduct);

            if (firstSubProduct != null && firstSubProduct.IsNeedCurrentRaster)
            {
                needFirstSettedArgs.Add(GeoDo.RSS.MIF.Core.ContextEnvironment.ENV_VAR_NAME_CURRENT_RASTER_FILE);
            }
            if (_monitoringProduct.SubProducts != null)
            {
                string         rstFileName = _contextEnvironment.GetContextVar(GeoDo.RSS.MIF.Core.ContextEnvironment.ENV_VAR_NAME_CURRENT_RASTER_FILE);
                RasterIdentify rstIdentify = new RasterIdentify();
                if (rstFileName != null)
                {
                    rstIdentify = new RasterIdentify(rstFileName);
                    initedArgs.Add(GeoDo.RSS.MIF.Core.ContextEnvironment.ENV_VAR_NAME_CURRENT_RASTER_FILE);
                }
                foreach (IMonitoringSubProduct subprd in _monitoringProduct.SubProducts)
                {
                    AlgorithmDef alg = subprd.Definition.Algorithms[0];
                    if (subprd.Definition.IsNeedCurrentRaster && subprd.Definition.Algorithms.Count() > 0)
                    {
                        ExtractAlgorithmIdentify id = new ExtractAlgorithmIdentify();
                        id.Satellite = rstIdentify.Satellite;
                        id.Sensor    = rstIdentify.Sensor;
                        alg          = subprd.Definition.GetAlgorithmDefByAlgorithmIdentify(id);
                        if (alg == null)
                        {
                            alg = subprd.Definition.Algorithms[0];
                        }
                    }
                    //子产品不存在实例
                    if (subprd.Definition.SubProductInstanceDefs == null)
                    {
                        foreach (ArgumentDef arg in alg.Arguments.Where((a) => { return(a is ArgumentDef); }))
                        {
                            if (arg.IsOptional)
                            {
                                continue;
                            }
                            if (arg.RefType == "file" && arg.FileProvider == null)
                            {
                                if (!needFirstSettedArgs.Contains(arg.Name))
                                {
                                    needFirstSettedArgs.Add(arg.Name);
                                }
                            }
                            else if (arg.RefType == "file")
                            {
                                if (arg.FileProvider.Contains("ContextEnvironment:"))
                                {
                                    string[] parts = arg.FileProvider.Split(':');
                                    if (!initedArgs.Contains(parts[1]) && !needFirstSettedArgs.Contains(parts[1]))
                                    {
                                        needFirstSettedArgs.Add(parts[1]);
                                    }
                                }
                            }
                        }
                    }
                    //子产品有实例
                    else
                    {
                        foreach (SubProductInstanceDef ist in subprd.Definition.SubProductInstanceDefs)
                        {
                            if (ist.FileProvider.Contains("ContextEnvironment:"))
                            {
                                string[] parts = ist.FileProvider.Split(':');
                                if (!initedArgs.Contains(parts[1]) && !needFirstSettedArgs.Contains(parts[1]))
                                {
                                    needFirstSettedArgs.Add(parts[1]);
                                }
                            }
                        }
                    }
                    //
                    initedArgs.Add(subprd.Identify);
                }
            }
            return(needFirstSettedArgs.Count > 0 ? needFirstSettedArgs.ToArray() : null);
        }
Exemplo n.º 15
0
        private void MakeSubProduct(string preBanks, IMonitoringSubProduct subprd, IContextMessage contextMessage, IArgumentMissProcessor argumentMissProcessor, string executeGroup, Action <int, string> processTracker)
        {
            bool isCreatDataProvider   = false;
            IRasterDataProvider raster = null;

            try
            {
                subprd.ArgumentProvider.Reset();
                subprd.ArgumentProvider.AOI = null;
                AlgorithmDef   alg         = subprd.AlgorithmDefs[0];
                RasterIdentify rstIdentify = null;
                rstIdentify = GetRasterIdentifOfCurrentFile();
                if (subprd.Definition.IsNeedCurrentRaster)
                {
                    string rstFileName = _contextEnvironment.GetContextVar(GeoDo.RSS.MIF.Core.ContextEnvironment.ENV_VAR_NAME_CURRENT_RASTER_FILE);
                    raster = GeoDataDriver.Open(rstFileName) as IRasterDataProvider;
                    subprd.ArgumentProvider.DataProvider = raster;
                    isCreatDataProvider = true;
                    //
                    TryApplyAOITemplates(subprd);
                    //
                    if (rstIdentify == null)
                    {
                        if (contextMessage != null)
                        {
                            contextMessage.PrintMessage("参数\"" + GeoDo.RSS.MIF.Core.ContextEnvironment.ENV_VAR_NAME_CURRENT_RASTER_FILE + "\"为空!");
                        }
                        if (argumentMissProcessor == null)
                        {
                            return;
                        }
                        string crtFileName = argumentMissProcessor.DoGettingArgument(subprd.Definition, subprd.UseDefaultAlgorithm(subprd.Definition.ProductDef.Identify), GeoDo.RSS.MIF.Core.ContextEnvironment.ENV_VAR_NAME_CURRENT_RASTER_FILE);
                        if (crtFileName == null)
                        {
                            return;
                        }
                        rstIdentify = new RasterIdentify(crtFileName);
                        _contextEnvironment.PutContextVar(GeoDo.RSS.MIF.Core.ContextEnvironment.ENV_VAR_NAME_CURRENT_RASTER_FILE, crtFileName);
                    }
                    ExtractAlgorithmIdentify id = new ExtractAlgorithmIdentify();
                    id.Satellite = rstIdentify.Satellite;
                    id.Sensor    = rstIdentify.Sensor;
                    alg          = subprd.Definition.GetAlgorithmDefByAlgorithmIdentify(id);
                    if (alg == null)
                    {
                        alg = subprd.Definition.Algorithms[0];
                    }
                }
                subprd.ResetArgumentProvider(alg.Identify);
                subprd.ArgumentProvider.SetArg("AlgorithmName", alg.Identify);
                if (alg.Bands != null && alg.Bands.Length > 0)
                {
                    MonitoringThemeFactory.SetBandArgs(subprd, rstIdentify.Satellite, rstIdentify.Sensor);
                    foreach (BandDef band in alg.Bands)
                    {
                        if (subprd.ArgumentProvider.GetArg(band.Identify).ToString() == "-1")
                        {
                            if (contextMessage != null)
                            {
                                contextMessage.PrintMessage(preBanks + "从波段映射表获取\"" + band.Identify + "\"的波段序号失败,生成过程终止!");
                            }
                            return;
                        }
                    }
                }
                //
                TryHandleCustomArguments(subprd.ArgumentProvider, alg);
                //
                if (subprd.Definition.SubProductInstanceDefs != null)
                {
                    MakeSubProductUseInstances(preBanks + "  ", subprd, alg, contextMessage, argumentMissProcessor, executeGroup, processTracker);
                }
                else
                {
                    DirectMakeSubProduct(preBanks + "  ", subprd, alg, contextMessage, argumentMissProcessor, processTracker);
                }
            }
            finally
            {
                if (raster != null)
                {
                    raster.Dispose();
                    raster = null;
                }
                if (subprd.ArgumentProvider.DataProvider != null && isCreatDataProvider)
                {
                    subprd.ArgumentProvider.DataProvider.Dispose();
                }
            }
        }
Exemplo n.º 16
0
        private void DirectMakeSubProduct(string preBanks, IMonitoringSubProduct subprd, AlgorithmDef alg, IContextMessage contextMessage, IArgumentMissProcessor argumentMissProcessor, Action <int, string> processTracker)
        {
            IArgumentProvider prd = subprd.ArgumentProvider;

            prd.SetArg("ThemeGraphyGenerator", _layoutGenerator);
            prd.SetArg("FileNameGenerator", _fileNameGenerator);
            foreach (ArgumentDef arg in alg.Arguments.Where((a) => { return(a is ArgumentDef); }))
            {
                if (arg.IsOptional)
                {
                    continue;
                }
                if (arg.RefType == "file" && arg.FileProvider == null)
                {
                    if (contextMessage != null)
                    {
                        contextMessage.PrintMessage(preBanks + "参数\"" + arg.Name + "\"为空,子产品\"" + subprd.Name + "\"过程终止!");
                    }
                    return;
                }
                else if (arg.RefType == "file")
                {
                    GetAndSetFileVar(preBanks + " ", subprd, arg, contextMessage);
                }
            }
            //根据某个文件型参数生成AOI
            TryApplyAOITemplateBySeconaryArg(subprd);
            //
            IExtractResult result = subprd.Make(processTracker);

            if (result != null)
            {
                if (_resultHandler != null)
                {
                    _resultHandler.HandleResult(_contextEnvironment, _monitoringProduct, subprd, result);
                }
            }
        }
Exemplo n.º 17
0
        private bool ArgsIsFull()
        {
            if (_argumentProvider == null)
            {
                _error = "未提供[" + _subProductDef.Name + "]子产品参数提供者.";
                return(false);
            }
            if (_argumentProvider.GetArg("AlgorithmName") == null)
            {
                _error = "未提供[" + _subProductDef.Name + "]子产品所用算法名.";
                return(false);
            }
            string       algorithmName = _argumentProvider.GetArg("AlgorithmName").ToString();
            AlgorithmDef algorithmDef  = _subProductDef.GetAlgorithmDefByIdentify(algorithmName);

            if (algorithmDef == null)
            {
                _error = "当前[" + _subProductDef.Name + "]子产品不包含\"" + algorithmName + "\"算法.";
                return(false);
            }
            if (algorithmDef != null)
            {
                object bandArg = null;
                foreach (BandDef arg in algorithmDef.Bands)
                {
                    bandArg = _argumentProvider.GetArg(arg.Identify);
                    if (bandArg == null)
                    {
                        _error = "未提供波段[" + arg.Identify + "]信息.";
                        return(false);
                    }
                    if (bandArg.ToString() == "-1")
                    {
                        _error = "波段[" + arg.Identify + "]未找到对应的波段映射.";
                        return(false);
                    }
                }
            }
            ArgumentPair argPair = null;
            ArgumentDef  argDef  = null;

            foreach (ArgumentBase arg in algorithmDef.Arguments)
            {
                if (arg is ArgumentPair)
                {
                    argPair = arg as ArgumentPair;
                    if (argPair.ArgumentMax != null && _argumentProvider.GetArg(argPair.ArgumentMax.Name) == null)
                    {
                        _error = "参数[" + argPair.ArgumentMax.Name + "]未提供.";
                        return(false);
                    }
                    if (argPair.ArgumentMin != null && _argumentProvider.GetArg(argPair.ArgumentMin.Name) == null)
                    {
                        _error = "参数[" + argPair.ArgumentMin.Name + "]未提供.";
                        return(false);
                    }
                }
                else if (arg is ArgumentDef)
                {
                    argDef = arg as ArgumentDef;
                    if (_argumentProvider.GetArg(argDef.Name) == null)
                    {
                        _error = "参数[" + argDef.Name + "]未提供.";
                        return(false);
                    }

                    if (argDef.RefType == "file")
                    {
                        string filename = _argumentProvider.GetArg(argDef.Name).ToString();
                        if (!File.Exists(filename))
                        {
                            _error = "参数文件[" + Path.GetFileName(filename) + "]不存在.";
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
Exemplo n.º 18
0
        private void UpdateCurrentAlgorithmDef(string algIdentify)
        {
            AlgorithmDef alg = _subProductDef.GetAlgorithmDefByIdentify(algIdentify);

            _argumentProvider.CurrentAlgorithmDef = alg;
        }