Example #1
0
        /**
         *  将NestPath列表转换成父子关系的树
         * @param list
         * @param idstart
         * @return
         */
        public static int toTree(List <NestPath> list, int idstart)
        {
            List <NestPath> parents = new List <NestPath>();
            int             id      = idstart;

            /**
             * 找出所有的内回环
             */
            for (int i = 0; i < list.Count; i++)
            {
                NestPath p       = list[i];
                bool     isChild = false;
                for (int j = 0; j < list.Count; j++)
                {
                    if (j == i)
                    {
                        continue;
                    }

                    if (GeometryUtil.pointInPolygon(p.getSegments()[0], list[j]) == true)
                    {
                        list[j].getChildren().Add(p);
                        p.setParent(list[j]);
                        isChild = true;
                        break;
                    }
                }
                if (!isChild)
                {
                    parents.Add(p);
                }
            }

            /**
             *  将内环从list列表中去除
             */
            for (int i = 0; i < list.Count; i++)
            {
                if (parents.IndexOf(list[i]) < 0)
                {
                    list.RemoveAt(i);
                    i--;
                }
            }

            for (int i = 0; i < parents.Count; i++)
            {
                parents[i].setId(id);
                id++;
            }

            for (int i = 0; i < parents.Count; i++)
            {
                if (parents[i].getChildren().Count > 0)
                {
                    id = toTree(parents[i].getChildren(), id);
                }
            }
            return(id);
        }