ILayer ALayer = this.axMapControl1.get_Layer(0);//所要加的层
IFeatureLayer AFeatureLyr = ALayer as IFeatureLayer;//将ILayer转换为IFeaturelayer,为了对图层上的要素进行编辑
IFeatureClass AFeatCls = AFeatureLyr.FeatureClass;//定义一个要素集合,并获取图层的要素集合
IFeatureClassWrite Afr = (IFeatureClassWrite)AFeatCls;//定义一个实现新增要素的接口实例,并该实例作用于当前图层的要素集
IWorkspaceEdit AworkSpace = (AFeatCls as IDataset).Workspace as IWorkspaceEdit;//定义一个工作编辑工作空间,用于开启前图层的编辑状态
IFeature Afrat;//定义一个IFeature实例,用于添加到当前图层上
AworkSpace.StartEditing(true);//开启编辑状态
AworkSpace.StartEditOperation();//开启编辑操作
IPoint Apoint;//定义一个点,用来作为IFeature实例的形状属性,即shape属性
//下面是设置点的坐标和参考系
Apoint = new PointClass();
Apoint.SpatialReference = this.axMapControl1.SpatialReference;
Apoint.X = m_Lon;
Apoint.Y = m_Lat;
//将IPoint设置为IFeature的shape属性时,需要通过中间接口IGeometry转换
IGeometry Apeo;
Apeo = Apoint;
Afrat = AFeatCls.CreateFeature();//实例化IFeature对象, 这样IFeature对象就具有当前图层上要素的字段信息
Afrat.Shape = Apeo;//设置IFeature对象的形状属性
Afrat.set_Value(2, m_Lon);
Afrat.set_Value(3, m_Lat);
Afrat.set_Value(4, m_Pointys);
Afrat.Store();//保存IFeature对象
Afr.WriteFeature(Afrat);//将IFeature对象,添加到当前图层上
AworkSpace.StopEditOperation();//停止编辑操作
AworkSpace.StopEditing(true);//关闭编辑状态,并保存修改
this.axMapControl1.Refresh();//刷新地图
IFeatureLayer AFeatureLyr = ALayer as IFeatureLayer;//将ILayer转换为IFeaturelayer,为了对图层上的要素进行编辑
IFeatureClass AFeatCls = AFeatureLyr.FeatureClass;//定义一个要素集合,并获取图层的要素集合
IFeatureClassWrite Afr = (IFeatureClassWrite)AFeatCls;//定义一个实现新增要素的接口实例,并该实例作用于当前图层的要素集
IWorkspaceEdit AworkSpace = (AFeatCls as IDataset).Workspace as IWorkspaceEdit;//定义一个工作编辑工作空间,用于开启前图层的编辑状态
IFeature Afrat;//定义一个IFeature实例,用于添加到当前图层上
AworkSpace.StartEditing(true);//开启编辑状态
AworkSpace.StartEditOperation();//开启编辑操作
IPoint Apoint;//定义一个点,用来作为IFeature实例的形状属性,即shape属性
//下面是设置点的坐标和参考系
Apoint = new PointClass();
Apoint.SpatialReference = this.axMapControl1.SpatialReference;
Apoint.X = m_Lon;
Apoint.Y = m_Lat;
//将IPoint设置为IFeature的shape属性时,需要通过中间接口IGeometry转换
IGeometry Apeo;
Apeo = Apoint;
Afrat = AFeatCls.CreateFeature();//实例化IFeature对象, 这样IFeature对象就具有当前图层上要素的字段信息
Afrat.Shape = Apeo;//设置IFeature对象的形状属性
Afrat.set_Value(2, m_Lon);
Afrat.set_Value(3, m_Lat);
Afrat.set_Value(4, m_Pointys);
Afrat.Store();//保存IFeature对象
Afr.WriteFeature(Afrat);//将IFeature对象,添加到当前图层上
AworkSpace.StopEditOperation();//停止编辑操作
AworkSpace.StopEditing(true);//关闭编辑状态,并保存修改
this.axMapControl1.Refresh();//刷新地图