Example #1
0
        public System.Data.DataTable AttributeList()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor   ed  = doc.Editor;
            Database db  = doc.Database;

            // 声明DataColumn、DataRow变量
            System.Data.DataColumn column;
            System.Data.DataRow    row;

            // 增加一个用地构成表(用地代码)dataTable
            System.Data.DataTable table = new System.Data.DataTable("用地构成");

            TypedValue[] tvs = new TypedValue[1] {
                new TypedValue((int)DxfCode.LayerName, "用地构成")
            };

            SelectionFilter       sf  = new SelectionFilter(tvs);
            PromptSelectionResult psr = ed.SelectAll(sf);

            if (psr.Status == PromptStatus.OK)
            {
                SelectionSet SS      = psr.Value;
                ObjectId[]   idArray = SS.GetObjectIds();

                using (Transaction acTrans = db.TransactionManager.StartTransaction())
                {
                    //List<string> compositionTableIndex = new List<string>() { "R", "R2", "A", "A1", "A33", "A7", "A9", "B", "B1", "B41", "S", "S1", "S42", "U", "U15", "G", "G1", "G2", "G3", "H11", "E", "E1" };

                    List <string> compositionTableIndex = new List <string>();
                    List <Entity> mtexts = new List <Entity>();

                    for (int j = 0; j < idArray.Length; j++)
                    {
                        Entity ent2 = (Entity)idArray[j].GetObject(OpenMode.ForRead);
                        if (ent2 is MText)
                        {
                            mtexts.Add(ent2);
                        }
                    }
                    ///找出索引
                    for (int j = 0; j < mtexts.Count; j++)
                    {
                        Entity ent2      = (Entity)mtexts[j];
                        string indexText = ((MText)mtexts[j]).Text.Replace("\n", "").Replace("\r", "").Replace(" ", "");
                        // 找一个参照物——主导功能
                        if (indexText == "用地代码")
                        {
                            for (int z = 0; z < mtexts.Count; z++)
                            {
                                // 读取数组里的实体
                                Entity ent3 = (Entity)mtexts[z];

                                if (((MText)ent2).Location.X - 300 < ((MText)ent3).Location.X && ((MText)ent3).Location.X < ((MText)ent2).Location.X + 500 && ((MText)ent2).Location.Y > ((MText)ent3).Location.Y)
                                {
                                    compositionTableIndex.Add(((MText)ent3).Text);
                                }
                            }
                        }
                    }

                    // 增加表格表头名称
                    table.Columns.Add(new System.Data.DataColumn(("用地代码"), typeof(string)));
                    table.Columns.Add(new System.Data.DataColumn(("用地名称"), typeof(string)));
                    table.Columns.Add(new System.Data.DataColumn(("面积(ha)"), typeof(string)));
                    table.Columns.Add(new System.Data.DataColumn(("占建设用地比例(%)"), typeof(string)));

                    //table.Columns.Add(new System.Data.DataColumn(("col"),typeof(string)));
                    //table.NewRow().ItemArray = new string[] { "",""};

                    // 用地代码循环
                    for (int w = 0; w < compositionTableIndex.Count; w++)
                    {
                        for (int j = 0; j < mtexts.Count; j++)
                        {
                            Entity ent1 = mtexts[j];

                            // 找出所有用地代码的关联属性
                            if (ent1 is MText && ((MText)ent1).Text == compositionTableIndex[w])
                            {
                                //ed.WriteMessage("\nFound X:{0} \n Y:{1} of {2}", ((MText)ent1).Location.X, ((MText)ent1).Location.Y, ((MText)ent1).Text);

                                // 增加一个排序列表,把实体对应的距离和文本内容放进去
                                List <int>    distances = new List <int>();
                                List <string> texts     = new List <string>();

                                for (int c = 0; c < mtexts.Count; c++)
                                {
                                    Entity ent2 = mtexts[c];

                                    // 如果为多行文本,以ent2为参考点,在y轴方向,在+400~-400范围内的,x轴方向,大于x轴的实体
                                    if (ent2 is MText)
                                    {
                                        if (((MText)ent1).Location.Y - 400 < ((MText)ent2).Location.Y && ((MText)ent2).Location.Y < ((MText)ent1).Location.Y + 400 && ((MText)ent1).Location.X <= ((MText)ent2).Location.X)
                                        {
                                            int distance = (int)MethodCommand.DistancePointToPoint(((MText)ent1).Location, ((MText)ent2).Location);

                                            distances.Add(distance);
                                            texts.Add(((MText)ent2).Text);
                                        }
                                    }
                                }

                                // 把获取的属性值按照距离大小排序,距离最近的放在第一位,以此类推
                                string temp;
                                int    tempDis;
                                for (int m = 0; m < distances.Count; m++)
                                {
                                    for (int q = 0; q < distances.Count - m - 1; q++)
                                    {
                                        try
                                        {
                                            if (distances[q] > distances[q + 1])
                                            {
                                                temp         = texts[q];
                                                texts[q]     = texts[q + 1];
                                                texts[q + 1] = temp;

                                                tempDis          = distances[q];
                                                distances[q]     = distances[q + 1];
                                                distances[q + 1] = tempDis;
                                            }
                                        }
                                        catch (Exception e)
                                        {
                                            System.Windows.Forms.MessageBox.Show(e.Message);
                                        }
                                    }
                                }

                                row           = table.NewRow();
                                row["用地代码"]   = texts[0];
                                row["用地名称"]   = texts[1];
                                row["面积(ha)"] = texts[2];
                                if (texts.Count < 4)
                                {
                                    row["占建设用地比例(%)"] = "无";
                                }
                                else
                                {
                                    row["占建设用地比例(%)"] = texts[3];
                                }
                                table.Rows.Add(row);
                            } // 找出所有用地代码的关联属性
                        }     // 循环整个实体群组结束
                    }         // 用地代码循环结束
                }
            }
            return(table);
        } // form 结束
Example #2
0
        private List <ObjectId> Sort(ObjectId[] oids2)
        {
            ObjectId[]      idArray = oids2;
            List <ObjectId> oids3   = new List <ObjectId>();

            using (Database db = HostApplicationServices.WorkingDatabase)
            {
                using (Transaction acTrans = db.TransactionManager.StartTransaction())
                {
                    List <MText>  compositionTableIndex = new List <MText>();
                    List <MText>  mtexts  = new List <MText>();
                    List <Entity> mtexts2 = new List <Entity>();


                    for (int j = 0; j < idArray.Length; j++)
                    {
                        Entity ent2 = (Entity)idArray[j].GetObject(OpenMode.ForRead);
                        if (ent2 is MText)
                        {
                            if (((MText)ent2).Text.Replace("\r", "").Replace("\n", "").Replace("\t", "").Replace(" ", "") != "图例")
                            {
                                MText mt = (MText)ent2;

                                mtexts.Add(mt);
                            }
                        }
                    }

                    double minX = double.NaN;
                    double maxX = double.NaN;
                    double maxY = double.NaN;
                    double minY = double.NaN;

                    ///找出排头兵
                    for (int j = 0; j < mtexts.Count; j++)
                    {
                        if (mtexts[j].Location.X > maxX || double.IsNaN(maxX))
                        {
                            maxX = mtexts[j].Location.X;
                        }
                        if (mtexts[j].Location.Y < minY || double.IsNaN(minY))
                        {
                            minY = mtexts[j].Location.Y;
                        }
                        if (mtexts[j].Location.Y > maxY || double.IsNaN(maxY))
                        {
                            maxY = mtexts[j].Location.Y;
                        }
                        if (mtexts[j].Location.X < minX || double.IsNaN(minX))
                        {
                            minX = mtexts[j].Location.X;
                        }
                    }

                    // 找出索引
                    for (int j = 0; j < mtexts.Count; j++)
                    {
                        if (maxY - 50 < ((MText)mtexts[j]).Location.Y && ((MText)mtexts[j]).Location.Y < maxY + 50)
                        {
                            compositionTableIndex.Add(mtexts[j]);
                        }
                    }

                    // 从近到远排序
                    List <int> distances = new List <int>();

                    for (int h = 0; h < compositionTableIndex.Count; h++)
                    {
                        if (minX - 20 < compositionTableIndex[h].Location.X && compositionTableIndex[h].Location.X < minX + 20)
                        {
                            for (int j = 0; j < compositionTableIndex.Count; j++)
                            {
                                int distance = (int)MethodCommand.DistancePointToPoint(((MText)compositionTableIndex[h]).Location, ((MText)compositionTableIndex[j]).Location);

                                distances.Add(distance);
                                mtexts2.Add(mtexts[j]);
                            }
                        }
                    }

                    // 把获取的属性值按照距离大小排序,距离最近的放在第一位,以此类推
                    Entity temp;
                    int    tempDis;
                    for (int m = 0; m < distances.Count; m++)
                    {
                        for (int q = 0; q < distances.Count - m - 1; q++)
                        {
                            try
                            {
                                if (distances[q] > distances[q + 1])
                                {
                                    temp           = mtexts2[q];
                                    mtexts2[q]     = mtexts2[q + 1];
                                    mtexts2[q + 1] = temp;

                                    tempDis          = distances[q];
                                    distances[q]     = distances[q + 1];
                                    distances[q + 1] = tempDis;
                                }
                            }
                            catch (Exception e)
                            {
                                System.Windows.Forms.MessageBox.Show(e.Message);
                            }
                        }
                    }

                    // 按索引排序
                    for (int j = 0; j < mtexts2.Count; j++)
                    {
                        Entity ent2 = (Entity)mtexts2[j];
                        for (int z = 0; z < mtexts.Count; z++)
                        {
                            Entity ent3 = (Entity)mtexts[z];

                            if (((MText)ent2).Location.X + 50 > ((MText)ent3).Location.X && ((MText)ent2).Location.X - 50 < ((MText)ent3).Location.X)
                            {
                                ObjectId oid = ent3.ObjectId;
                                oids3.Add(oid);
                            }
                        }
                    }
                }
            }

            return(oids3);
        }
Example #3
0
        public RoadInfoItemModel GetRoadItemInfo(Polyline line, List <DBText> txtList, List <Polyline> sectionLineList, List <DBText> sectionTextList)
        {
            RoadInfoItemModel item = new RoadInfoItemModel();

            item.RoadLength = line.Length.ToString();
            item.RoadWidth  = line.ConstantWidth.ToString();
            item.RoadType   = "polyline";
            item.ColorIndex = line.ColorIndex == 256 ? MethodCommand.GetLayerColorByID(line.LayerId) : System.Drawing.ColorTranslator.ToHtml(line.Color.ColorValue);
            item.roadList   = PolylineMethod.GetPolyLineInfoPt(line);
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;

            using (Transaction tran = db.TransactionManager.StartTransaction())
            {
                int vtnum = line.NumberOfVertices;
                for (int i = 0; i < vtnum - 1; i++)
                {
                    foreach (DBText mText in txtList)
                    {
                        if (item.RoadName != null)
                        {
                            break;
                        }
                        Point2d pt = mText.AlignmentPoint.Convert2d(new Plane());



                        if (PolylineMethod.PtInPolyLine(pt, line.GetPoint2dAt(i), line.GetPoint2dAt(i + 1), 20) == 1)
                        {
                            item.RoadName         = mText.TextString.Replace(" ", "").Replace(" ", "");
                            item.RoadNameLocaiton = new List <System.Drawing.PointF>();
                            item.sectionList      = new List <RoadSectionItemModel>();

                            double middleLen  = MethodCommand.DistancePointToPoint(mText.Position, mText.AlignmentPoint);
                            double textLen    = MethodCommand.GetEndLengthByTheorem(middleLen, mText.Height / 2) * 2;
                            double partLength = textLen / item.RoadName.Length;

                            for (int j = 1; j < item.RoadName.Length + 1; j++)
                            {
                                item.RoadNameLocaiton.Add(MethodCommand.GetEndPointByTrigonometricHu(mText.Rotation, MethodCommand.Point3d2Pointf(mText.Position), partLength * j));
                            }

                            item.RoadNameLayer = mText.Layer;
                            item.RoadNameType  = "text";

                            break;
                        }
                    }
                    //获取横截面


                    foreach (Polyline pl in sectionLineList)
                    {
                        for (int j = 0; j < pl.NumberOfVertices; j++)
                        {
                            double dic = MethodCommand.DistancePointToSegment(pl.GetPoint2dAt(j), line.GetPoint2dAt(i), line.GetPoint2dAt(i + 1));
                            if (dic < 60)
                            {
                                RoadSectionItemModel modelsc = new RoadSectionItemModel();
                                modelsc.Line = AutoCad2ModelTools.Polyline2Model(pl);
                                DBText secMtext = MethodCommand.FindMTextIsInPolyineForPipe(pl, sectionTextList);
                                if (secMtext != null)
                                {
                                    modelsc.SectionName = AutoCad2ModelTools.DbText2Model(secMtext);
                                }
                                item.sectionList.Add(modelsc);
                            }
                        }
                    }
                }

                item.isDashed = MethodCommand.GetLayerLineTypeByIDEx(line);

                item.individualName   = "";
                item.individualFactor = "";
                item.individualCode   = "";
                item.individualStage  = "";

                // 增加个体编码、个体要素、个体名称
                System.Data.DataTable tb = Method.AutoGenerateNumMethod.GetAllPolylineNumsEx(line);
                if (tb.Rows != null && tb.Rows.Count > 0)
                {
                    foreach (System.Data.DataRow row in tb.Rows)
                    {
                        if ((string)row["多段线id"] == line.Id.Handle.Value.ToString())
                        {
                            item.individualName   = (string)row["个体名称"];
                            item.individualFactor = (string)row["个体要素"];
                            item.individualCode   = (string)row["个体编码"];
                            item.individualStage  = (string)row["个体阶段"];
                        }
                    }
                }
                return(item);
            }
        }
Example #4
0
        public System.Data.DataTable AttributeList()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor   ed  = doc.Editor;
            Database db  = doc.Database;

            // 识别个体指标图表 开始

            // 增加一个个体指标dataTable,个体指标必须在同一图层上,且固定一个图层名,比如“个体指标”
            System.Data.DataTable table = new System.Data.DataTable("控制指标");

            TypedValue[] tvs =
                new TypedValue[1] {
                new TypedValue(
                    (int)DxfCode.LayerName,
                    "控制指标"
                    )
            };

            SelectionFilter       sf  = new SelectionFilter(tvs);
            PromptSelectionResult psr = ed.SelectAll(sf);
            SelectionSet          SS  = psr.Value;

            if (psr.Status == PromptStatus.OK)
            {
                ObjectId[] idArray = SS.GetObjectIds();
                using (Transaction acTrans = db.TransactionManager.StartTransaction())
                {
                    // 声明DataColumn、DataRow变量
                    System.Data.DataColumn column;
                    System.Data.DataRow    row;

                    // 个体指标地块编号索引
                    ArrayList index = new ArrayList();
                    // 个体指标图标表头
                    ArrayList biaotou = new ArrayList();

                    // 增加一个排序列表,把实体对应的距离和文本内容放进去
                    SortedList eSListRes = new SortedList();

                    // 循环所有实体 获取表头、地块编号索引
                    for (int j = 0; j < idArray.Length; j++)
                    {
                        Entity ent1 = (Entity)idArray[j].GetObject(OpenMode.ForRead);
                        if (ent1 is MText)
                        {
                            // 循环所有实体
                            for (int c = 0; c < idArray.Length; c++)
                            {
                                // 读取数组里的实体
                                Entity ent2 = (Entity)idArray[c].GetObject(OpenMode.ForRead);
                                if (ent2 is MText && ((MText)ent2).Text == "地块编号")
                                {
                                    // 添加表头
                                    if (((MText)ent2).Location.X <= ((MText)ent1).Location.X && ((MText)ent2).Location.Y - 14 < ((MText)ent1).Location.Y && ((MText)ent1).Location.Y < ((MText)ent2).Location.Y + 14)
                                    {
                                        //MessageBox.Show((((MText)ent1).Text).ToString());
                                        biaotou.Add(ent1);
                                    }

                                    // 添加索引
                                    if (((MText)ent2).Location.Y > ((MText)ent1).Location.Y && ((MText)ent2).Location.X - 14 < ((MText)ent1).Location.X && ((MText)ent1).Location.X < ((MText)ent2).Location.X + 14)
                                    {
                                        //MessageBox.Show((((MText)ent1).Text).ToString());
                                        index.Add(ent1);
                                    }
                                }
                            }
                        }
                    } // 循环整个实体群组结束

                    // 给表头排序 从小到大
                    List <int>    distances = new List <int>();
                    List <string> texts     = new List <string>();
                    string        temp;
                    int           tempDis;
                    for (int i = 0; i < idArray.Length; i++)
                    {
                        Entity ent3 = (Entity)idArray[i].GetObject(OpenMode.ForRead);
                        if (ent3 is MText && ((MText)ent3).Text == "地块编号")
                        {
                            for (int s = 0; s < biaotou.Count; s++)
                            {
                                Entity ent4      = (Entity)biaotou[s];
                                int    eDistance = (int)MethodCommand.DistancePointToPoint(((MText)ent4).Location, ((MText)ent3).Location);
                                //MessageBox.Show(eDistance.ToString());

                                distances.Add(eDistance);
                                texts.Add(((MText)ent4).Text);
                            }

                            // 把获取的属性值按照距离大小排序,距离最近的放在第一位,以此类推
                            for (int m = 0; m < distances.Count; m++)
                            {
                                for (int q = 0; q < distances.Count - m - 1; q++)
                                {
                                    if (distances[q] > distances[q + 1])
                                    {
                                        temp         = texts[q];
                                        texts[q]     = texts[q + 1];
                                        texts[q + 1] = temp;

                                        tempDis          = distances[q];
                                        distances[q]     = distances[q + 1];
                                        distances[q + 1] = tempDis;
                                    }
                                }
                            }
                        }
                    }

                    // 添加表头
                    foreach (string text in texts)
                    {
                        table.Columns.Add(new System.Data.DataColumn(text, typeof(string)));
                    }

                    // 循环所有实体 给每一行排序
                    for (int s = 0; s < index.Count; s++)
                    {
                        distances.Clear();
                        texts.Clear();
                        MText ent3Mtext = (MText)index[s];

                        // 循环所有实体,如果实体的x值大于table索引的x值,加进table的每一行
                        for (int i = 0; i < idArray.Length; i++)
                        {
                            Entity ent4 = (Entity)idArray[i].GetObject(OpenMode.ForRead);

                            if (ent4 is MText)
                            {
                                MText  ent4Mtext = (MText)ent4;
                                int    num       = System.Text.RegularExpressions.Regex.Matches(((MText)ent4).Text, "P").Count;
                                double textHeightPlusLineSpacing = ent4Mtext.TextHeight / 2;
                                double ent4LocationY             = ent4Mtext.Location.Y - ent4Mtext.ActualHeight / 2;
                                double ent3LocationY             = ent3Mtext.Location.Y - ent3Mtext.ActualHeight / 2;

                                if (ent3Mtext.Location.X <= ent4Mtext.Location.X && ent3Mtext.Location.Y - 3.5 < ent4LocationY && ent4LocationY < ent3Mtext.Location.Y + 3.5)
                                {
                                    int eDistance = (int)MethodCommand.DistancePointToPoint(ent4Mtext.Location, ent3Mtext.Location);

                                    //MessageBox.Show(eDistance.ToString());
                                    distances.Add(eDistance);
                                    texts.Add(ent4Mtext.Text.Replace("\r", "").Replace("\n", ""));
                                }
                            }
                        }

                        // 把获取的属性值按照距离大小排序,距离最近的放在第一位,以此类推
                        for (int m = 0; m < distances.Count; m++)
                        {
                            for (int q = 0; q < distances.Count - m - 1; q++)
                            {
                                if (distances[q] > distances[q + 1])
                                {
                                    temp         = texts[q];
                                    texts[q]     = texts[q + 1];
                                    texts[q + 1] = temp;

                                    tempDis          = distances[q];
                                    distances[q]     = distances[q + 1];
                                    distances[q + 1] = tempDis;
                                }
                            }
                        }
                        // 删除多余的文本
                        if (texts.Count > biaotou.Count)
                        {
                            int length = texts.Count;
                            for (int h = length; h > biaotou.Count; h--)
                            {
                                texts.RemoveAt(h - 1);
                            }
                        }

                        row = table.NewRow();
                        for (int f = 0; f < texts.Count; f++)
                        {
                            //MessageBox.Show(table.Columns[f].ToString());
                            row[table.Columns[f]] = texts[f];
                        }

                        table.Rows.Add(row);
                    }
                    // 识别个体指标图表结束

                    //SetupLayout(songsDataGridView);
                } // 事务结束
            }

            // 用地构成表
            //InitializeComponent(songsDataGridView);

            //MessageBox.Show(table.ToString());

            return(table);
        } // form 结束