Пример #1
0
        private void btnminmaxok_Click(object sender, EventArgs e)
        {
            IsNumberic isnum = new IsNumberic();
            bool       ismin = isnum.IsNumber(txtmin.Text);
            bool       ismax = isnum.IsNumber(txtmax.Text);

            if (ismin && ismax)
            {
                if (Convert.ToDouble(txtmin.Text) < Convert.ToDouble(txtmax.Text))
                {
                    chart1.ChartAreas[0].AxisY.Minimum = Convert.ToDouble(txtmin.Text);
                    chart1.ChartAreas[0].AxisY.Maximum = Convert.ToDouble(txtmax.Text);
                    txtmax.Enabled = false;
                    txtmin.Enabled = false;
                }
                else
                {
                    MessageBox.Show("最小值不能比最大值大", "提示", MessageBoxButtons.OK);
                }
            }
            else
            {
                MessageBox.Show("请输入数字", "提示", MessageBoxButtons.OK);
            }
        }
Пример #2
0
        private void txtOutRows_TextChanged(object sender, EventArgs e)
        {
            IsNumberic isnum = new IsNumberic();

            if (isnum.IsNumber(txtOutRows.Text) && chkRasterSize.Checked)
            {
                double RowsCount = Convert.ToDouble(txtOutRows.Text);
                double cy        = m_pRasterProps.Extent.Height / RowsCount;
                txtCellSizeY.Text = cy.ToString();
            }
        }
Пример #3
0
        private void txtOutColumns_TextChanged(object sender, EventArgs e)
        {
            IsNumberic isnum = new IsNumberic();

            if (isnum.IsNumber(txtOutColumns.Text) && chkRasterSize.Checked)
            {
                double columnCount = Convert.ToDouble(txtOutColumns.Text);
                double cx          = m_pRasterProps.Extent.Width / columnCount;
                txtCellSizeX.Text = cx.ToString();
            }
        }
Пример #4
0
        private void txtCellSizeY_TextChanged(object sender, EventArgs e)
        {
            IsNumberic isnum = new IsNumberic();

            if (isnum.IsNumber(txtCellSizeY.Text) && chkCellSize.Checked)
            {
                double cy = Convert.ToDouble(txtCellSizeY.Text);
                //double RowOut = m_pRasterProps.Extent.Height / cy;
                txtOutRows.Text = (Convert.ToInt32(m_pRasterProps.Extent.Height / cy)).ToString();
            }
        }
Пример #5
0
        private void txtCellSizeX_TextChanged(object sender, EventArgs e)
        {
            IsNumberic isnum = new IsNumberic();

            if (isnum.IsNumber(txtCellSizeX.Text) && chkCellSize.Checked)
            {
                double cx = Convert.ToDouble(txtCellSizeX.Text);
                //double ColumnOut = m_pRasterProps.Extent.Width / cx;
                txtOutColumns.Text = (Convert.ToInt32(m_pRasterProps.Extent.Width / cx)).ToString();
            }
        }
Пример #6
0
        private void txtCircleY_TextChanged(object sender, EventArgs e)
        {
            IsNumberic isNum = new IsNumberic();

            if (isNum.IsNumber(txtCircleY.Text))
            {
                m_circleY = Convert.ToDouble(txtCircleY.Text);
            }
            else
            {
                MessageBox.Show("输入的不是数字", "提示", MessageBoxButtons.OK);
            }
        }
Пример #7
0
        private void btnDraw_Click(object sender, EventArgs e)
        {
            IsNumberic isNum = new IsNumberic();

            if (isNum.IsNumber(txtRadio.Text))
            {
                m_radius          = Convert.ToDouble(txtRadio.Text);
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                MessageBox.Show("输入的不是数字", "提示", MessageBoxButtons.OK);
            }
        }
Пример #8
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                //创建shp文件
                string        strFullName = txtFileName.Text;
                IFeatureClass pFt         = CreateShapeFile(strFullName, pSpaReference);

                if (pFt == null)
                {
                    return;
                }
                //读取richtext文本
                string[]   strSplitLine;
                string[]   strSplitXY;
                IsNumberic isNum = new IsNumberic();
                strSplitLine = System.Text.RegularExpressions.Regex.Split(richTextFile.Text.Trim(), @"\n");
                for (int i = 0; i < strSplitLine.Length; i++)
                {
                    strSplitXY = System.Text.RegularExpressions.Regex.Split(strSplitLine[i], @",");
                    //根据XY坐标添加点
                    IPoint pPoint = new PointClass();
                    if (strSplitXY.Length < 2)
                    {
                        continue;
                    }
                    if (isNum.IsNumber(strSplitXY[0]) && isNum.IsNumber(strSplitXY[1]))
                    {
                        pPoint.X = System.Convert.ToDouble(strSplitXY[0]);
                        pPoint.Y = System.Convert.ToDouble(strSplitXY[1]);
                        IFeature pFeature = pFt.CreateFeature();
                        pFeature.Shape = pPoint;
                        pFeature.Store();
                    }
                }

                IFeatureLayer pFeatureLayer = new FeatureLayerClass();
                pFeatureLayer.FeatureClass = pFt;
                pFeatureLayer.Name         = System.IO.Path.GetFileNameWithoutExtension(System.IO.Path.GetFileNameWithoutExtension(txtFileName.Text));
                m_mapControl.AddLayer(pFeatureLayer as ILayer, 0);
                m_mapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #9
0
 /// <summary>
 /// 设置矩阵
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void dataGridMatrix_CellValueChanged(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex < 3 && e.ColumnIndex >= 0 && e.RowIndex >= 0)
     {
         int        nindex = e.RowIndex * 3 + e.ColumnIndex;
         IsNumberic isnum  = new IsNumberic();
         if (dataGridMatrix.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
         {
             if (isnum.IsNumber(dataGridMatrix.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()))
             {
                 if (e.ColumnIndex == 0 && e.RowIndex == 0)//编辑第一行第一列
                 {
                     rotateMat[nindex] = Convert.ToDouble(dataGridMatrix.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
                     rotateMat[4]      = rotateMat[0];
                     if (isgo)
                     {
                         if (dataGridMatrix.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
                         {
                             dataGridMatrix.Rows[1].Cells[1].Value = Convert.ToDouble(dataGridMatrix.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
                         }
                         else
                         {
                             dataGridMatrix.Rows[1].Cells[1].Value = 0.0;
                         }
                     }
                     //dataGridMatrix.Rows[1].Cells[5].Value = Convert.ToDouble(dataGridMatrix.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
                 }
                 else if (e.ColumnIndex == 1 && e.RowIndex == 0)//编辑第一行第二列
                 {
                     rotateMat[nindex] = Convert.ToDouble(dataGridMatrix.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
                     rotateMat[3]      = -rotateMat[1];
                     if (isgo)
                     {
                         if (dataGridMatrix.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
                         {
                             //dataGridMatrix.Rows[1].Cells[0].Value = -Convert.ToDouble(dataGridMatrix.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
                         }
                         else
                         {
                             dataGridMatrix.Rows[1].Cells[0].Value = 0.0;
                         }
                     }
                     //dataGridMatrix.Rows[1].Cells[4].Value = -Convert.ToDouble(dataGridMatrix.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
                 }
                 else
                 {
                     rotateMat[nindex] = Convert.ToDouble(dataGridMatrix.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
                 }
             }
             else
             {
                 MessageBox.Show("请输入数字", "提示", MessageBoxButtons.OK);
             }
         }
         else
         {
             rotateMat[nindex] = 0.0;
         }
     }
     else if (e.ColumnIndex == 3 && e.RowIndex >= 0)
     {
         if (dataGridMatrix.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
         {
             IsNumberic isnum = new IsNumberic();
             if (isnum.IsNumber(dataGridMatrix.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()))
             {
                 tranVec[e.RowIndex] = Convert.ToDouble(dataGridMatrix.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
             }
             else
             {
                 MessageBox.Show("请输入数字", "提示", MessageBoxButtons.OK);
             }
         }
         else
         {
             tranVec[e.RowIndex] = 0.0;
         }
     }
 }
Пример #10
0
        private void buttonX_ok_Click(object sender, EventArgs e)
        {
            //add all point
            List <IPoint> pointList = new List <IPoint>();
            //add point type
            List <string> typeList = new List <string>();
            //read excel file to creat Field
            string          strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = " + this.textBoxX1.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();

            ISpatialReference pSpaReference = new UnknownCoordinateSystemClass();

            pSpaReference.SetDomain(-8000000, 8000000, -800000, 8000000);
            IFeatureClass pFt = CreateShapeFile(ds, this.textBoxX2.Text, pSpaReference);

            int xindex = 18;
            int yindex = 19;
            int zindex = 20;

            if (ds.Tables[0].Columns[19].ColumnName.ToString().Contains("东坐标"))
            {
                xindex++;
                yindex++;
                zindex++;
            }

            if (pFt == null)
            {
                return;
            }
            else
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    //get type
                    string typeTemp = ds.Tables[0].Rows[i][3].ToString();
                    typeTemp = typeTemp.Split(new char[1] {
                        ' '
                    })[0];
                    //根据XY坐标添加点,edit attribute
                    IsNumberic isNum  = new IsNumberic();
                    IPoint     pPoint = new PointClass();
                    if (isNum.IsNumber(ds.Tables[0].Rows[i][xindex].ToString()) && isNum.IsNumber(ds.Tables[0].Rows[i][yindex].ToString()))
                    {
                        pPoint.X = System.Convert.ToDouble(ds.Tables[0].Rows[i][xindex].ToString());
                        pPoint.Y = System.Convert.ToDouble(ds.Tables[0].Rows[i][yindex].ToString());
                        pPoint.Z = System.Convert.ToDouble(ds.Tables[0].Rows[i][zindex].ToString());
                        IFeature pFeature = pFt.CreateFeature();
                        pFeature.Shape = pPoint;

                        pFeature.Store();
                        for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
                        {
                            //pFeature.set_Value(pFeature.Fields.FindField(ds.Tables[0].Columns[j].ColumnName), ds.Tables[0].Rows[i][j]);
                            pFeature.set_Value(j + 2, ds.Tables[0].Rows[i][j].ToString());
                        }
                        pFeature.set_Value(pFeature.Fields.FindField("Type"), typeTemp);
                        pFeature.Store();

                        pointList.Add(pPoint);
                    }
                    else
                    {
                        MessageBox.Show("the" + i + "rows x and y value is unvalid!");
                    }
                }
            }

            ClsGDBDataCommon processDataCommon = new ClsGDBDataCommon();
            string           strInputPath      = System.IO.Path.GetDirectoryName(textBoxX2.Text);
            string           strInputName      = System.IO.Path.GetFileName(textBoxX2.Text);

            IFeatureLayer pFeatureLayer = new FeatureLayerClass();

            pFeatureLayer.FeatureClass = pFt;
            pFeatureLayer.Name         = System.IO.Path.GetFileNameWithoutExtension(System.IO.Path.GetFileNameWithoutExtension(strInputName)) + "_point";

            //create line shape file
            IPointCollection PointCollection = ReadPoint(pFeatureLayer);
            string           lineName        = strInputPath + "\\" + System.IO.Path.GetFileNameWithoutExtension(strInputName) + "_line.shp";

            CreateLineShpFile(lineName, pSpaReference);
            //将所有的点连接成线
            List <IPolyline> Polyline       = CreatePolyline(PointCollection);
            List <double>    lineLengthList = new List <double>();
            //将连接成的线添加到线图层中
            string pLineFile = lineName;
            string pFilePath = System.IO.Path.GetDirectoryName(pLineFile);
            string pFileName = System.IO.Path.GetFileName(pLineFile);
            //打开工作空间
            IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace pWS  = (IFeatureWorkspace)pWSF.OpenFromFile(pFilePath, 0);
            //写入实体对象
            IFeatureLayer plineLayer = new FeatureLayerClass();

            plineLayer.FeatureClass = pWS.OpenFeatureClass(pFileName);
            AddFeature(plineLayer, Polyline, pointList, lineLengthList);
            plineLayer.Name = pFeatureLayer.Name + "_line";

            m_pMapCtl.AddLayer(plineLayer as ILayer, 0);
            m_pMapCtl.AddLayer(pFeatureLayer as ILayer, 0);
            m_pMapCtl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);

            ImpSymbolFromFile(textBoxX3.Text, pFeatureLayer, plineLayer);

            //export doc file
            string TemplateFileName = ClsGDBDataCommon.GetParentPathofExe() + @"Resource\WordTemplate\内检测报告.doc";

            exportDocFile(TemplateFileName, textBoxX4.Text, lineLengthList);

            //#region 读取SHP文件
            //IWorkspace pWorkspace = processDataCommon.OpenFromShapefile(strInputPath);
            //IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
            //IFeatureClass pInputFC = pFeatureWorkspace.OpenFeatureClass(strInputName);
            //#endregion

            //IFeatureLayer pFeatureLayer = new FeatureLayerClass();
            //pFeatureLayer.FeatureClass = pInputFC;
            //pFeatureLayer.Name = strInputName;
            //m_pMapCtl.AddLayer(pFeatureLayer as ILayer, 0);
            //m_pMapCtl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);

            this.Close();
        }
Пример #11
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            IsNumberic isNum = new IsNumberic();

            if (txtPosX.Text != null && txtPosY != null && txtPosZ != null && txtOriOmg != null &&
                txtOriPhi != null && txtOriKap != null && txtExpAngle != null && txtPitchAngle != null &&
                txtBeginYaw != null)
            {
                if (isNum.IsNumber(txtPosX.Text) && isNum.IsNumber(txtPosY.Text) && isNum.IsNumber(txtPosZ.Text) &&
                    isNum.IsNumber(txtOriOmg.Text) && isNum.IsNumber(txtOriPhi.Text) && isNum.IsNumber(txtOriKap.Text) &&
                    isNum.IsNumber(txtExpAngle.Text) && isNum.IsNumber(txtPitchAngle.Text) &&
                    isNum.IsNumber(txtBeginYaw.Text))
                {
                    dPosX       = Convert.ToDouble(txtPosX.Text);
                    dPosY       = Convert.ToDouble(txtPosY.Text);
                    dPosZ       = Convert.ToDouble(txtPosZ.Text);
                    dOriOmg     = Convert.ToDouble(txtOriOmg.Text);
                    dOriPhi     = Convert.ToDouble(txtOriPhi.Text);
                    dOriKap     = Convert.ToDouble(txtOriKap.Text);
                    dExpAngle   = Convert.ToDouble(txtExpAngle.Text);
                    dYawAngle   = Convert.ToDouble(txtBeginYaw.Text);
                    dPitchAngle = Convert.ToDouble(txtPitchAngle.Text);
                }
                else
                {
                    MessageBox.Show("相机参数值必须为数字,请检查并重新输入", "输入有误", MessageBoxButtons.OK);
                }
            }
            else
            {
                MessageBox.Show("参数值不能为空", "提示", MessageBoxButtons.OK);
            }

            //string exepath = ClsGDBDataCommon.GetParentPathofExe() + @"Resource\rob.exe";
            try
            {
                string s = "";
                //foreach (string arg in args)
                //{
                //    s = s + arg + " ";
                //}
                s = s.Trim();
                if (myprocess == null)
                {
                    myprocess = new Process();
                }
                else
                {
                    myprocess.Close();
                    myprocess.Dispose();
                    myprocess = new Process();
                }



                //if (textBoxParaFile.Text.Trim() == "" || textBoxPicFile.Text.Trim() == "")
                if (textBoxPicFile.Text.Trim() == "")
                {
                    MessageBox.Show("参数不能为空");
                    this.DialogResult = DialogResult.None;
                    return;
                }

                isDialogOk = true;


                //ProcessStartInfo startInfo = new ProcessStartInfo(exepath, textBoxPicFile.Text + " " + textBoxParaFile.Text);
                //myprocess.StartInfo = startInfo;
                ////myprocess.StartInfo.CreateNoWindow = true;
                //myprocess.StartInfo.UseShellExecute = false;
                //myprocess.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show("启动应用程序时出错!原因:" + ex.Message);
            }
        }
Пример #12
0
        private void buttonX_ok_Click(object sender, EventArgs e)
        {
            //add all point
            List <IPoint> pointList = new List <IPoint>();

            Microsoft.Office.Interop.Excel.Application myExcel = new Microsoft.Office.Interop.Excel.Application();
            object missing = System.Reflection.Missing.Value;

            myExcel.Application.Workbooks.Open(textBoxX1.Text, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing); //this.txtFile.Text为Excel文件的全路径
            Microsoft.Office.Interop.Excel.Workbook myBook = myExcel.Workbooks[1];

            //获取第一个Sheet
            Microsoft.Office.Interop.Excel.Worksheet sheet = (Microsoft.Office.Interop.Excel.Worksheet)myBook.Sheets[1];
            string sheetName = sheet.Name; //Sheet名

            myBook.Close(Type.Missing, Type.Missing, Type.Missing);
            myExcel.Quit();

            //read excel file to creat Field
            string          strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = " + this.textBoxX1.Text + ";Extended Properties=Excel 8.0";
            OleDbConnection conn   = new OleDbConnection(strCon);
            string          sql1   = string.Format("select * from [{0}$]", sheetName);

            conn.Open();

            OleDbDataAdapter myCommand = new OleDbDataAdapter(sql1, strCon);
            DataSet          ds        = new DataSet();

            myCommand.Fill(ds);
            conn.Close();

            int xIndex = 0;
            int yIndex = 0;
            int zIndex = 0;

            for (int i = 0; i < ds.Tables[0].Columns.Count; i++)
            {
                if (ds.Tables[0].Columns[i].ColumnName == "X_经度")
                {
                    xIndex = i;
                }
                if (ds.Tables[0].Columns[i].ColumnName == "Y_纬度")
                {
                    yIndex = i;
                }
                if (ds.Tables[0].Columns[i].ColumnName.Contains("Z_高程"))
                {
                    zIndex = i;
                }
            }

            ISpatialReference pSpaReference = new UnknownCoordinateSystemClass();

            pSpaReference.SetDomain(-8000000, 8000000, -800000, 8000000);
            IFeatureClass pFt = CreateShapeFile(ds, this.textBoxX2.Text, pSpaReference);

            if (pFt == null)
            {
                return;
            }
            else
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    //根据XY坐标添加点,edit attribute
                    IsNumberic isNum = new IsNumberic();
                    ESRI.ArcGIS.Geometry.IPoint pPoint = new ESRI.ArcGIS.Geometry.PointClass();
                    if (ds.Tables[0].Rows[i][xIndex].ToString() == "" || ds.Tables[0].Rows[i][xIndex].ToString() == " ")
                    {
                        break;
                    }
                    if (isNum.IsNumber(ds.Tables[0].Rows[i][xIndex].ToString()) && isNum.IsNumber(ds.Tables[0].Rows[i][yIndex].ToString()))
                    {
                        pPoint.X = System.Convert.ToSingle(ds.Tables[0].Rows[i][xIndex].ToString());
                        pPoint.Y = System.Convert.ToSingle(ds.Tables[0].Rows[i][yIndex].ToString());
                        pPoint.Z = System.Convert.ToSingle(ds.Tables[0].Rows[i][zIndex].ToString());
                        IFeature pFeature = pFt.CreateFeature();
                        pFeature.Shape = pPoint;

                        pFeature.Store();
                        for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
                        {
                            if (ds.Tables[0].Columns[j].ColumnName.Contains("里程"))
                            {
                                continue;
                            }
                            //pFeature.set_Value(pFeature.Fields.FindField(ds.Tables[0].Columns[j].ColumnName), ds.Tables[0].Rows[i][j]);
                            pFeature.set_Value(j + 2, ds.Tables[0].Rows[i][j].ToString());
                        }
                        pFeature.Store();

                        pointList.Add(pPoint);
                    }
                    else
                    {
                        MessageBox.Show("the" + i + "rows x and y value is unvalid!");
                    }
                }
            }

            ClsGDBDataCommon processDataCommon = new ClsGDBDataCommon();
            string           strInputPath      = System.IO.Path.GetDirectoryName(textBoxX2.Text);
            string           strInputName      = System.IO.Path.GetFileName(textBoxX2.Text);

            IFeatureLayer pFeatureLayer = new FeatureLayerClass();

            pFeatureLayer.FeatureClass = pFt;
            pFeatureLayer.Name         = System.IO.Path.GetFileNameWithoutExtension(System.IO.Path.GetFileNameWithoutExtension(strInputName));


            //create line shape file
            IPointCollection PointCollection = ReadPoint(pFeatureLayer);
            string           lineName        = strInputPath + "\\" + System.IO.Path.GetFileNameWithoutExtension(strInputName) + "_line.shp";

            CreateLineShpFile(lineName, pSpaReference);
            //将所有的点连接成线
            List <IPolyline> Polyline       = CreatePolyline(PointCollection);
            List <double>    lineLengthList = new List <double>();
            //将连接成的线添加到线图层中
            string pLineFile = lineName;
            string pFilePath = System.IO.Path.GetDirectoryName(pLineFile);
            string pFileName = System.IO.Path.GetFileName(pLineFile);
            //打开工作空间
            IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace pWS  = (IFeatureWorkspace)pWSF.OpenFromFile(pFilePath, 0);
            //写入实体对象
            IFeatureLayer plineLayer = new FeatureLayerClass();

            plineLayer.FeatureClass = pWS.OpenFeatureClass(pFileName);
            AddFeature(plineLayer, Polyline, pointList, lineLengthList);
            plineLayer.Name = pFeatureLayer.Name + "_line";

            m_pMapCtl.AddLayer(plineLayer as ILayer, 0);
            m_pMapCtl.AddLayer(pFeatureLayer as ILayer, 0);
            m_pMapCtl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);

            ImpSymbolFromFile(textBoxX3.Text, pFeatureLayer, plineLayer);

            this.Close();
        }
Пример #13
0
        private void buttonX_ok_Click(object sender, EventArgs e)
        {
            //read excel file to creat Field
            string          strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = " + this.textBoxX1.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();

            int xIndex = 0;
            int yIndex = 0;

            for (int i = 0; i < ds.Tables[0].Columns.Count; i++)
            {
                if (ds.Tables[0].Columns[i].ColumnName == "经度X")
                {
                    xIndex = i;
                }
                if (ds.Tables[0].Columns[i].ColumnName == "纬度Y")
                {
                    yIndex = i;
                }
            }

            ISpatialReference pSpaReference = new UnknownCoordinateSystemClass();

            pSpaReference.SetDomain(-8000000, 8000000, -800000, 8000000);
            IFeatureClass pFt = CreateShapeFile(ds, this.textBoxX2.Text, pSpaReference);

            if (pFt == null)
            {
                return;
            }
            else
            {
                for (int i = 1; i < ds.Tables[0].Rows.Count; i++)//first row is not valuable data
                {
                    //根据XY坐标添加点,edit attribute
                    IsNumberic isNum  = new IsNumberic();
                    IPoint     pPoint = new PointClass();
                    if (isNum.IsNumber(ds.Tables[0].Rows[i][xIndex].ToString()) && isNum.IsNumber(ds.Tables[0].Rows[i][yIndex].ToString()))
                    {
                        pPoint.X = System.Convert.ToSingle(ds.Tables[0].Rows[i][xIndex].ToString());
                        pPoint.Y = System.Convert.ToSingle(ds.Tables[0].Rows[i][yIndex].ToString());
                        IFeature pFeature = pFt.CreateFeature();
                        pFeature.Shape = pPoint;

                        pFeature.Store();
                        for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
                        {
                            //pFeature.set_Value(pFeature.Fields.FindField(ds.Tables[0].Columns[j].ColumnName), ds.Tables[0].Rows[i][j]);
                            pFeature.set_Value(j + 2, ds.Tables[0].Rows[i][j].ToString());
                        }
                        pFeature.Store();
                    }
                    else
                    {
                        MessageBox.Show("the" + i + "rows x and y value is unvalid!");
                    }
                }
            }

            ClsGDBDataCommon processDataCommon = new ClsGDBDataCommon();
            string           strInputPath      = System.IO.Path.GetDirectoryName(textBoxX2.Text);
            string           strInputName      = System.IO.Path.GetFileName(textBoxX2.Text);

            IFeatureLayer pFeatureLayer = new FeatureLayerClass();

            pFeatureLayer.FeatureClass = pFt;
            pFeatureLayer.Name         = System.IO.Path.GetFileNameWithoutExtension(System.IO.Path.GetFileNameWithoutExtension(strInputName));

            //create line shape file
            IPointCollection PointCollection = ReadPoint(pFeatureLayer);
            string           lineName        = strInputPath + "\\" + System.IO.Path.GetFileNameWithoutExtension(strInputName) + "_line.shp";

            CreateLineShpFile(lineName, pSpaReference);
            //将所有的点连接成线
            List <IPolyline> Polyline = CreatePolyline(PointCollection);
            //将连接成的线添加到线图层中
            string pLineFile = lineName;
            string pFilePath = System.IO.Path.GetDirectoryName(pLineFile);
            string pFileName = System.IO.Path.GetFileName(pLineFile);
            //打开工作空间
            IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace pWS  = (IFeatureWorkspace)pWSF.OpenFromFile(pFilePath, 0);
            //写入实体对象
            IFeatureLayer plineLayer = new FeatureLayerClass();

            plineLayer.FeatureClass = pWS.OpenFeatureClass(pFileName);
            AddFeature(plineLayer, Polyline);
            plineLayer.Name = pFeatureLayer.Name + "_line";

            m_pMapCtl.AddLayer(plineLayer as ILayer, 0);
            m_pMapCtl.AddLayer(pFeatureLayer as ILayer, 0);
            m_pMapCtl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);

            ImpSymbolFromFile(textBoxX3.Text, pFeatureLayer, plineLayer);

            this.Close();
        }