| |
Public Function bufferIn(pFeatclass As IFeatureClass, lbuffDist As Long, sName As String, sPath As String) As IFeatureClass
'This function takes a feature class and buffers inwards by a specified distance and then saves it as a new shapefile feature class
'the newly saved feature class is then returned from the function
'dim the ArcVariables:
Dim pFeatCursorBuff As IFeatureCursorBuffer
Dim pFeatCursor As IFeatureCursor
Dim pFeatClassName As IFeatureClassName
Dim pWorkspaceName As IWorkspaceName
Dim pDatasetName As IDatasetName
Dim pBufferProcessParam As IBufferProcessingParameter
'set the info for the output feature class
Set pFeatClassName = New FeatureClassName
Set pDatasetName = pFeatClassName
Set pWorkspaceName = New WorkspaceName
'......first the workspace:
With pWorkspaceName
.PathName = sPath & ".shp"
.WorkspaceFactoryProgID = "esricore.shapefileworkspacefactory.1"
End With
Set pDatasetName.WorkspaceName = pWorkspaceName
'......then the feature class:
With pFeatClassName
.FeatureType = esriFTSimple
.ShapeFieldName = "Shape"
.ShapeType = esriGeometryPolygon
End With
Set pFeatCursor = pFeatclass.Search(Nothing, False)
Set pFeatCursorBuff = New FeatureCursorBuffer
'.....then set the info for the buffer operation:
Set pFeatCursorBuff.FeatureCursor = pFeatCursor
With pFeatCursorBuff
.PolygonBufferType = esriBufferInside
.Units(esriMeters) = esriMeters
.ValueDistance = lbuffDist
End With
'and for the processing parameters:
Set pBufferProcessParam = pFeatCursorBuff
Set pBufferProcessParam.FeatureClass = pFeatclass
With pBufferProcessParam
.AdjustCirclesForProjection = True
.SimplifyShapes = True
.InputHasPolygons = True
.SaveAsGraphics = False
End With
pFeatCursorBuff.buffer pFeatClassName
'now release the variables:
Set pFeatCursorBuff = Nothing
Set pFeatCursor = Nothing
Set pFeatClassName = Nothing
Set pWorkspaceName = Nothing
Set pDatasetName = Nothing
End Function |