Пример #1
0
        /// <summary>
        /// Gets an attribute value for a particular Tag
        /// </summary>
        /// <param name="TagName">"The name of the Tag (e.g. DATUM)</param>
        /// <param name="AttribName">The name of the Attribute to search for (e.g. Latitude_Of_Origin)</param>
        /// <param name="AttribNumber">The item number of the Attribute array (defaults to 0)</param>
        public string GetAttribValuebyName(string TagName, string AttribName, int AttribNumber)
        {
            string RetString = null;

            // Iterate through all the nodes and their children to find the match
            foreach (string testLevel in LevelList)
            {
                string[] splitLevels = testLevel.Split('.');
                WKTNode  retNode     = mvarNodes[Convert.ToInt32(splitLevels[0])];
                for (int i = 1; i < splitLevels.Length - 1; i++)
                {
                    retNode = retNode.Children[Convert.ToInt32(splitLevels[i])];
                }

                if (!String.IsNullOrEmpty(retNode.AttributeName))
                {
                    if (retNode.TagName.ToUpper() == TagName.ToUpper() & retNode.AttributeName.ToUpper() == AttribName.ToUpper())
                    {
                        RetString = (string)retNode.Attributes[AttribNumber];
                        break;
                    }
                }
            }
            return(RetString);
        }
Пример #2
0
        private void FindAllLevels()
        {
            bool HasChildren = true;

            LevelList.Clear();
            for (int i = 0; i < mvarNodes.Count; i++)
            {
                LevelList.Add(i.ToString() + ".");
            }

            int startSearch = 0;
            int noAdded     = 0;

            while (HasChildren)
            {
                HasChildren = false;
                for (int i = startSearch; i < LevelList.Count; i++)
                {
                    startSearch += noAdded;
                    noAdded      = 0;
                    string thisLevel = LevelList[i].ToString();
                    thisLevel = thisLevel.Substring(0, thisLevel.Length - 1);
                    string[] testLevels = thisLevel.Split('.');
                    WKTNode  tNode      = mvarNodes[Convert.ToInt32(testLevels[0])];
                    for (int j = 1; j < testLevels.Length; j++)
                    {
                        tNode = tNode.Children[Convert.ToInt32(testLevels[j])];
                    }
                    if (tNode.hasChildren)
                    {
                        // Does this already exist in the list?
                        for (int nNode = 0; nNode < tNode.Children.Count; nNode++)
                        {
                            string newLevel = LevelList[i].ToString() + nNode.ToString() + ".";
                            if (!LevelList.Contains(newLevel))
                            {
                                HasChildren = true;
                                LevelList.Add(newLevel);
                                noAdded++;
                            }
                        }
                    }
                }
            }

            for (int i = 0; i < LevelList.Count; i++)
            {
                System.Diagnostics.Debug.WriteLine(LevelList[i].ToString());
            }
        }
Пример #3
0
        /// <summary>
        /// Returns all the nodes in the WKT string that match
        /// </summary>
        /// <param name="TagName">"The name of the Tag (e.g. DATUM)</param>
        public WKTNodes GetNodesbyName(string TagName)
        {
            WKTNodes getNodes = new WKTNodes();

            // Iterate through all the nodes and their children to find the match
            foreach (string testLevel in LevelList)
            {
                string[] splitLevels = testLevel.Split('.');
                WKTNode  retNode     = mvarNodes[Convert.ToInt32(splitLevels[0])];
                for (int i = 1; i < splitLevels.Length - 1; i++)
                {
                    retNode = retNode.Children[Convert.ToInt32(splitLevels[i])];
                }
                if (retNode.TagName.ToUpper() == TagName.ToUpper())
                {
                    getNodes.Add(retNode);
                }
            }
            return(getNodes);
        }
Пример #4
0
 /// <summary>
 /// Well Know Text node by Name
 /// </summary>
 /// <param name="Name"></param>
 public WKTNode this[string Name]
 {
     get
     {
         int retIndex = -1;
         for (int Index = 0; Index < List.Count; Index++)
         {
             WKTNode testField = (WKTNode)List[Index];
             if (testField.TagName == Name.ToUpper())
             {
                 retIndex = Index;
                 break;
             }
         }
         if (retIndex > -1)
         {
             return((WKTNode)List[retIndex]);
         }
         else
         {
             return(null);
         }
     }
 }
Пример #5
0
 internal void Add(WKTNode addNode)
 {
     List.Add(addNode);
 }
Пример #6
0
        internal void Add(string Parent, string Name, string InnerText, string Parameters, string Level)
        {
            //create a new object
            string[] paramList;
            WKTNode  objNewMember = default(WKTNode);

            objNewMember = new WKTNode();
            WKTNodes Kids = new WKTNodes();

            sLevel = Level;
            Counter++;

            //set the properties passed into the method
            objNewMember.TagName    = Name.Replace("\"", "");
            objNewMember.InnerText  = InnerText;
            objNewMember.ParentName = Parent;
            objNewMember.Children   = Kids;
            //if (Parent == "Top")
            //{ objNewMember.Level = Level; }
            //else
            objNewMember.Level = Level + "." + Counter.ToString();


            if (Parameters != null)
            {
                paramList = Parameters.Split(',');
                if (paramList[0].StartsWith("\""))
                {
                    objNewMember.AttributeName = paramList[0].Replace("\"", "");
                }
                else
                {
                    objNewMember.Attributes.Add(paramList[0].Trim());
                }
                for (int i = 1; i < paramList.Length; i++)
                {
                    // TO DO: Because the paramList is an ArrayList there is no reason why everything has to be
                    // Stored as a string.
                    objNewMember.Attributes.Add(paramList[i].Replace("\"", "").Trim());
                }
            }

            List.Add(objNewMember);

            while (InnerText != null)
            {
                int    brkPos  = InnerText.IndexOf("[");
                string valName = null;
                string subText = null;
                string param   = null;
                if (brkPos > -1)
                {
                    valName = (InnerText.Substring(0, brkPos)).Trim();
                    if (valName.Contains(","))
                    {
                        valName = (valName.Substring(valName.LastIndexOf(",") + 1)).Trim();
                    }
                    subText   = LoadParameterFromWKT(valName, InnerText);
                    InnerText = (InnerText.Substring(brkPos + 2 + subText.Length)).Trim();
                    if (InnerText.StartsWith(","))
                    {
                        InnerText = InnerText.Substring(1);
                    }
                    InnerText = InnerText.Trim();

                    if (subText.Contains("["))
                    {
                        brkPos = subText.IndexOf("[");
                        brkPos = subText.LastIndexOf(",", brkPos);
                        param  = subText.Substring(0, brkPos).Trim();
                    }
                    else
                    {
                        param   = subText;
                        subText = null;
                    }
                }
                else
                {
                    param     = InnerText;
                    InnerText = null;
                }
                if (InnerText == "")
                {
                    InnerText = null;
                }

                objNewMember             = (WKTNode)List[List.Count - 1];
                objNewMember.hasChildren = true;
                objNewMember.Children.Add(objNewMember.TagName, valName, subText, param, objNewMember.Level);
            }
        }