导入要素集到SDE数据库的方法以及使用GP工具的许可问题(转载)

转自:http://blog.csdn.net/lk103852503/article/details/7496850

费话不说,先上代码

       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";

                }

            }

        }

 此函数的作用是将要素集导入数据库中,这里主要使用了FeatureClassToGeodatabase类,这是一个将要素集导入数据库的类,这个数据库不仅仅是SDE数据库,还包括personal geodatabase和 file geodatabase,导入不同的数据库时,参数写法不同。导入SDE数据库,这样调用该函数:

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);

要注意的关键问题:

1.     数据库路径参数的写法

sdePath这个参数的写法十分关键,它实际指向的是SDE数据库连接文件,这个文件是在Catolog中连接数据库时自动生成的,当然也可以用代码来创建SDE数据库连接文件,并以此来连接数据库,方法如下:

            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.      许可问题

当做好以上这些后,可能会发现导入数据不成功,错误提示如下:

ERROR 00210:Cannot create output

这里是提示不能创建输出,此时,如果在此SDE数据库中做其它的操作如创建、删除、修改时,提示这样的错误:The application is not licensed to create or modify schema for thistype of data,那么可以确定这是许可问题。解决方法如下:

打开License属性,在Products栏中勾选上ArcGIS Engine Enterprise Geodatabase,在Extension一栏中勾选Data Interoperability,这样的做的目的是要获取产品版本的许可以及扩展模块的许可,千万要注意的是在Products一栏中勾选对应的产品许可即可,不要多选。

如果用代码来设置许可,方法如下(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);

总结:

关于许可的问题,在使用其它的GP工具时也常会遇到,因此,当你发现所有的参数都设置无误而执行却不能成功的诡异问题时,就要检查下是不是许可在做怪了。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值