Esempio n. 1
0
        private void btOK_Click(object sender, EventArgs e)
        {
            try
            {
                string          strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = " + this.textBoxFile.Text + ";Extended Properties=Excel 8.0";
                OleDbConnection conn   = new OleDbConnection(strCon);
                string          sql1   = "select * from [Sheet1$]";
                conn.Open();
                OleDbDataAdapter myCommand = new OleDbDataAdapter(sql1, strCon);
                DataSet          ds        = new DataSet();
                myCommand.Fill(ds);
                conn.Close();
                DataTable alignmentPointTable = ds.Tables[0];
                if (!alignmentPointTable.Columns.Contains("对齐里程"))
                {
                    MessageBox.Show("对齐外检测表的'对齐里程' 不存在!");
                    return;
                }
                alignmentPointTable.Columns["对齐里程"].DataType = System.Type.GetType("System.Double");


                strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = " + this.textBoxFileBase.Text + ";Extended Properties=Excel 8.0";
                conn   = new OleDbConnection(strCon);
                sql1   = "select * from [Sheet1$]";
                conn.Open();
                myCommand = new OleDbDataAdapter(sql1, strCon);
                ds        = new DataSet();
                myCommand.Fill(ds);
                conn.Close();
                DataTable basetable = ds.Tables[0];

                double tolerance   = Convert.ToDouble(numericUpDown1.Value);
                string measurevcol = "对齐里程";
                MatchWaijianceTable(basetable, ref alignmentPointTable, measurevcol, tolerance);

                FrmIMUAlignmentresult frm = new FrmIMUAlignmentresult(alignmentPointTable);
                frm.setResultType("两次外检测对齐报告");
                frm.BasePointTable      = basetable;
                frm.AlignmentPointTable = alignmentPointTable;
                frm.ShowDialog();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 2
0
        private void buttonXOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (IMUFeatureList.Count < 2)
                {
                    MessageBox.Show("最少需要2个特征点");
                    return;
                }

                IQueryFilter  pQF     = null;
                IFeatureClass pLineFC = CenterlinePointLayer.FeatureClass;
                DataTable     CenterlinePointTable = AOFunctions.GDB.ITableUtil.GetDataTableFromITable(pLineFC as ITable, pQF);
                IFeatureClass pPointFC             = IMULayer.FeatureClass;

                DataTable IMUTable;
                IMUTable = AOFunctions.GDB.ITableUtil.GetDataTableFromITable(pPointFC as ITable, pQF);

                Dictionary <DataRow, DataRow> MatchedDataRowPair = new Dictionary <DataRow, DataRow>();
                List <IFeature> sortedIMUList = (from IFeature f in IMUFeatureList
                                                 select f).OrderBy(x => x.get_Value(x.Fields.FindField(EvConfig.IMUMoveDistanceField))).ToList();

                List <IFeature> sortedCenterlinePointList = (from IFeature f in CenterlinePointFeatureList
                                                             select f).OrderBy(x => x.get_Value(x.Fields.FindField(EvConfig.CenterlineMeasureField))).ToList();


                DataView dv = CenterlinePointTable.DefaultView;
                // dv.Sort = "里程(m) ASC";
                dv.Sort = EvConfig.CenterlineMeasureField + " ASC";
                CenterlinePointTable = dv.ToTable();
                dv = IMUTable.DefaultView;
                // dv.Sort = "记录距离__ ASC";
                dv.Sort  = EvConfig.IMUMoveDistanceField + " ASC";
                IMUTable = dv.ToTable();


                // double centerlineLength = endM - beginM;
                if (!IMUTable.Columns.Contains("X"))
                {
                    IMUTable.Columns.Add("X", System.Type.GetType("System.Double"));
                }
                if (!IMUTable.Columns.Contains("Y"))
                {
                    IMUTable.Columns.Add("Y", System.Type.GetType("System.Double"));
                }
                if (!IMUTable.Columns.Contains("Z"))
                {
                    IMUTable.Columns.Add("Z", System.Type.GetType("System.Double"));
                }
                if (!IMUTable.Columns.Contains("里程差"))
                {
                    IMUTable.Columns.Add("里程差", System.Type.GetType("System.Double"));
                }
                if (!IMUTable.Columns.Contains("对齐里程"))
                {
                    IMUTable.Columns.Add("对齐里程", System.Type.GetType("System.Double"));
                }

                for (int i = 0; i < IMUFeatureList.Count; i++)
                {
                    int     oid1          = sortedIMUList[i].OID;
                    int     oid2          = sortedCenterlinePointList[i].OID;
                    DataRow IMURow        = IMUTable.AsEnumerable().First(x => Convert.ToInt16(x[0]) == oid1);
                    DataRow CenterlineRow = CenterlinePointTable.AsEnumerable().First(x => Convert.ToInt16(x[0]) == oid2);
                    MatchedDataRowPair.Add(IMURow, CenterlineRow);
                }


                foreach (DataRow r in IMUTable.Rows)
                {
                    r["对齐里程"] = DBNull.Value;
                    r["里程差"]  = DBNull.Value;
                }

                double endIMUM   = Convert.ToDouble(IMUTable.Rows[IMUTable.Rows.Count - 1][EvConfig.IMUMoveDistanceField]);
                double beginIMUM = Convert.ToDouble(IMUTable.Rows[0][EvConfig.IMUMoveDistanceField]);
                double IMULength = endIMUM - beginIMUM;

                double CenterlineBeginM = Convert.ToDouble(CenterlinePointTable.Rows[0][EvConfig.CenterlineMeasureField]);
                double CenterlineEndM   = Convert.ToDouble(CenterlinePointTable.AsEnumerable().Last()[EvConfig.CenterlineMeasureField]);

                foreach (DataRow r in MatchedDataRowPair.Keys)
                {
                    r["对齐里程"] = MatchedDataRowPair[r][EvConfig.CenterlineMeasureField];
                    r["里程差"]  = 0;
                }

                //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();

                DataTable alignmentPointTable = IMUTable;

                double beginM = 0;
                double endM   = 0;
                var    query  = (from r in alignmentPointTable.AsEnumerable()
                                 where r["对齐里程"] != DBNull.Value
                                 select r).ToList();
                if (query.Count > 0)
                {
                    DataRow r = query[0];
                    if (IMUTable.Rows[0]["对齐里程"] != DBNull.Value)
                    {
                        beginM = Convert.ToDouble(IMUTable.Rows[0]["对齐里程"]);
                    }
                    else
                    {
                        beginM = Convert.ToDouble(r["对齐里程"]) -
                                 (Convert.ToDouble(r[EvConfig.IMUMoveDistanceField]) - Convert.ToDouble(alignmentPointTable.Rows[0][EvConfig.IMUMoveDistanceField]));
                        alignmentPointTable.Rows[0]["对齐里程"] = beginM;
                    }


                    int idx = alignmentPointTable.Rows.Count - 1;
                    r = query[query.Count - 1];

                    if (IMUTable.AsEnumerable().Last()["对齐里程"] != DBNull.Value)
                    {
                        endM = Convert.ToDouble(IMUTable.AsEnumerable().Last()["对齐里程"]);
                    }
                    else
                    {
                        endM = Convert.ToDouble(r["对齐里程"]) +
                               (Convert.ToDouble(alignmentPointTable.Rows[idx][EvConfig.IMUMoveDistanceField]) - Convert.ToDouble(r[EvConfig.IMUMoveDistanceField]));
                        alignmentPointTable.Rows[idx]["对齐里程"] = endM;
                    }
                }

                if (beginM < CenterlineBeginM)
                {
                    beginM = CenterlineBeginM;
                    alignmentPointTable.Rows[0]["对齐里程"] = beginM;
                }
                if (endM > CenterlineEndM)
                {
                    int idx = alignmentPointTable.Rows.Count - 1;
                    endM = CenterlineEndM;
                    alignmentPointTable.Rows[idx]["对齐里程"] = 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[EvConfig.IMUMoveDistanceField]);
                        double endJiluM     = Convert.ToDouble(NextRowWithM[EvConfig.IMUMoveDistanceField]);
                        double BeginAM      = Convert.ToDouble(PrevRowWithM["对齐里程"]);
                        double endAM        = Convert.ToDouble(NextRowWithM["对齐里程"]);
                        double currentJiluM = Convert.ToDouble(r[EvConfig.IMUMoveDistanceField]);
                        r["对齐里程"] = (currentJiluM - BeginJiluM) * (endAM - BeginAM) / (endJiluM - BeginJiluM) + BeginAM;
                    }
                }

                IFeatureLayer pLinearlayer = CenterlineLinarLayer;

                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.CenterlinePointTable = CenterlinePointTable;
                frm.setResultType("内检测对齐中线报告");
                frm.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 3
0
        private void btOK_Click(object sender, EventArgs e)
        {
            try
            {
                string        pPointFileName   = cboBoxPointLayer.SelectedItem.ToString();
                string        pCenterlinName   = comboBoxExCenterlineLinearLayer.SelectedItem.ToString();
                IFeatureLayer pPointLayer      = null;
                IFeatureLayer pCenterlineLayer = null;
                for (int i = 0; i < pMapcontrol.LayerCount; i++)
                {
                    if (pPointFileName == pMapcontrol.get_Layer(i).Name)
                    {
                        pPointLayer = pMapcontrol.get_Layer(i) as IFeatureLayer;
                    }
                    if (pCenterlinName == pMapcontrol.get_Layer(i).Name)
                    {
                        pCenterlineLayer = pMapcontrol.get_Layer(i) as IFeatureLayer;
                    }
                }
                IFeatureClass  pLineFC      = pCenterlineLayer.FeatureClass;
                IFeatureClass  pPointFC     = pPointLayer.FeatureClass;
                IFeatureCursor pLineCursor  = pLineFC.Search(null, false);
                IFeature       pLineFeature = pLineCursor.NextFeature();
                IQueryFilter   qf1          = null;
                DataTable      ptable;

                if (radioButtonLayer.Checked)
                {
                    ptable = AOFunctions.GDB.ITableUtil.GetDataTableFromITable(pPointFC as ITable, qf1);
                }
                else
                {
                    string          strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = " + this.textBoxFile.Text + ";Extended Properties=Excel 8.0";
                    OleDbConnection conn   = new OleDbConnection(strCon);
                    string          sql1   = "select * from [Sheet1$]";
                    conn.Open();
                    OleDbDataAdapter myCommand = new OleDbDataAdapter(sql1, strCon);
                    DataSet          ds        = new DataSet();
                    myCommand.Fill(ds);
                    conn.Close();
                    ptable = ds.Tables[0];
                    if (ptable.Columns.Contains(EvConfig.IMUMoveDistanceField))
                    {
                        ptable.Columns[EvConfig.IMUMoveDistanceField].DataType = System.Type.GetType("System.Double");
                    }
                }


                if (!ptable.Columns.Contains("X"))
                {
                    ptable.Columns.Add("X", System.Type.GetType("System.Double"));
                }
                if (!ptable.Columns.Contains("Y"))
                {
                    ptable.Columns.Add("Y", System.Type.GetType("System.Double"));
                }
                if (!ptable.Columns.Contains("Z"))
                {
                    ptable.Columns.Add("Z", System.Type.GetType("System.Double"));
                }
                if (!ptable.Columns.Contains("对齐里程"))
                {
                    ptable.Columns.Add("对齐里程", System.Type.GetType("System.Double"));
                }
                if (!ptable.Columns.Contains("距离偏移"))
                {
                    ptable.Columns.Add("距离偏移", System.Type.GetType("System.Double"));
                }
                ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
                //wgs 84
                IGeographicCoordinateSystem wgs84 = spatialReferenceFactory.CreateGeographicCoordinateSystem(4326) as IGeographicCoordinateSystem;
                IUnit meterUnit = spatialReferenceFactory.CreateUnit((int)ESRI.ArcGIS.Geometry.esriSRUnitType.esriSRUnit_Meter);

                IPolyline pline = pLineFeature.Shape as IPolyline;
                pline.SpatialReference = wgs84;

                IProximityOperator pPO = pline as IProximityOperator;

                int idx = 0;
                for (int i = 0; i < ptable.Rows.Count; i++)
                {
                    try
                    {
                        DataRow r  = ptable.Rows[i];
                        IPoint  pt = new PointClass();
                        pt.X = Convert.ToDouble(r[EvConfig.WeldXField]);
                        pt.Y = Convert.ToDouble(r[EvConfig.WeldYField]);
                        pt.SpatialReference = wgs84;
                        IPoint ptInLine = pPO.ReturnNearestPoint(pt, esriSegmentExtension.esriNoExtension);
                        r["X"]    = ptInLine.X;
                        r["Y"]    = ptInLine.Y;
                        r["对齐里程"] = ptInLine.M;
                        r["Z"]    = ptInLine.Z;

                        r["距离偏移"] = Math.Round(DataAlignment.DataAlignment.CalculateDistanceBetween84TwoPoints(pt, ptInLine), 2);
                    }
                    catch
                    {
                    }
                }
                System.Runtime.InteropServices.Marshal.ReleaseComObject(spatialReferenceFactory);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pLineCursor);


                FrmIMUAlignmentresult frm = new FrmIMUAlignmentresult(ptable);
                frm.setResultType("焊缝对齐报告");
                frm.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 4
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);
            }
        }
        private void btOK_Click(object sender, EventArgs e)
        {
            try
            {
                string        pBasePointFileName    = cboBoxPointLayer.SelectedItem.ToString();
                string        pAlignmentPointnName  = comboBoxExCenterlineLayer.SelectedItem.ToString();
                IFeatureLayer pBasePointLayer       = null;
                IFeatureLayer pCenterlinePointLayer = null;
                for (int i = 0; i < pMapcontrol.LayerCount; i++)
                {
                    if (pBasePointFileName == pMapcontrol.get_Layer(i).Name)
                    {
                        pBasePointLayer = pMapcontrol.get_Layer(i) as IFeatureLayer;
                    }
                    if (pAlignmentPointnName == pMapcontrol.get_Layer(i).Name)
                    {
                        pCenterlinePointLayer = pMapcontrol.get_Layer(i) as IFeatureLayer;
                    }
                }
                IFeatureClass pAlignmentPointFC = pCenterlinePointLayer.FeatureClass;
                IFeatureClass pPointFC          = pBasePointLayer.FeatureClass;
                IQueryFilter  pQF = null;
                DataTable     alignmentPointTable = AOFunctions.GDB.ITableUtil.GetDataTableFromITable(pAlignmentPointFC as ITable, pQF);
                DataTable     baseTable           = AOFunctions.GDB.ITableUtil.GetDataTableFromITable(pPointFC as ITable, pQF);

                //IMUTable => basetable, Centerlinetable => alignmenttable
                double beginM = (double)numericUpDown1.Value;
                double endM   = (double)numericUpDown2.Value;


                string baseMeasureColumn  = comboBoxBaseMeasureField.SelectedItem.ToString();
                string AlingMeasureColumn = comboBoxMeasureField.SelectedItem.ToString();

                DataView dv = baseTable.DefaultView;
                dv.Sort             = baseMeasureColumn + " ASC";
                baseTable           = dv.ToTable();
                dv                  = alignmentPointTable.DefaultView;
                dv.Sort             = AlingMeasureColumn + " ASC";
                alignmentPointTable = dv.ToTable();

                double centerlineLength = endM - beginM;
                alignmentPointTable.Columns.Add("特征点里程差");
                alignmentPointTable.Columns.Add("对齐里程");

                double endIMUM   = Convert.ToDouble(alignmentPointTable.Rows[alignmentPointTable.Rows.Count - 1][AlingMeasureColumn]);
                double beginIMUM = Convert.ToDouble(alignmentPointTable.Rows[0][AlingMeasureColumn]);
                double IMULength = endIMUM - beginM;

                List <DataRow> WantouPointList = (from DataRow r in alignmentPointTable.Rows
                                                  where r["类型"].ToString().Contains("弯头")
                                                  select r).ToList();
                List <DataRow> GuandianPointList = (from DataRow r in baseTable.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[AlingMeasureColumn]) - beginIMUM) * centerlineLength / IMULength + beginM;
                    List <DataRow> Featurerow = (from r in GuandianPointList
                                                 where Math.Abs(Convert.ToDouble(r[baseMeasureColumn]) - ActionIMUM) < Convert.ToDouble(numericUpDown3.Value)
                                                 select r).OrderBy(x => Math.Abs(Convert.ToDouble(x[baseMeasureColumn]) - ActionIMUM)).ToList();
                    if (Featurerow.Count > 0)
                    {
                        DataRow NearestR = Featurerow[0];
                        if (MatchedDataRowPair.Values.Contains(NearestR) == false)
                        {
                            IMUr["特征点里程差"] = Convert.ToDouble(NearestR[baseMeasureColumn]) - 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[baseMeasureColumn]) - ActionIMUM);
                            double olddis = Math.Abs(Convert.ToDouble(mathcedIMUr["特征点里程差"]));
                            if (dis < olddis)
                            {
                                MatchedDataRowPair.Remove(mathcedIMUr);
                                IMUr["特征点里程差"] = Convert.ToDouble(NearestR[baseMeasureColumn]) - ActionIMUM;
                                MatchedDataRowPair.Add(IMUr, NearestR);
                            }
                            else
                            {
                                continue;
                            }
                        }
                    }
                }
                foreach (DataRow r in MatchedDataRowPair.Keys)
                {
                    r["对齐里程"] = MatchedDataRowPair[r][baseMeasureColumn];
                }
                alignmentPointTable.Rows[0]["对齐里程"] = beginM;
                alignmentPointTable.Rows[alignmentPointTable.Rows.Count - 1]["对齐里程"] = endM;

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


                MatchedDataRowPair.Clear();
                alignmentPointTable.Columns.Add("对齐基准点里程");
                alignmentPointTable.Columns.Add("对齐基准点里程差");
                alignmentPointTable.Columns.Add("对齐基准点类型");

                foreach (DataRow IMUr in alignmentPointTable.Rows)
                {
                    double ActionIMUM = Convert.ToDouble(IMUr["对齐里程"]);

                    List <DataRow> Featurerow = (from DataRow r in baseTable.Rows
                                                 where Math.Abs(Convert.ToDouble(r[baseMeasureColumn]) - ActionIMUM) < Convert.ToDouble(numericUpDown3.Value) &&
                                                 ((r["类型"].ToString().Contains("弯头") && IMUr["类型"].ToString().Contains("弯头")) ||
                                                  (r["类型"].ToString().Contains("异常") && IMUr["类型"].ToString().Contains("异常")))
                                                 select r).OrderBy(x => Math.Abs(Convert.ToDouble(x[baseMeasureColumn]) - ActionIMUM)).ToList();
                    if (Featurerow.Count > 0)
                    {
                        DataRow NearestR = Featurerow[0];
                        if (MatchedDataRowPair.Values.Contains(NearestR) == false)
                        {
                            IMUr["对齐基准点里程差"] = Convert.ToDouble(NearestR[baseMeasureColumn]) - ActionIMUM;
                            IMUr["对齐基准点里程"]  = NearestR[baseMeasureColumn];
                            IMUr["对齐基准点类型"]  = NearestR["类型"];
                            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[baseMeasureColumn]) - ActionIMUM);
                            double olddis = Math.Abs(Convert.ToDouble(mathcedIMUr["对齐基准点里程差"]));
                            if (dis < olddis)
                            {
                                MatchedDataRowPair.Remove(mathcedIMUr);
                                IMUr["对齐基准点里程差"] = Convert.ToDouble(NearestR[baseMeasureColumn]) - ActionIMUM;
                                IMUr["对齐基准点里程"]  = NearestR[baseMeasureColumn];
                                IMUr["对齐基准点类型"]  = NearestR["类型"];
                                MatchedDataRowPair.Add(IMUr, NearestR);
                            }
                            else
                            {
                                continue;
                            }
                        }
                    }
                }



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