Dim mPoint As IPoint
Dim m_pMpt As IMultipoint
Dim m_pPtColl As IPointCollection
Dim pPolygon As Polygon
Dim pWorkspaceFactory As IWorkspaceFactory
Dim pWorkspaceEdit As IWorkspaceEdit
Dim pFeatureLayer As IFeatureLayer
Dim pDataSet As IDataset
Dim pFeature As IFeature
'pGeoms_Polyline = New Collection
mPoint = New Point
m_pMpt = New Multipoint
m_pPtColl = m_pMpt
'第一个点
mPoint.X = AxMapControl1.Bounds.X
mPoint.Y = AxMapControl1.Bounds.Y
m_pPtColl.AddPoint(mPoint)
'第二个点
mPoint.X = AxMapControl1.Bounds.X + AxMapControl1.Bounds.Width
mPoint.Y = AxMapControl1.Bounds.Y
m_pPtColl.AddPoint(mPoint)
'第三个点
mPoint.X = AxMapControl1.Bounds.X + AxMapControl1.Bounds.Width
mPoint.Y = AxMapControl1.Bounds.Y + AxMapControl1.Bounds.Height
m_pPtColl.AddPoint(mPoint)
'第四个点
mPoint.X = AxMapControl1.Bounds.X
mPoint.Y = AxMapControl1.Bounds.Y + AxMapControl1.Bounds.Height
m_pPtColl.AddPoint(mPoint)
'第五个点
mPoint.X = AxMapControl1.Bounds.X
mPoint.Y = AxMapControl1.Bounds.Y
m_pPtColl.AddPoint(mPoint)
pPolygon = New Polygon
pPolygon.AddPointCollection(m_pPtColl)
'得到0层的FeatureClass
pWorkspaceFactory = New ShapefileWorkspaceFactory
pFeatureLayer = AxMapControl1.ActiveView.FocusMap.Layer(0)
'创建一个编辑工作区
pDataSet = pFeatureLayer.FeatureClass
MsgBox(pDataSet.Workspace.PathName)
pWorkspaceEdit = pWorkspaceFactory.OpenFromFile(pDataSet.Workspace.PathName, 0)
'开始编辑
pWorkspaceEdit.StartEditOperation()
pWorkspaceEdit.StartEditing(True)
'将创建的Polygon,加到Polygon层上,新建的Feature中
pFeature = pFeatureLayer.FeatureClass.CreateFeature
pFeature.Shape = pPolygon
'保存Feature
pFeature.Store()
AxMapControl1.ActiveView.Refresh()
'停止编辑
pWorkspaceEdit.StopEditOperation()
pWorkspaceEdit.StopEditing(True)
3 个解决方案
#1
pPolygon = New Polygon
pPolygon.AddPointCollection(m_pPtColl)
这里有问题,改为:
pPolygon = New Polygon
pPolygon=m_pPtColl
pPolygon.AddPointCollection(m_pPtColl)
这里有问题,改为:
pPolygon = New Polygon
pPolygon=m_pPtColl
#2
添加图元没有问题,通过ARCGIS查看TABLE中有记录,只是在图层中什么也看不见。而且修改为pPolygon=m_pPtColl后运行时会报错,提示“No support for this geometry type.”
#3
不好意思,忘记写m_pPtColl=New Polygon了,另外你的point有问题,因为你只是New了一个point,所以实际上你加的五个点都是指向最后一个点,代码改一下就可以了:
Dim mPoint As IPoint
Dim m_pPtColl As IPointCollection
Dim pPolygon As Polygon
Dim pWorkspaceFactory As IWorkspaceFactory
Dim pWorkspaceEdit As IWorkspaceEdit
Dim pFeatureLayer As IFeatureLayer
Dim pDataSet As IDataset
Dim pFeature As IFeature
'pGeoms_Polyline = New Collection
m_pPtColl = New Polygon
'第一个点
mPoint = New Point
mPoint.X = AxMapControl1.Bounds.X
mPoint.Y = AxMapControl1.Bounds.Y
m_pPtColl.AddPoint(mPoint)
'第二个点
mPoint = New Point
mPoint.X = AxMapControl1.Bounds.X + AxMapControl1.Bounds.Width
mPoint.Y = AxMapControl1.Bounds.Y
m_pPtColl.AddPoint(mPoint)
'第三个点
mPoint = New Point
mPoint.X = AxMapControl1.Bounds.X + AxMapControl1.Bounds.Width
mPoint.Y = AxMapControl1.Bounds.Y + AxMapControl1.Bounds.Height
m_pPtColl.AddPoint(mPoint)
'第四个点
mPoint = New Point
mPoint.X = AxMapControl1.Bounds.X
mPoint.Y = AxMapControl1.Bounds.Y + AxMapControl1.Bounds.Height
m_pPtColl.AddPoint(mPoint)
'第五个点
mPoint = New Point
mPoint.X = AxMapControl1.Bounds.X
mPoint.Y = AxMapControl1.Bounds.Y
m_pPtColl.AddPoint(mPoint)
pPolygon = m_pPtColl
'得到0层的FeatureClass
pWorkspaceFactory = New ShapefileWorkspaceFactory
pFeatureLayer = AxMapControl1.ActiveView.FocusMap.Layer(0)
'创建一个编辑工作区
pDataSet = pFeatureLayer.FeatureClass
MsgBox(pDataSet.Workspace.PathName)
pWorkspaceEdit = pWorkspaceFactory.OpenFromFile(pDataSet.Workspace.PathName, 0)
'开始编辑
pWorkspaceEdit.StartEditOperation()
pWorkspaceEdit.StartEditing(True)
'将创建的Polygon,加到Polygon层上,新建的Feature中
pFeature = pFeatureLayer.FeatureClass.CreateFeature
pFeature.Shape = pPolygon
'保存Feature
pFeature.Store()
'停止编辑
pWorkspaceEdit.StopEditOperation()
pWorkspaceEdit.StopEditing(True)
AxMapControl1.ActiveView.Refresh()
Dim mPoint As IPoint
Dim m_pPtColl As IPointCollection
Dim pPolygon As Polygon
Dim pWorkspaceFactory As IWorkspaceFactory
Dim pWorkspaceEdit As IWorkspaceEdit
Dim pFeatureLayer As IFeatureLayer
Dim pDataSet As IDataset
Dim pFeature As IFeature
'pGeoms_Polyline = New Collection
m_pPtColl = New Polygon
'第一个点
mPoint = New Point
mPoint.X = AxMapControl1.Bounds.X
mPoint.Y = AxMapControl1.Bounds.Y
m_pPtColl.AddPoint(mPoint)
'第二个点
mPoint = New Point
mPoint.X = AxMapControl1.Bounds.X + AxMapControl1.Bounds.Width
mPoint.Y = AxMapControl1.Bounds.Y
m_pPtColl.AddPoint(mPoint)
'第三个点
mPoint = New Point
mPoint.X = AxMapControl1.Bounds.X + AxMapControl1.Bounds.Width
mPoint.Y = AxMapControl1.Bounds.Y + AxMapControl1.Bounds.Height
m_pPtColl.AddPoint(mPoint)
'第四个点
mPoint = New Point
mPoint.X = AxMapControl1.Bounds.X
mPoint.Y = AxMapControl1.Bounds.Y + AxMapControl1.Bounds.Height
m_pPtColl.AddPoint(mPoint)
'第五个点
mPoint = New Point
mPoint.X = AxMapControl1.Bounds.X
mPoint.Y = AxMapControl1.Bounds.Y
m_pPtColl.AddPoint(mPoint)
pPolygon = m_pPtColl
'得到0层的FeatureClass
pWorkspaceFactory = New ShapefileWorkspaceFactory
pFeatureLayer = AxMapControl1.ActiveView.FocusMap.Layer(0)
'创建一个编辑工作区
pDataSet = pFeatureLayer.FeatureClass
MsgBox(pDataSet.Workspace.PathName)
pWorkspaceEdit = pWorkspaceFactory.OpenFromFile(pDataSet.Workspace.PathName, 0)
'开始编辑
pWorkspaceEdit.StartEditOperation()
pWorkspaceEdit.StartEditing(True)
'将创建的Polygon,加到Polygon层上,新建的Feature中
pFeature = pFeatureLayer.FeatureClass.CreateFeature
pFeature.Shape = pPolygon
'保存Feature
pFeature.Store()
'停止编辑
pWorkspaceEdit.StopEditOperation()
pWorkspaceEdit.StopEditing(True)
AxMapControl1.ActiveView.Refresh()
#1
pPolygon = New Polygon
pPolygon.AddPointCollection(m_pPtColl)
这里有问题,改为:
pPolygon = New Polygon
pPolygon=m_pPtColl
pPolygon.AddPointCollection(m_pPtColl)
这里有问题,改为:
pPolygon = New Polygon
pPolygon=m_pPtColl
#2
添加图元没有问题,通过ARCGIS查看TABLE中有记录,只是在图层中什么也看不见。而且修改为pPolygon=m_pPtColl后运行时会报错,提示“No support for this geometry type.”
#3
不好意思,忘记写m_pPtColl=New Polygon了,另外你的point有问题,因为你只是New了一个point,所以实际上你加的五个点都是指向最后一个点,代码改一下就可以了:
Dim mPoint As IPoint
Dim m_pPtColl As IPointCollection
Dim pPolygon As Polygon
Dim pWorkspaceFactory As IWorkspaceFactory
Dim pWorkspaceEdit As IWorkspaceEdit
Dim pFeatureLayer As IFeatureLayer
Dim pDataSet As IDataset
Dim pFeature As IFeature
'pGeoms_Polyline = New Collection
m_pPtColl = New Polygon
'第一个点
mPoint = New Point
mPoint.X = AxMapControl1.Bounds.X
mPoint.Y = AxMapControl1.Bounds.Y
m_pPtColl.AddPoint(mPoint)
'第二个点
mPoint = New Point
mPoint.X = AxMapControl1.Bounds.X + AxMapControl1.Bounds.Width
mPoint.Y = AxMapControl1.Bounds.Y
m_pPtColl.AddPoint(mPoint)
'第三个点
mPoint = New Point
mPoint.X = AxMapControl1.Bounds.X + AxMapControl1.Bounds.Width
mPoint.Y = AxMapControl1.Bounds.Y + AxMapControl1.Bounds.Height
m_pPtColl.AddPoint(mPoint)
'第四个点
mPoint = New Point
mPoint.X = AxMapControl1.Bounds.X
mPoint.Y = AxMapControl1.Bounds.Y + AxMapControl1.Bounds.Height
m_pPtColl.AddPoint(mPoint)
'第五个点
mPoint = New Point
mPoint.X = AxMapControl1.Bounds.X
mPoint.Y = AxMapControl1.Bounds.Y
m_pPtColl.AddPoint(mPoint)
pPolygon = m_pPtColl
'得到0层的FeatureClass
pWorkspaceFactory = New ShapefileWorkspaceFactory
pFeatureLayer = AxMapControl1.ActiveView.FocusMap.Layer(0)
'创建一个编辑工作区
pDataSet = pFeatureLayer.FeatureClass
MsgBox(pDataSet.Workspace.PathName)
pWorkspaceEdit = pWorkspaceFactory.OpenFromFile(pDataSet.Workspace.PathName, 0)
'开始编辑
pWorkspaceEdit.StartEditOperation()
pWorkspaceEdit.StartEditing(True)
'将创建的Polygon,加到Polygon层上,新建的Feature中
pFeature = pFeatureLayer.FeatureClass.CreateFeature
pFeature.Shape = pPolygon
'保存Feature
pFeature.Store()
'停止编辑
pWorkspaceEdit.StopEditOperation()
pWorkspaceEdit.StopEditing(True)
AxMapControl1.ActiveView.Refresh()
Dim mPoint As IPoint
Dim m_pPtColl As IPointCollection
Dim pPolygon As Polygon
Dim pWorkspaceFactory As IWorkspaceFactory
Dim pWorkspaceEdit As IWorkspaceEdit
Dim pFeatureLayer As IFeatureLayer
Dim pDataSet As IDataset
Dim pFeature As IFeature
'pGeoms_Polyline = New Collection
m_pPtColl = New Polygon
'第一个点
mPoint = New Point
mPoint.X = AxMapControl1.Bounds.X
mPoint.Y = AxMapControl1.Bounds.Y
m_pPtColl.AddPoint(mPoint)
'第二个点
mPoint = New Point
mPoint.X = AxMapControl1.Bounds.X + AxMapControl1.Bounds.Width
mPoint.Y = AxMapControl1.Bounds.Y
m_pPtColl.AddPoint(mPoint)
'第三个点
mPoint = New Point
mPoint.X = AxMapControl1.Bounds.X + AxMapControl1.Bounds.Width
mPoint.Y = AxMapControl1.Bounds.Y + AxMapControl1.Bounds.Height
m_pPtColl.AddPoint(mPoint)
'第四个点
mPoint = New Point
mPoint.X = AxMapControl1.Bounds.X
mPoint.Y = AxMapControl1.Bounds.Y + AxMapControl1.Bounds.Height
m_pPtColl.AddPoint(mPoint)
'第五个点
mPoint = New Point
mPoint.X = AxMapControl1.Bounds.X
mPoint.Y = AxMapControl1.Bounds.Y
m_pPtColl.AddPoint(mPoint)
pPolygon = m_pPtColl
'得到0层的FeatureClass
pWorkspaceFactory = New ShapefileWorkspaceFactory
pFeatureLayer = AxMapControl1.ActiveView.FocusMap.Layer(0)
'创建一个编辑工作区
pDataSet = pFeatureLayer.FeatureClass
MsgBox(pDataSet.Workspace.PathName)
pWorkspaceEdit = pWorkspaceFactory.OpenFromFile(pDataSet.Workspace.PathName, 0)
'开始编辑
pWorkspaceEdit.StartEditOperation()
pWorkspaceEdit.StartEditing(True)
'将创建的Polygon,加到Polygon层上,新建的Feature中
pFeature = pFeatureLayer.FeatureClass.CreateFeature
pFeature.Shape = pPolygon
'保存Feature
pFeature.Store()
'停止编辑
pWorkspaceEdit.StopEditOperation()
pWorkspaceEdit.StopEditing(True)
AxMapControl1.ActiveView.Refresh()