一個完整的ESRI的shape文件包括一個主文件,一個索引文件,和一個dBASE表文件。主文件是一個直接存取,變記錄長度文件,其中每個記錄描述一 個由其頂點列表組成的shape。在索引文件中,每條記錄是在主文件中對應記錄距離主文件頭部的偏移量。dBASE中記錄的是對應主文件中記錄的屬性記 錄,每條主文件記錄對應dBASE中的一條屬性記錄。幾何對象和屬性間的一一對應關系是基於記錄編號的。在dBASE文件中的屬性記錄必須和主文件中的記 錄保持相同的順序。如果只需要處理dBASE文件,可以用操作數據庫的方式來處理,首先的下載 VFPODBC 的驅動程序,直接安裝即可。
-
建立連接字符串
1 string fileDir = System.Environment.CurrentDirectory; 2 string RelativePath = @"Beijing\ways.dbf"; 3 filePath = Path.Combine(fileDir, RelativePath); 4 connStr = @"Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=" + filePath + 5 ";Exclusive=No;NULL=NO;Collate=Machine;BACKGROUNDFETCH=NO;DELETED=NO";
-
查詢語句
1 string selectSql = @"select * from " + filePath; 2 DataSet dataSet = OdbcHelper.ExecuteDataset(connStr, CommandType.Text, selectSql); 3 DataTable dataTable = dataSet.Tables[0];
-
更新語句
1 string UpdateSql = "UPDATE " + filePath + " SET Len=" + length + " where ID =" + "'" + id + "'"; 2 OdbcHelper.ExecuteNonQuery(connStr, CommandType.Text, UpdateSql);
最后,用ArcGIS 軟件檢驗,發現要修改的屬性信息已經更新完成。
參考資料:
http://blog.csdn.net/lee576/article/details/9959357