Ejemplo n.º 1
0
        private void btOK_Click(object sender, EventArgs e)
        {
            try
            {
                string        pPointFileName        = cboBoxPointLayer.SelectedItem.ToString();
                string        pCenterlinName        = comboBoxExCenterlineLayer.SelectedItem.ToString();
                IFeatureLayer pIMUPointLayer        = null;
                IFeatureLayer pCenterlinePointLayer = null;
                for (int i = 0; i < pMapcontrol.LayerCount; i++)
                {
                    if (pPointFileName == pMapcontrol.get_Layer(i).Name)
                    {
                        pIMUPointLayer = pMapcontrol.get_Layer(i) as IFeatureLayer;
                    }
                    if (pCenterlinName == pMapcontrol.get_Layer(i).Name)
                    {
                        pCenterlinePointLayer = pMapcontrol.get_Layer(i) as IFeatureLayer;
                    }
                }
                IFeatureClass pLineFC              = pCenterlinePointLayer.FeatureClass;
                IFeatureClass pPointFC             = pIMUPointLayer.FeatureClass;
                IQueryFilter  pQF                  = null;
                DataTable     CenterlinePointTable = AOFunctions.GDB.ITableUtil.GetDataTableFromITable(pLineFC as ITable, pQF);
                DataTable     IMUTable             = AOFunctions.GDB.ITableUtil.GetDataTableFromITable(pPointFC as ITable, pQF);

                double beginM = (double)numericUpDown1.Value;
                double endM   = (double)numericUpDown2.Value;



                DataView dv = CenterlinePointTable.DefaultView;
                dv.Sort = "里程(m) ASC";
                CenterlinePointTable = dv.ToTable();
                dv       = IMUTable.DefaultView;
                dv.Sort  = "记录距离__ ASC";
                IMUTable = dv.ToTable();
                double centerlineLength = endM - beginM;
                IMUTable.Columns.Add("X", System.Type.GetType("System.Double"));
                IMUTable.Columns.Add("Y", System.Type.GetType("System.Double"));
                IMUTable.Columns.Add("Z", System.Type.GetType("System.Double"));
                IMUTable.Columns.Add("特征点里程差", System.Type.GetType("System.Double"));
                IMUTable.Columns.Add("对齐里程", System.Type.GetType("System.Double"));

                double endIMUM   = Convert.ToDouble(IMUTable.Rows[IMUTable.Rows.Count - 1]["记录距离__"]);
                double beginIMUM = Convert.ToDouble(IMUTable.Rows[0]["记录距离__"]);
                double IMULength = endIMUM - beginM;

                List <DataRow> WantouPointList = (from DataRow r in IMUTable.Rows
                                                  where r["类型"].ToString().Contains("弯头")
                                                  select r).ToList();
                List <DataRow> GuandianPointList = (from DataRow r in CenterlinePointTable.Rows
                                                    where r["测点属性"].ToString().Contains("拐点")
                                                    select r).ToList();

                Dictionary <DataRow, DataRow> MatchedDataRowPair = new Dictionary <DataRow, DataRow>();
                for (int i = 0; i < WantouPointList.Count; i++)
                {
                    DataRow        IMUr       = WantouPointList[i];
                    double         ActionIMUM = (Convert.ToDouble(IMUr["记录距离__"]) - beginIMUM) * centerlineLength / IMULength + beginM;
                    List <DataRow> Featurerow = (from r in GuandianPointList
                                                 where Math.Abs(Convert.ToDouble(r["里程(m)"]) - ActionIMUM) < Convert.ToDouble(numericUpDown3.Value)
                                                 select r).OrderBy(x => Math.Abs(Convert.ToDouble(x["里程(m)"]) - ActionIMUM)).ToList();
                    if (Featurerow.Count > 0)
                    {
                        DataRow NearestR = Featurerow[0];
                        if (MatchedDataRowPair.Values.Contains(NearestR) == false)
                        {
                            IMUr["特征点里程差"] = Convert.ToDouble(NearestR["里程(m)"]) - ActionIMUM;
                            MatchedDataRowPair.Add(IMUr, NearestR);
                        }
                        else
                        {
                            DataRow mathcedIMUr = (from DataRow k in MatchedDataRowPair.Keys
                                                   where MatchedDataRowPair[k].Equals(NearestR)
                                                   select k).ToList().First();
                            double dis    = Math.Abs(Convert.ToDouble(NearestR["里程(m)"]) - ActionIMUM);
                            double olddis = Math.Abs(Convert.ToDouble(mathcedIMUr["特征点里程差"]));
                            if (dis < olddis)
                            {
                                MatchedDataRowPair.Remove(mathcedIMUr);
                                IMUr["特征点里程差"] = Convert.ToDouble(NearestR["里程(m)"]) - ActionIMUM;
                                MatchedDataRowPair.Add(IMUr, NearestR);
                            }
                            else
                            {
                                continue;
                            }
                        }
                    }
                }

                foreach (DataRow r in MatchedDataRowPair.Keys)
                {
                    r["对齐里程"] = MatchedDataRowPair[r]["里程(m)"];
                }
                IMUTable.Rows[0]["对齐里程"] = beginM;
                IMUTable.Rows[IMUTable.Rows.Count - 1]["对齐里程"] = endM;

                DataRow PrevRowWithM = null;
                for (int i = 0; i < IMUTable.Rows.Count; i++)
                {
                    DataRow r = IMUTable.Rows[i];
                    if (r["对齐里程"] != DBNull.Value)
                    {
                        PrevRowWithM = r;
                    }
                    else
                    {
                        DataRow NextRowWithM = null;
                        for (int j = i + 1; j < IMUTable.Rows.Count; j++)
                        {
                            DataRow r2 = IMUTable.Rows[j];
                            if (r2["对齐里程"] != DBNull.Value)
                            {
                                NextRowWithM = r2;
                                break;
                            }
                        }
                        if (PrevRowWithM == null || NextRowWithM == null)
                        {
                            break;
                        }
                        double BeginJiluM   = Convert.ToDouble(PrevRowWithM["记录距离__"]);
                        double endJiluM     = Convert.ToDouble(NextRowWithM["记录距离__"]);
                        double BeginAM      = Convert.ToDouble(PrevRowWithM["对齐里程"]);
                        double endAM        = Convert.ToDouble(NextRowWithM["对齐里程"]);
                        double currentJiluM = Convert.ToDouble(r["记录距离__"]);
                        r["对齐里程"] = (currentJiluM - BeginJiluM) * (endAM - BeginAM) / (endJiluM - BeginJiluM) + BeginAM;
                    }
                }

                //for (int i = 0; i < CenterlinePointTable.Rows.Count; i++)
                //{
                //    DataRow r = CenterlinePointTable.Rows[i];
                //    double cM = Convert.ToDouble(r["里程(m)"]);
                //    if (cM < beginM)
                //    {
                //        continue;
                //    }
                //    if (cM > endM)
                //    {
                //        break;
                //    }
                //    for (int j = 0; j < IMUTable.Rows.Count; j++)
                //    {
                //        DataRow IMUr = IMUTable.Rows[j];
                //        double ActionIMUM = (Convert.ToDouble(IMUr["记录距离__"]) - beginIMUM) * centerlineLength / IMULength + beginM;

                //    }
                //}
                IFeatureLayer pLinearlayer          = null;
                string        pCenterlineLinearName = comboBoxExCenterlineLinearLayer.SelectedItem.ToString();
                for (int i = 0; i < pMapcontrol.LayerCount; i++)
                {
                    if (pCenterlineLinearName == pMapcontrol.get_Layer(i).Name)
                    {
                        pLinearlayer = pMapcontrol.get_Layer(i) as IFeatureLayer;
                    }
                }
                IFeatureCursor pcursor  = pLinearlayer.FeatureClass.Search(null, false);
                IFeature       pFeature = pcursor.NextFeature();
                IPolyline      pline    = pFeature.Shape as IPolyline;
                IMSegmentation mSegment = pline as IMSegmentation;
                double         maxM     = mSegment.MMax;
                double         minM     = mSegment.MMin;

                if (beginM > maxM || beginM < minM || endM > maxM || endM < minM)
                {
                    MessageBox.Show("输入的起始或终点里程值超出中线里程范围!");
                    return;
                }

                for (int i = 0; i < IMUTable.Rows.Count; i++)
                {
                    DataRow r = IMUTable.Rows[i];
                    double  M = Convert.ToDouble(r["对齐里程"]);

                    IGeometryCollection ptcollection = mSegment.GetPointsAtM(M, 0);
                    IPoint pt = ptcollection.get_Geometry(0) as IPoint;
                    r["X"] = pt.X;
                    r["Y"] = pt.Y;
                    r["Z"] = pt.Z;
                }


                FrmIMUAlignmentresult frm = new FrmIMUAlignmentresult(IMUTable);
                frm.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }