陳 平,高仕華,楊海關(guān),代進(jìn)文
(1.云南省測繪工程院,云南 昆明 650034; 2.云南省測繪產(chǎn)品檢測站,云南 昆明 650034)
?
第二次全國地名普查地名登記表批量導(dǎo)入的實(shí)現(xiàn)*
陳平1,高仕華1,楊海關(guān)2,代進(jìn)文1
(1.云南省測繪工程院,云南 昆明650034; 2.云南省測繪產(chǎn)品檢測站,云南 昆明650034)
隨著第二次全國地名普查的深入開展,地名登記表已經(jīng)基本填寫完畢,如何高效、快速地將地名登記表錄入到地名普查數(shù)據(jù)管理系統(tǒng)中顯得非常重要,文章介紹了基于C#編程把地名登記表批量導(dǎo)入到地名屬性表,然后將地名屬性表一次性錄入到地名普查數(shù)據(jù)管理系統(tǒng)的方法,極大地提高了工作效率。
地名普查;地名登記表;批量導(dǎo)入;C#
云南省第二次全國地名普查從2014年7月1日開始,到2018年6月30日結(jié)束,分4個階段實(shí)施(動員部署階段、全面普查階段、檢查驗收上報階段、普查成果開發(fā)利用階段)。
地名普查的任務(wù)是查清地名基本情況,對有地?zé)o名的有地名作用的地理實(shí)體進(jìn)行命名,對不規(guī)范地名進(jìn)行標(biāo)準(zhǔn)化處理,設(shè)置標(biāo)準(zhǔn)規(guī)范的地名標(biāo)志,建立、完善各級國家地名和區(qū)劃數(shù)據(jù)庫(國家地名數(shù)據(jù)庫)。
地名是基礎(chǔ)地理信息。地名普查是一項公益性、基礎(chǔ)性的國情調(diào)查。開展地名普查,查清并掌握地名基本情況,提高地名標(biāo)準(zhǔn)化水平,為社會提供全面準(zhǔn)確的地名信息,有利于維護(hù)國家主權(quán)和領(lǐng)土完整、鞏固國防建設(shè),有利于經(jīng)濟(jì)社會協(xié)調(diào)發(fā)展,有利于社會交流交往、方便人民群眾生產(chǎn)生活,對提高政府管理水平和公共服務(wù)具有重要意義[1-4]。
云南省第二次全國地名普查使用的普查軟件為江蘇速度信息科技有限公司開發(fā)的云南省第二次全國地名普查數(shù)據(jù)建庫與管理軟件[1]。該軟件提供了地名屬性表(Excel)數(shù)據(jù)導(dǎo)入功能,能夠?qū)崿F(xiàn)地名信息批量導(dǎo)入。但在全面普查階段中,填寫的地名登記表都是單張的Word表格,如表1所示。為此,本文介紹了基于C#編程批量實(shí)現(xiàn)所有地名登記表(Word)批量導(dǎo)入地名屬性表(Excel)的方法,從而實(shí)現(xiàn)地名信息的批量導(dǎo)入。
1.1程序?qū)崿F(xiàn)方法
程序通過打開文件夾中的每一張地名登記表,讀取地名登記表中的類別名稱,判斷類別名稱為第二次全國地名普查內(nèi)容與指標(biāo)中的一級、二級、三級類別名稱中具體的哪一個類別,然后再讀取地名登記表(Word)中每一個單元格的信息,根據(jù)對應(yīng)關(guān)系寫入到地名屬性表(Excel)相應(yīng)的單元格中,將地名登記表內(nèi)的屬性導(dǎo)入到相應(yīng)的地名屬性表中。地名屬性表包括陸地水系、陸地地形、行政區(qū)域、群眾自治組織、非行政區(qū)域、居民點(diǎn)、交通運(yùn)輸設(shè)施、水利水電通信設(shè)施、紀(jì)念地旅游景點(diǎn)、建筑物、單位共11個大類的屬性表格。
程序打開、讀取、判斷每一張地名登記表,并導(dǎo)入到相應(yīng)的地名屬性表后,關(guān)閉該地名登記表和相應(yīng)的地名屬性表,然后循環(huán)操作下一張地名登記表和相應(yīng)的地名屬性表,直到選擇的文件夾下的所有地名登記表都導(dǎo)入完畢。該方法能夠快速釋放內(nèi)存,不會因為地名登記表數(shù)量太多而導(dǎo)致電腦內(nèi)存不足崩潰死機(jī),程序運(yùn)行效率較高。
表1地名登記表樣表
Tab.1Place names registration form’s sample
1.2程序?qū)崿F(xiàn)主要代碼
程序?qū)崿F(xiàn)的主要代碼如下:
string path = @textBox1.Text;
string path1 = @textBox3.Text;
string[] fileList = Directory.GetFileSystemEntries(path1);
int m = 2;
{
foreach(stringfileinfileList)
{
if(File.Exists(file))
{
objectunknow=Type.Missing;
msWord.Applicationwordapp=newmsWord
.Application();
wordapp.Visible=false;
try
{
msWord.Documentworddoc=wordapp.Documents.Open(file,refunknow,refunknow);
stringmystring=worddoc.Tables[1].Cell(1,4).Range.Text.Trim().ToString()
.Replace(" ","");
//河流
{
if(mystring=="河流")
{
stringfilename=this.textBox1.Text+
"\01陸地水系.xlsx";
stringconnectstring=string.Format
("Provider=Microsoft.Jet.OLEDB.4.0;
datasource=filename;ExtendedProperties
=' Excel8.0' ");
OleDbConnectionmyconn=newOleDbConnection
(connectstring);
myconn.Open();
excel.Applicationexcelapp=newMicrosoft
.Office.Interop.Excel.Application();
excel.Workbookbook=excelapp.Workbooks
.Open(filename,Missing.Value,false
,Missing.Value,Missing.Value,Missing
.Value,true,Missing.Value,Missing.Value
,Missing.Value,Missing.Value,Missing
.Value,Missing.Value,Missing.Value
,Missing.Value);
excel.Worksheetsheet=book.Worksheets
.get_Item(1);
introwsint=sheet.UsedRange.Cells.Columns
.Count;
introwsinti=sheet.UsedRange.Rows.Count;
sheet.Rows.Cells[1][m]=m-1;
sheet.Rows.Cells[2][m]="";
sheet.Rows.Cells[3][m]=worddoc.Tables[1]
.Cell(2,3).Range.Text.Trim().ToString()
.Replace(" ","");
sheet.Rows.Cells[4][m]=worddoc.Tables[1]
.Cell(7,3).Range.Text.Trim().ToString()
.Replace(" ","");
sheet.Rows.Cells[5][m]=worddoc.Tables[1]
.Cell(8,3).Range.Text.Trim().ToString()
.Replace(" ","");
sheet.Rows.Cells[6][m]=worddoc.Tables[1]
.Cell(7,5).Range.Text.Trim().ToString()
.Replace(" ","");
sheet.Rows.Cells[7][m]=worddoc.Tables[1]
.Cell(8,5).Range.Text.Trim().ToString()
.Replace(" ","");
sheet.Rows.Cells[8][m]=worddoc.Tables[1]
.Cell(11,2).Range.Text.Trim().ToString()
.Replace(" ","");
sheet.Rows.Cells[9][m]="";
sheet.Rows.Cells[10][m]="";
sheet.Rows.Cells[11][m]= "";
sheet.Rows.Cells[12][m]=worddoc.Tables[1]
.Cell(22,2).Range.Text.Trim().ToString()
.Replace(" ","");
sheet.Rows.Cells[13][m]=worddoc.Tables[1]
.Cell(5,3).Range.Text.Trim().ToString()
.Replace(" ","").Remove(4,worddoc.Tables
[1].Cell(5,3).Range.Text.Trim()
.ToString().Replace(" ","").Length-4);
sheet.Rows.Cells[14][m]=worddoc.Tables[1]
.Cell(9,6).Range.Text.Trim().ToString()
.Replace(" ","");
sheet.Rows.Cells[15][m]="2000";
sheet.Rows.Cells[16][m]="1∶50000";
sheet.Rows.Cells[17][m]="秘密";
sheet.Rows.Cells[18][m]="實(shí)測";
sheet.Rows.Cells[19][m]="不變";
sheet.Rows.Cells[20][m]=worddoc.Tables[1]
.Cell(20,2).Range.Text.Trim().ToString()
.Replace(" ","");
sheet.Rows.Cells[21][m]=worddoc.Tables[1]
.Cell(23,2).Range.Text.Trim().ToString()
.Replace(" ","");
sheet.Rows.Cells[22][m]=worddoc.Tables[1]
.Cell(23,6).Range.Text.Trim().ToString()
.Replace(" ","");
sheet.Rows.Cells[23][m]="";
sheet.Rows.Cells[24][m]=@textBox2.Text;
sheet.Rows.Cells[25][m]="12100";
sheet.Rows.Cells[26][m]=worddoc.Tables[1]
.Cell(13,3).Range.Text.Trim().ToString()
.Replace(" ","");
sheet.Rows.Cells[27][m]=worddoc.Tables[1]
.Cell(13,5).Range.Text.Trim().ToString()
.Replace(" ","");
sheet.Rows.Cells[28][m]=worddoc.Tables[1]
.Cell(14,3).Range.Text.Trim().ToString()
.Replace(" ","");
sheet.Rows.Cells[29][m]=worddoc.Tables[1]
.Cell(14,5).Range.Text.Trim().ToString()
.Replace(" ","");
sheet.Rows.Cells[30][m]="請選擇..";
sheet.Rows.Cells[31][m]="請選擇..";
sheet.Rows.Cells[32][m]="請選擇..";
sheet.Rows.Cells[33][m]=worddoc.Tables[1]
.Cell(16,3).Range.Text.Trim().ToString()
.Replace(" ","");
sheet.Rows.Cells[34][m]=worddoc.Tables[1]
.Cell(16,5).Range.Text.Trim().ToString()
.Replace(" ","");
sheet.Rows.Cells[35][m]=worddoc.Tables[1]
.Cell(10,2).Range.Text.Trim().ToString()
.Replace(" ","");
sheet.Rows.Cells[36][m]=worddoc.Tables[1]
.Cell(19,3).Range.Text.Trim().ToString()
.Replace(" ","");
sheet.Rows.Cells[2][2]="3219c8ce-979d
-4e20-927c-21e742006fd2";
}
book.Save();
book.Close();
excelapp.Quit();
myconn.Close();
m++;
}
//瀑布
else if(mystring22 == "瀑布")
……
worddoc.Close(ref unknow,ref unknow
,ref unknow);
wordapp.Quit(ref unknow,ref unknow
,ref unknow);
……
MessageBox.Show("完成??!");
1.3程序運(yùn)行界面
程序界面設(shè)計簡單,如圖1所示。運(yùn)行時選擇地名登記表所在文件夾以及地名屬性表,然后填寫行政區(qū)劃,點(diǎn)擊【確認(rèn)】即可運(yùn)行計算。程序界面中增加了類別名稱檢查,通過讀取每一張地名登記表中的類別名稱,判斷是否屬于第二次全國地名普查內(nèi)容與指標(biāo)中的一級、二級、三級類別名稱,如果不屬于則篩選出錯誤類型的地名登記表,確保所有導(dǎo)入到地名屬性表中的屬性都來源于正確類型的地名登記表,進(jìn)而確保了數(shù)據(jù)批量錄入的質(zhì)量。
圖1 程序運(yùn)行界面Fig.1 Program operation interface
云南省第二次全國地名普查數(shù)據(jù)建庫與管理軟件提供了地名屬性表(Excel)導(dǎo)入,并且支持與地名相關(guān)的多媒體數(shù)據(jù)的導(dǎo)入。 Excel屬性數(shù)據(jù)導(dǎo)入操作步驟如下:
第一步,打開菜單數(shù)據(jù)導(dǎo)入→Excel屬性數(shù)據(jù)導(dǎo)入。
第二步,如果用戶沒有Excel模版整理數(shù)據(jù)的話,可以通過該功能下載模版;對于已經(jīng)整理好Excel數(shù)據(jù)的用戶,可以選擇Excel地名屬性數(shù)據(jù)所在的文件夾,點(diǎn)擊【導(dǎo)入】,則可以將數(shù)據(jù)導(dǎo)入到系統(tǒng)中,并且在界面的列表中顯示導(dǎo)入
的數(shù)據(jù),如圖2所示。
圖2 導(dǎo)入數(shù)據(jù)界面Fig.2 Importing data interface
如果通過手動錄入地名登記表到云南省第二次全國地名普查數(shù)據(jù)建庫與管理軟件將是一個復(fù)雜而又繁瑣的工作,利用程序能夠極大地提高工作效率。更重要的是,地名普查意義重大,一旦出現(xiàn)錯誤,影響范圍大,影響時間長。實(shí)踐證明,利用本文所編程序批量導(dǎo)入地名登記表能夠大大降低錄入出錯的可能,確保數(shù)據(jù)的質(zhì)量。
[1]云南省民政廳,江蘇速度信息科技有限公司.云南省第二次全國地名普查數(shù)據(jù)建庫與管理軟件操作手冊[K].江蘇:江蘇速度信息科技有限公司,2015.
[2]第二次全國地名普查領(lǐng)導(dǎo)小組辦公室.第二次全國地名普查實(shí)施方案(國地名普查組發(fā)〔2014〕1號)[Z].北京:第二次全國地名普查領(lǐng)導(dǎo)小組辦公室,2014.
[3]第二次全國地名普查領(lǐng)導(dǎo)小組辦公室.第二次全國地名普查工作規(guī)程(國地名普查組發(fā)〔2014〕3號)[Z].北京:第二次全國地名普查領(lǐng)導(dǎo)小組辦公室,2014.
[4]苑洲云,孔玲華,王海江.淺談上虞地名普查數(shù)據(jù)快速建庫的方法應(yīng)用[J].浙江測繪,2011(1):26-27.
Realization of Batch Input of Place Names Registration Forms in Second National Census of Place Names
CHEN Ping1,GAO Shi-hua1,YANG Hai-guan2,DAI Jin-wen1
(1.Yunnan Institute of Surveying and Mapping Engineering,Kunming Yunnan 650034,China; 2.Yunnan Testing Station of Mapping and Surveying Products,Kunming Yunnan 650034,China)
Along with further development of Second National Census of Place Names,data input of place names registration forms has been basically completed,and how to efficiently and quickly input place names registration forms to place names census data management system has become very important.To this end,this article describes a method of batch inputing place names registration forms to place names property sheet based on C#,and then inputs place names property sheet to place names census data management system at once,which can greatly improve the work efficiency.
census of place names;place names registration form;batch input;C #
2016-05-11
P 208; P 209
A
1007-9394(2016)03-0018-03
陳平(1988~),男,湖南邵陽人,學(xué)士,助理工程師,現(xiàn)主要從事工程測量及地理信息應(yīng)用方面的工作。