How to implement Arcobjects IbufferconstructionProperties interface to create partial Buffer one side[left/right]? Please provide a code snippet.
Asked
Active
Viewed 549 times
1 Answers
2
I put together a quick C# example but it should be easy to convert. Let me know if you need help. More info on the IBufferConstructionProperties Interface can be found here.
private void DoBuffer()
{
IMxDocument mxDoc = m_application.Document as IMxDocument;
IMap map = mxDoc.FocusMap;
IGraphicsContainer graphicsContainer = (ESRI.ArcGIS.Carto.IGraphicsContainer)map;
MapSelection featSelection = map.FeatureSelection as MapSelection;
IGeometryCollection originalGeometryBag;
IEnumGeometry originalGeometryEnum;
IGeometryCollection outBufferedGeometryCol;
object Missing = Type.Missing;
IEnumGeometry resultingGeometries;
IGeometry resultGeo = null;
IElement element = null;
IRgbColor rgbColor;
ISimpleFillSymbol simpleFillSymbol = new ESRI.ArcGIS.Display.SimpleFillSymbolClass();
IFillShapeElement fillShapeElement;
// Set our buffer properties.
// * The BufferConstruction.ConstructBuffers() and BufferConstruction.ConstructBuffersByDistances()
// methods make use of the these properties. The BufferConstruction.Buffer() method does not.
IBufferConstructionProperties bcp = new BufferConstructionClass();
bcp.SideOption = esriBufferConstructionSideEnum.esriBufferLeft;
bcp.EndOption = esriBufferConstructionEndEnum.esriBufferFlat;
IBufferConstruction bc = bcp as BufferConstruction; // object that will do the actual buffer
// Resulting Polygon buffer elements (this could be changed to output to a polygon feature class)
rgbColor = new ESRI.ArcGIS.Display.RgbColorClass();
rgbColor.Red = 255;
simpleFillSymbol.Color = rgbColor;
simpleFillSymbol.Style = ESRI.ArcGIS.Display.esriSimpleFillStyle.esriSFSForwardDiagonal;
// Buffer selected features
if (featSelection != null && map.SelectionCount > 0)
{
originalGeometryBag = new GeometryBagClass();
// Get our original geometries to buffer
IFeature feat = featSelection.Next();
while (feat != null)
{
originalGeometryBag.AddGeometry(feat.ShapeCopy, Missing, Missing);
feat = featSelection.Next();
}
// Get the resulting buffered geometries and draw them in the map
originalGeometryEnum = originalGeometryBag as IEnumGeometry;
if (originalGeometryEnum != null)
{
outBufferedGeometryCol = new GeometryBagClass();
bc.ConstructBuffers(originalGeometryEnum, 50,outBufferedGeometryCol);
if (outBufferedGeometryCol != null)
{
resultingGeometries = outBufferedGeometryCol as IEnumGeometry;
if (resultingGeometries != null)
resultGeo = resultingGeometries.Next();
while (resultGeo != null)
{
fillShapeElement = new ESRI.ArcGIS.Carto.PolygonElementClass();
fillShapeElement.Symbol = simpleFillSymbol;
element = (ESRI.ArcGIS.Carto.IElement)fillShapeElement; // Explicit Cast
element.Geometry = resultGeo;
graphicsContainer.AddElement(element, 0);
resultGeo = resultingGeometries.Next();
}
}
}
}
// Refresh the map to see the results
mxDoc.ActiveView.Refresh();
}

Tim Sexton
- 188
- 8