Пример #1
0
        /// <summary>Creates new network attribute parameters</summary>
        private static void AddNetworkParameters(NetworkAttributeInfo nai, IEvaluatedNetworkAttribute netAttr)
        {
            // Create parameters
            if ((nai.Parameters != null) && (nai.Parameters.Count > 0))
            {
                IArray naParams = new ArrayClass();

                foreach (ParameterInfo paramInfo in nai.Parameters)
                {
                    INetworkAttributeParameter nap = new NetworkAttributeParameterClass();
                    nap.Name = paramInfo.Name;

                    if (paramInfo.DefaultValue is double)
                    {
                        nap.VarType = (int)VarEnum.VT_R8;
                    }
                    else if (paramInfo.DefaultValue is bool)
                    {
                        nap.VarType = (int)VarEnum.VT_BOOL;
                    }
                    else if (paramInfo.DefaultValue is string)
                    {
                        nap.VarType = (int)VarEnum.VT_BSTR;
                    }

                    nap.DefaultValue = paramInfo.DefaultValue;

                    naParams.Add(nap);
                }

                ((INetworkAttribute3)netAttr).Parameters = naParams;
            }
        }
Пример #2
0
        /// <summary>Creates a single NetworkAttributeInfo for the given network_attribute element</summary>
        private NetworkAttributeInfo CreateNetworkAttributeInfo(XElement x)
        {
            NetworkAttributeInfo netAttrInfo = new NetworkAttributeInfo();

            netAttrInfo.Name      = x.Element("name").Value;
            netAttrInfo.UsageType = GetNetworkAttributeUsageType(x);

            XElement xType = null;

            switch (netAttrInfo.UsageType)
            {
            case esriNetworkAttributeUsageType.esriNAUTCost:
                xType = x.Element("cost");
                netAttrInfo.DataType     = GetNetworkAttributeDataType(xType);
                netAttrInfo.UseAsDefault = bool.Parse(xType.Attribute("useAsDefault").Value);
                netAttrInfo.Units        = GetNetworkAttributeUnits(xType);
                netAttrInfo.Parameters   = GetNetworkAttributeParameters(xType).ToList();
                netAttrInfo.Evaluators   = GetNetworkAttributeEvaluators(xType).ToList();
                break;

            case esriNetworkAttributeUsageType.esriNAUTHierarchy:
                xType = x.Element("hierachy");
                netAttrInfo.DataType     = esriNetworkAttributeDataType.esriNADTInteger;
                netAttrInfo.UseAsDefault = bool.Parse(xType.Attribute("useAsDefault").Value);
                netAttrInfo.Units        = esriNetworkAttributeUnits.esriNAUUnknown;
                netAttrInfo.Parameters   = GetNetworkAttributeParameters(xType).ToList();
                netAttrInfo.Evaluators   = GetNetworkAttributeEvaluators(xType).ToList();
                break;

            case esriNetworkAttributeUsageType.esriNAUTRestriction:
                xType = x.Element("restriction");
                netAttrInfo.DataType     = esriNetworkAttributeDataType.esriNADTBoolean;
                netAttrInfo.UseAsDefault = bool.Parse(xType.Attribute("useAsDefault").Value);
                netAttrInfo.Units        = esriNetworkAttributeUnits.esriNAUUnknown;
                netAttrInfo.Parameters   = GetNetworkAttributeParameters(xType).ToList();
                netAttrInfo.Evaluators   = GetNetworkAttributeEvaluators(xType).ToList();
                break;

            case esriNetworkAttributeUsageType.esriNAUTDescriptor:
                xType = x.Element("descriptor");
                netAttrInfo.DataType     = GetNetworkAttributeDataType(xType);
                netAttrInfo.UseAsDefault = false;
                netAttrInfo.Units        = esriNetworkAttributeUnits.esriNAUUnknown;
                netAttrInfo.Parameters   = GetNetworkAttributeParameters(xType).ToList();
                netAttrInfo.Evaluators   = GetNetworkAttributeEvaluators(xType).ToList();
                break;
            }

            netAttrInfo.DefaultValue = GetNetworkAttributeDefaultValue(netAttrInfo.DataType, x.Element("default_value").Value);

            return(netAttrInfo);
        }
Пример #3
0
        /// <summary>Adds new Network Attribute Evaluators</summary>
        private void AddEvaluators(NetworkAttributeInfo nai, IEvaluatedNetworkAttribute netAttr)
        {
            foreach (EvaluatorInfo eval in nai.Evaluators)
            {
                INetworkEvaluator evaluator = null;

                if (eval.EvaluatorType == eEvaluatorType.Constant)
                {
                    evaluator = new NetworkConstantEvaluatorClass();
                    if (netAttr.DataType == esriNetworkAttributeDataType.esriNADTBoolean)
                    {
                        ((INetworkConstantEvaluator)evaluator).ConstantValue = eval.Expression.Equals(bool.TrueString, StringComparison.CurrentCultureIgnoreCase);
                    }
                    else if (netAttr.DataType == esriNetworkAttributeDataType.esriNADTDouble)
                    {
                        ((INetworkConstantEvaluator)evaluator).ConstantValue = Convert.ToDouble(eval.Expression);
                    }
                    else if (netAttr.DataType == esriNetworkAttributeDataType.esriNADTFloat)
                    {
                        ((INetworkConstantEvaluator)evaluator).ConstantValue = Convert.ToSingle(eval.Expression);
                    }
                    else if (netAttr.DataType == esriNetworkAttributeDataType.esriNADTInteger)
                    {
                        ((INetworkConstantEvaluator)evaluator).ConstantValue = Convert.ToInt32(eval.Expression);
                    }
                }
                else if (eval.EvaluatorType == eEvaluatorType.Script)
                {
                    evaluator = new NetworkScriptEvaluatorClass();

#if ARCGIS_10_0     // Handle Python script language added in ArcGIS 10.1
                    if (eval.ScriptLanguage != "VBScript")
                    {
                        throw new ApplicationException(RESMGR.GetString("GPTools_OSMGPCreateNetworkDataset_invalidScriptLanguage"));
                    }

                    INetworkScriptEvaluator scriptEvaluator = (INetworkScriptEvaluator)evaluator;
                    scriptEvaluator.SetExpression(eval.Expression, eval.Prelogic);
#else
                    INetworkScriptEvaluator2 scriptEvaluator = (INetworkScriptEvaluator2)evaluator;
                    scriptEvaluator.SetLanguage(eval.ScriptLanguage);
                    scriptEvaluator.SetExpression(eval.Expression, eval.Prelogic);
#endif
                }
                else if (eval.EvaluatorType == eEvaluatorType.Field)
                {
                    evaluator = new NetworkFieldEvaluatorClass();

#if ARCGIS_10_0     // Handle Python script language added in ArcGIS 10.1
                    if (eval.ScriptLanguage != "VBScript")
                    {
                        throw new ApplicationException(RESMGR.GetString("GPTools_OSMGPCreateNetworkDataset_invalidScriptLanguage"));
                    }

                    INetworkFieldEvaluator fieldEvaluator = (INetworkFieldEvaluator)evaluator;
                    fieldEvaluator.SetExpression(eval.Expression, eval.Prelogic);
#else
                    INetworkFieldEvaluator2 fieldEvaluator = (INetworkFieldEvaluator2)evaluator;
                    fieldEvaluator.SetLanguage(eval.ScriptLanguage);
                    fieldEvaluator.SetExpression(eval.Expression, eval.Prelogic);
#endif
                }

                INetworkSource source = EnumerateNetworkSources()
                                        .FirstOrDefault(ns => ns.Name.Equals(GetFullClassName(eval.Source), StringComparison.CurrentCultureIgnoreCase));
                if (source != null)
                {
                    esriNetworkEdgeDirection direction = eval.Direction;
                    if (!(source is IEdgeFeatureSource))
                    {
                        direction = esriNetworkEdgeDirection.esriNEDNone;
                    }

                    netAttr.set_Evaluator(source, direction, evaluator);
                }
            }
        }