1

如何实现 Arcobjects IbufferconstructionProperties 接口创建部分 Buffer 一侧[左/右]?请提供代码片段。

4

1 回答 1

2

我整理了一个快速的 C# 示例,但它应该很容易转换。如果您需要帮助,请告诉我。可以在此处找到有关 IBufferConstructionProperties 接口的更多信息。

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();
    }
于 2014-07-09T15:25:26.570 回答