arcengine 连接sde,并对sde内数据进行管理(增删改)

1、连接sde,用的是连接文件,怎么创建连接文件,arcgis 工具箱,

如果service参数使用的默认的端口号5151,则必须在创建连接文件之前必须创建和开启sde服务,而如果使用sde:sqlserver:ip地址或计算机名,则不需要创建和开启服务。

location:自己选文件夹路径;

filename:自己填名字

server:192.168.106.33

service:sde:sqlserver:192.168.106.33;

database:数据库名称;

username:用户名

password:密码

arcengine 连接sde,并对sde内数据进行管理(增删改)_第1张图片 图三

 private IFeatureClass GetWrokspace()
        {
            string connectionString = @"D:\123\sde1.sde";
            Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory");
            IWorkspaceFactory2 workspaceFactory2 = (IWorkspaceFactory2)Activator.CreateInstance(factoryType);
            IWorkspace pworkspace = workspaceFactory2.OpenFromFile(connectionString, 1);
            pFeaWS = pworkspace as IFeatureWorkspace;
            pFeatureClas = pFeaWS.OpenFeatureClass("sde.SDE.testPoint");
            IFeatureLayer pFLr = new FeatureLayerClass();
            pFLr.FeatureClass = pFeatureClas;
            axMapControl1.AddLayer(pFLr as ILayer);


            //deleteFeature(pFeatureClas, pFeaWS);


            return pFeatureClas;
        }


   private void deleteFeature(IFeatureClass pFeatureClas, IFeatureWorkspace featureWorkspace)
        {
            //IQueryFilter pQF = new QueryFilterClass();
            //pQF.WhereClause = "点号 ='N182'";
            //IFeatureCursor pFeatureCursor = featureclass.Update(pQF, false);
            //IFeature pFeature = pFeatureCursor.NextFeature();
            //if (pFeature == null) return;
            //while (pFeature != null)
            //{
            //    pFeatureCursor.DeleteFeature();
            //    pFeature = pFeatureCursor.NextFeature();
            //}


            IWorkspaceEdit edit = featureWorkspace as IWorkspaceEdit;
            edit.StartEditing(true);
            edit.StartEditOperation();


            IQueryFilter queryFilter = new QueryFilterClass
            {
                WhereClause = "点号 = 'N181'"
            };


            // Create a ComReleaser for cursor management.
           
                // Create and manage a cursor.
            IFeatureCursor searchCursor = pFeatureClas.Search(queryFilter, false);
              


                // Delete the retrieved features.
                IFeature feature = null;
                while ((feature = searchCursor.NextFeature()) != null)
                {
                    feature.Delete();
                }
              edit.StopEditOperation();
              edit.StopEditing(true);




              axMapControl1.Refresh();
 
        }


 private void addFeature(IFeatureClass pFeatureClas, IFeatureWorkspace featureWorkspace)
        {
            IWorkspaceEdit edit = featureWorkspace as IWorkspaceEdit;
            edit.StartEditing(true);
            edit.StartEditOperation();




            IFeatureBuffer featureBuffer = pFeatureClas.CreateFeatureBuffer();
            IFeatureCursor featureCursor = pFeatureClas.Insert(true);


            featureBuffer.set_Value(1, "haha");
            IPoint point = new PointClass();
            point.X=116.027;
            point.Y =39.678;
            featureBuffer.Shape = point;


            featureCursor.InsertFeature(featureBuffer);


            edit.StopEditOperation();
            edit.StopEditing(true);


            axMapControl1.Refresh();
 
        }

 private void updateFeature(IFeatureClass pFeatureClas, IFeatureWorkspace featureWorkspace)
        {
            IWorkspaceEdit edit = featureWorkspace as IWorkspaceEdit;
            edit.StartEditing(true);
            edit.StartEditOperation();


            IQueryFilter pQF = new QueryFilterClass();
            pQF.WhereClause = "点号 ='N204'";
            IFeatureCursor pFeatureCursor = pFeatureClas.Update(pQF, false);
            int index = pFeatureClas.FindField("点名");
            IFeature pFeature = pFeatureCursor.NextFeature();
            if (pFeature == null) return;
            while (pFeature != null)
            {
                pFeature.set_Value(index, "哈哈222");


                pFeatureCursor.UpdateFeature(pFeature);


                pFeature = pFeatureCursor.NextFeature();
            }




            edit.StopEditOperation();
            edit.StopEditing(true);




            axMapControl1.Refresh();
 
        }

你可能感兴趣的:(arcengine 连接sde,并对sde内数据进行管理(增删改))