读取shp数据的属性表数据(*.dbf)

   //获取shp文件的属性表数据
        public DataTable GetShpDataTable(string shpPath)
        {
            System.Data.Odbc.OdbcConnection conn = new System.Data.Odbc.OdbcConnection();
            string table = shpPath;
            string connStr = @”Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=” + table + “;Exclusive=No;NULL=NO;Collate=Machine;BACKGROUNDFETCH=NO;DELETED=NO”;

            conn.ConnectionString = connStr;
            conn.Open();

            OdbcCommand cmd = new OdbcCommand();
            cmd.Connection = conn;
            string sql = “update ” + table + ” set other=’2′,rate=1.014 “;
            cmd.CommandText = sql;
            cmd.CommandType = CommandType.Text;
            //cmd.ExecuteNonQuery();

            sql = @”select * from ” + table;
            OdbcDataAdapter da = new OdbcDataAdapter(sql, conn);
            DataTable dt = new DataTable();
            da.Fill(dt);
            return dt;
        }
        //读取datatable中的值
        public void ReadDatatableToPoints(DataTable dt)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                IPoint ipoint = new PointClass();
                ipoint.X = Convert.ToDouble(dt.Rows[i][“POINT_X”]);
                ipoint.Y = Convert.ToDouble(dt.Rows[i][“POINT_Y”]);
                ipoint.ID = i;
                points.Add(ipoint);
            }

        }
 

转载自:https://blog.csdn.net/Sun_xiangyan/article/details/86515025

You may also like...