C#+ArcEngine 新建点元素

IFeatureLayer pFLayer = mapMain.get_Layer(0) as IFeatureLayer;
                IFeatureClass pFC = pFLayer.FeatureClass;

                //类型不对停止编辑
                if (pFC.ShapeType != ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint) { return; }
                //建立编辑空间
                IDataset pDataset = pFC as IDataset;
                IWorkspace pWorkspace = pDataset.Workspace;
                IWorkspaceEdit pWorkspaceEdit = pWorkspace as IWorkspaceEdit;

                //开始编辑
                pWorkspaceEdit.StartEditing(false);
                pWorkspaceEdit.StartEditOperation();

                //创建点
                ESRI.ArcGIS.Geometry.IPoint point = new ESRI.ArcGIS.Geometry.PointClass();
                point.X = e.mapX;
                point.Y = e.mapY;

                IFeature pFeature = pFC.CreateFeature();

                pFeature.Shape = point;//设置新建的元素为点元素

               //对元素设置属性值: pFeature.set_Value(pFeature.Fields.FindField("Name"), name);

                pFeature.Store();

                //停止编辑
                pWorkspaceEdit.StopEditOperation();
                pWorkspaceEdit.StopEditing(true);
                mapMain.ActiveView.Refresh();//更新视窗

posted @ 2010-05-17 14:24  孙老板  阅读(1588)  评论(0编辑  收藏  举报