shp导入SDE以及遇到的问题

在将shp文件导入SDE的时候一直报错,说没有权限修改此模块。通过google搜索,发现是权限的问题,通过设置licensecontrol的属性解决了这个问题:

勾选 ArcGIS Engine Enterprise GeoDatabase即可,同时在初始化里加入以下代码就可以实现向SDE导入数据

IAoInitialize initAO = new AoInitializeClass();
            initAO.Initialize((esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB));
目前导出只实现了单个要素类的导入,即右键单击选中导出要素类功能,下一步实现多要素和栅格数据的导入。单个要素类导入代码:

 public void FeatureClassToFeatureClass (IFeatureClass pInputFeatureClass,IWorkspace pOutWorkspace)
        {
             if(pInputFeatureClass == null || pOutWorkspace == null)
             {
                 return;
             } 
             else
             {
                 //输入要素类参数设置
                 IFeatureClassName pInputFeatureclassName = new FeatureClassNameClass();
                 IDataset pInputDataSet = pInputFeatureClass as IDataset;
                 pInputFeatureclassName = pInputDataSet.FullName as IFeatureClassName;

                 //设置输出要素类参数
                 string featureclassName = pInputFeatureClass.AliasName.Trim().Substring(pInputFeatureClass.AliasName.Trim().IndexOf(".") + 1);
                 IDataset pOutDataset = pOutWorkspace as IDataset;
                 
                 IFeatureClassName pOutFeatureClassName = new FeatureClassNameClass();
                 IDatasetName pOutDatasetName = pOutFeatureClassName as IDatasetName;
                 pOutDatasetName.WorkspaceName = pOutDataset.FullName as IWorkspaceName;
                 pOutDatasetName.Name = featureclassName;

                 //删除重名的要素类
                 IWorkspace2 pOutWorkspace2 = (IWorkspace2)pOutWorkspace;
                 if(pOutWorkspace2.get_NameExists(esriDatasetType.esriDTFeatureClass,featureclassName))
                 {
                     IFeatureWorkspace pFWS = pOutWorkspace as IFeatureWorkspace;
                     IFeatureClass pFeatureClass = pFWS.OpenFeatureClass(featureclassName);
                     IDataset pDataset = pFeatureClass as IDataset;
                     pDataset.Delete();

                 }
         
                 //通过fieldCheck检查字段的合法性,为输出SHP获得字段集合 
                 IFields pInputFields=new FieldsClass();
                 IFields pOutFields=new FieldsClass(); 
                 IFieldChecker pFieldChecker = new FieldCheckerClass();
                 IEnumFieldError pError;
                 pInputFields = pInputFeatureClass.Fields;

                 pFieldChecker.Validate(pInputFields,out pError,out pOutFields);

                 //获取几何字段
                 IField geoField = new FieldClass();
                 for(int i = 0;i < pOutFields.FieldCount;i++)
                 {
                     IField pField = pOutFields.get_Field(i);
                     if(pField.Type == esriFieldType.esriFieldTypeOID)
                     {
                         IFieldEdit pFieldEdit = pField as IFieldEdit;
                         pFieldEdit.Name_2 = pField.AliasName;
                     }
                     if(pField.Type == esriFieldType.esriFieldTypeGeometry)
                     {
                         geoField = pField;
                         break;
                     }
                 }
                 IGeometryDef geometryDef = geoField.GeometryDef;

                 IFeatureDataConverter featureDataConverter = new FeatureDataConverterClass();
                 if(pOutWorkspace.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace)
                 {
                     featureDataConverter.ConvertFeatureClass(pInputFeatureclassName,null,null,pOutFeatureClassName,geometryDef,
                     pOutFields,"",1000,0);
                 }
                 else
                 {
                     IFeatureDatasetName pOutFeatDSName = new FeatureDatasetNameClass();
                     IDatasetName pDSname = pOutFeatDSName as IDatasetName;
                     pDSname.WorkspaceName = pOutDataset.FullName as IWorkspaceName;
                     pDSname.Name = pInputFeatureClass.FeatureDataset.Name;
                     featureDataConverter.ConvertFeatureClass(pInputFeatureclassName,null,pOutFeatDSName,pOutFeatureClassName,geometryDef,
                     pOutFields,"",1000,0);
                 }
             }
        }

posted @ 2014-04-16 14:49  奔跑的鸡丝  阅读(645)  评论(0编辑  收藏  举报