导入要素集到SDE数据库的方法以及使用GP工具的许可问题(转载)
轉(zhuǎn)自:http://blog.csdn.net/lk103852503/article/details/7496850
費(fèi)話不說(shuō),先上代碼
???????public?static?void?shpFeatureClassToGeodatabase(string?inputPath,string?sdePath)
??????? {
??????????? ESRI.ArcGIS.ConversionTools.FeatureClassToGeodatabasefeatureClassToGeodatabase =newESRI.ArcGIS.ConversionTools.FeatureClassToGeodatabase();
???????????featureClassToGeodatabase.Output_Geodatabase = sdePath;
???????????featureClassToGeodatabase.Input_Features = inputPath;
???????????featureClassToGeodatabase.Derived_Geodatabase =?"";
????????????Geoprocessorgeoprocessor =newGeoprocessor();
??????????? geoprocessor.OverwriteOutput =?true;
????????????try
??????????? {? ? ? ?
???????????????geoprocessor.Execute(featureClassToGeodatabase,?null);
????????????????string?mess =?null;
????????????????for(int?k = 0; k < geoprocessor.MessageCount;k++)
??????????????? {
??????????????????? mess +=geoprocessor.GetMessage(k) +?"\n";
??????????????? }
????????????????MessageBox.Show(mess);
??????????? }
????????????catch(Exception?ex)
??????????? {
????????????????stringmess =?null;
????????????????for(int?k = 0; k < geoprocessor.MessageCount;k++)
??????????????? {
????????? ??????????mess += geoprocessor.GetMessage(k) +?"\n";
??????????????? }
??????????? }
??????? }
?此函數(shù)的作用是將要素集導(dǎo)入數(shù)據(jù)庫(kù)中,這里主要使用了FeatureClassToGeodatabase類,這是一個(gè)將要素集導(dǎo)入數(shù)據(jù)庫(kù)的類,這個(gè)數(shù)據(jù)庫(kù)不僅僅是SDE數(shù)據(jù)庫(kù),還包括personal geodatabase和 file geodatabase,導(dǎo)入不同的數(shù)據(jù)庫(kù)時(shí),參數(shù)寫法不同。導(dǎo)入SDE數(shù)據(jù)庫(kù),這樣調(diào)用該函數(shù):
string shpPath=@"E:\Data\TestData\streetPoint.shp";
stringsdePath = @"C:\Users\Administrator\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\Connectionto localhost.sde";
?//stringsdePath = @"E:\Data\TestData\New File Geodatabase.gdb";? ? ?
??shpFeatureClassToGeodatabase(shpPath,sdePath);
要注意的關(guān)鍵問(wèn)題:
1.?????數(shù)據(jù)庫(kù)路徑參數(shù)的寫法
sdePath這個(gè)參數(shù)的寫法十分關(guān)鍵,它實(shí)際指向的是SDE數(shù)據(jù)庫(kù)連接文件,這個(gè)文件是在Catolog中連接數(shù)據(jù)庫(kù)時(shí)自動(dòng)生成的,當(dāng)然也可以用代碼來(lái)創(chuàng)建SDE數(shù)據(jù)庫(kù)連接文件,并以此來(lái)連接數(shù)據(jù)庫(kù),方法如下:
????????????IPropertySetpProSet =newPropertySet();
????????????try
??????????? {
??????????????? pProSet.SetProperty("Server","EGOVA-Likun");
??????????????? pProSet.SetProperty("Instance","5152");
??????????????? pProSet.SetProperty("Database","cgdb");
??????????????? pProSet.SetProperty("user","sde");
??????????????? pProSet.SetProperty("password","sde");
??????????????? pProSet.SetProperty("version","SDE.DEFAULT");
??????????? }
?
????????????catch(Exception?ex)
???????????{
????????????????stringmsg = ex.Message;
???????????? }
????????string?path =@"C:\test";
????????????string?sdeName =@"test.sde";
????????????string?sdePath = path +"\\"?+ sdeName;
????????????if?(File.Exists(sdePath))
????????????{
????????????????File.Delete(sdePath);
????????????}
?
IWorkspaceFactory?workspaceFactory =newSdeWorkspaceFactoryClass();
??IWorkspaceName?workspaceName = workspaceFactory.Create(path, sdeName,pProSet, 0);
?
2.??????許可問(wèn)題
當(dāng)做好以上這些后,可能會(huì)發(fā)現(xiàn)導(dǎo)入數(shù)據(jù)不成功,錯(cuò)誤提示如下:
ERROR 00210:Cannot create output
這里是提示不能創(chuàng)建輸出,此時(shí),如果在此SDE數(shù)據(jù)庫(kù)中做其它的操作如創(chuàng)建、刪除、修改時(shí),提示這樣的錯(cuò)誤:The application is not licensed to create or modify schema for thistype of data,那么可以確定這是許可問(wèn)題。解決方法如下:
打開License屬性,在Products欄中勾選上ArcGIS Engine Enterprise Geodatabase,在Extension一欄中勾選Data Interoperability,這樣的做的目的是要獲取產(chǎn)品版本的許可以及擴(kuò)展模塊的許可,千萬(wàn)要注意的是在Products一欄中勾選對(duì)應(yīng)的產(chǎn)品許可即可,不要多選。
如果用代碼來(lái)設(shè)置許可,方法如下(Java代碼):
com.esri.arcgis.system.AoInitializeao =new?com.esri.arcgis.system.AoInitialize();
???????????if(ao.isProductCodeAvailable(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB) == com.esri.arcgis.system.esriLicenseStatus.esriLicenseAvailable)
???????????ao.initialize(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB);
???????ao.checkOutExtension(com.esri.arcgis.system.esriLicenseExtensionCode.esriLicenseExtensionCodeDataInteroperability);
總結(jié):
關(guān)于許可的問(wèn)題,在使用其它的GP工具時(shí)也常會(huì)遇到,因此,當(dāng)你發(fā)現(xiàn)所有的參數(shù)都設(shè)置無(wú)誤而執(zhí)行卻不能成功的詭異問(wèn)題時(shí),就要檢查下是不是許可在做怪了。
總結(jié)
以上是生活随笔為你收集整理的导入要素集到SDE数据库的方法以及使用GP工具的许可问题(转载)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 安装Apache2.4.23
- 下一篇: ibatis实现1对多