Solved! Go to Solution.
Thanks for the help, Tim. I implemented your suggestions. The routine is still creating features with empty geometries. Any idea why it would add a row to the table but not add take the geometry? The shape field does show 'polygon' but when I select or try to zoom to one onf the new features - nothing.
Dim pMap As IMap = My.ArcMap.Document.FocusMap Dim pFLayer As IFeatureLayer = pMap.Layer(0) Dim pFC As IFeatureClass = pFLayer.FeatureClass Dim pCursor As IFeatureCursor = pFC.Search(Nothing, False) Dim pFeature As IFeature = pCursor.NextFeature Dim pEnv As IEnvelope Dim pPoly As IPointCollection Dim uid As ESRI.ArcGIS.esriSystem.UID uid = New ESRI.ArcGIS.esriSystem.UIDClass() uid.Value = "esriEditor.Editor" Dim editor As IEditor editor = CType(My.ArcMap.Application.FindExtensionByCLSID(uid), IEditor) Dim pDS As IDataset = pFLayer.FeatureClass Dim pWS As IWorkspace = pDS.Workspace 'Check to see if a workspace is already being edited. If editor.EditState = esriEditState.esriStateNotEditing Then editor.StartEditing(pWS) End If Do Until pFeature Is Nothing ' Expand the envelope pEnv = pFeature.Shape.Envelope pEnv.Expand(100, 100, False) ' Create the vertices Dim LL As New Point LL.PutCoords(pEnv.XMin, pEnv.YMin) Dim LR As New Point LR.PutCoords(pEnv.XMax, pEnv.YMin) Dim UR As New Point UR.PutCoords(pEnv.XMax, pEnv.YMax) Dim UL As New Point UL.PutCoords(pEnv.XMin, pEnv.YMax) ' Add vertices to the polygon and close the loop pPoly = New Polygon pPoly.AddPoint(LL) pPoly.AddPoint(LR) pPoly.AddPoint(UR) pPoly.AddPoint(UL) pPoly.AddPoint(LL) ' Assign properties to the new feature Dim pNewFeat As IFeature = pFC.CreateFeature pNewFeat.Shape = pPoly pNewFeat.Value(3) = pFeature.Value(3) pNewFeat.Store() pFeature = pCursor.NextFeature Loop editor.StopEditing(True) My.ArcMap.Document.ActiveView.Refresh()
Dim pPoly As IPointCollection
pPoly = New Polygon Dim LL As New Point LL.PutCoords(pEnv.XMin, pEnv.YMin) pPoly.AddPoint(LL) Dim LR As New Point LR.PutCoords(pEnv.XMax, pEnv.YMin) pPoly.AddPoint(LR)
pEnv = pFeature.Shape.Envelope pEnv.Expand(100, 100, False)
ITopologicalOperator topologicalOperator = pFeature.Shape as ITopologicalOperator; IPolygon pPoly = topologicalOperator.Buffer(100) as IPolygon; pNewFeat.Shape = pPoly;
If you are just adding a buffer to the existing polygon then you can use the below code. You may have to convert it to VB though.ITopologicalOperator topologicalOperator = pFeature.Shape as ITopologicalOperator; IPolygon pPoly = topologicalOperator.Buffer(100) as IPolygon; pNewFeat.Shape = pPoly;
Thanks for the help, Tim. I implemented your suggestions. The routine is still creating features with empty geometries. Any idea why it would add a row to the table but not add take the geometry? The shape field does show 'polygon' but when I select or try to zoom to one onf the new features - nothing.
Dim pMap As IMap = My.ArcMap.Document.FocusMap Dim pFLayer As IFeatureLayer = pMap.Layer(0) Dim pFC As IFeatureClass = pFLayer.FeatureClass Dim pCursor As IFeatureCursor = pFC.Search(Nothing, False) Dim pFeature As IFeature = pCursor.NextFeature Dim pEnv As IEnvelope Dim pPoly As IPointCollection Dim uid As ESRI.ArcGIS.esriSystem.UID uid = New ESRI.ArcGIS.esriSystem.UIDClass() uid.Value = "esriEditor.Editor" Dim editor As IEditor editor = CType(My.ArcMap.Application.FindExtensionByCLSID(uid), IEditor) Dim pDS As IDataset = pFLayer.FeatureClass Dim pWS As IWorkspace = pDS.Workspace 'Check to see if a workspace is already being edited. If editor.EditState = esriEditState.esriStateNotEditing Then editor.StartEditing(pWS) End If Do Until pFeature Is Nothing ' Expand the envelope pEnv = pFeature.Shape.Envelope pEnv.Expand(100, 100, False) ' Create the vertices Dim LL As New Point LL.PutCoords(pEnv.XMin, pEnv.YMin) Dim LR As New Point LR.PutCoords(pEnv.XMax, pEnv.YMin) Dim UR As New Point UR.PutCoords(pEnv.XMax, pEnv.YMax) Dim UL As New Point UL.PutCoords(pEnv.XMin, pEnv.YMax) ' Add vertices to the polygon and close the loop pPoly = New Polygon pPoly.AddPoint(LL) pPoly.AddPoint(LR) pPoly.AddPoint(UR) pPoly.AddPoint(UL) pPoly.AddPoint(LL) ' Assign properties to the new feature Dim pNewFeat As IFeature = pFC.CreateFeature pNewFeat.Shape = pPoly pNewFeat.Value(3) = pFeature.Value(3) pNewFeat.Store() pFeature = pCursor.NextFeature Loop editor.StopEditing(True) My.ArcMap.Document.ActiveView.Refresh()
Maybe you need to close the polygon by adding the first point to the end of the point collection. This code worked for me.