示例#1
0
        private void button1_Click(object sender, EventArgs e)
        {
            //读配置文件
            string xmlPath = @"C:\Users\czy\Desktop\XYTest\Excle2Shp\Excel2Shp\Excel2Shp\bin\Debug\myData.xml";

            myDictionary = ReadXml.GetXmlFile(xmlPath);

            //获取参数名称
            string WholePath = FClassNameBox2.Text;

            string[] sArray  = WholePath.Split('\\');
            string   GDBname = sArray.GetGDBPath();
            string   FCname  = sArray.GetFeatureName();

            //要Excel读入datatable
            string path      = @ExcelNameBox3.Text;
            string SheetName = FCname;

            exDt = Excel2DataTable.removeEmpty(Excel2DataTable.ReadExcelTool(path, SheetName));
            MessageBox.Show("读取excel至dataTable");

            //打开要素
            ptFeclass = FeatureClassTools.GetFeatureClass(GDBname, FCname);
            MessageBox.Show("成功读取要素");

            //写入属性表
            //int n = myDictionary[SheetName];
            int n = 0;

            FeatureClassTools.WritePtAttribute(exDt, ptFeclass, "Lon", "Lat", n);

            //点转线
        }
示例#2
0
        private void btn_pointToline_Click(object sender, EventArgs e)
        {
            if (PtFClassBox != null)
            {
                //获取点要素和线要素
                //路径和要素名称获取
                string   wholePtPath   = @PtFClassBox.Text;
                string   wholelinePath = @savePathBox.Text;
                string[] pArray        = wholePtPath.Split('\\');
                string[] lArray        = wholelinePath.Split('\\');

                string ptGDBPath = pArray.GetGDBPath();
                string ptName    = pArray.GetFeatureName();
                string lGDBPath  = lArray.GetGDBPath();
                string lname     = lArray.GetFeatureName();

                //获取数据库中的点和要素
                IFeatureClass ptFeatureClass   = Point2LineTool.GetFeatureClass(ptGDBPath, ptName);
                IFeatureClass lineFeatureClass = Point2LineTool.GetFeatureClass(lGDBPath, lname);


                //读配置文件
                string xmlPath = @"C:\Users\czy\Desktop\XYTest\Excle2Shp\Excel2Shp\Excel2Shp\bin\Debug\myData.xml";
                myDictionary = ReadXml.GetXmlFile(xmlPath);

                //读取excel
                //要Excel读入datatable
                string path      = @LineExcelBox.Text;
                string SheetName = lname;
                exDt = Excel2DataTable.removeEmpty(Excel2DataTable.ReadExcelTool(path, SheetName));
                MessageBox.Show("读取excel至dataTable");

                //写属性表
                int n = myDictionary[SheetName];
                FeatureClassTools.WriteLineAttribute(exDt, ptFeatureClass, n);

                //赋几何属性值
                //FeatureCount方法参数为null,返回featureclass中feature的总数
                int      fCount  = ptFeatureClass.FeatureCount(null);
                string[] strline = new string[fCount];
                if (LineFiledBox.Text != "")
                {
                    int            lineID         = ptFeatureClass.FindField(LineFiledBox.Text);
                    IFeatureCursor pFeatureCursor = ptFeatureClass.Search(null, false);
                    for (int i = 0; i < fCount; i++)
                    {
                        strline[i] = pFeatureCursor.NextFeature().get_Value(lineID).ToString();
                    }
                }
                else
                {
                    for (int i = 0; i < fCount; i++)
                    {
                        strline[i] = "";
                    }
                }
                //点一共涉及多少条线段
                int lineCount = Point2LineTool.RepeatTime(strline).Length;
                //所有线段
                string[] lineName = Point2LineTool.RepeatTime(strline);
                int      index;
                if (pointIndexBox.Text == "")
                {
                    index = 0;
                }
                else
                {
                    //点位编号field的ID
                    index = ptFeatureClass.FindField(pointIndexBox.Text);
                }
                for (int i = 0; i < lineCount; i++)
                {
                    IFeature lineFeature = lineFeatureClass.GetFeature(i + 1);
                    lineFeature.Shape = Point2LineTool.CreatePath(lineName[i], ptFeatureClass, index, LineFiledBox.Text) as IGeometry;
                    lineFeature.Store();
                }
            }
            else
            {
                MessageBox.Show("请先完整输入所有参数!");
            }
            MessageBox.Show("完成!");
        }