public void DrawBuffer() { ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = axMapControl1.ActiveView.ScreenDisplay; IElement pInptLine = new LineElementClass(); object missing = Type.Missing; IFillShapeElement pElem = new CircleElementClass(); ISimpleFillSymbol sysm = new SimpleFillSymbol(); sysm.Style = esriSimpleFillStyle.esriSFSDiagonalCross; sysm.Outline.Width = 20; //Get the IRGBColor interface IRgbColor color = new RgbColorClass(); //Set the color properties color.Red = 255; color.Green = 0; color.Blue = 0; color.Transparency = 255; sysm.Color = color; sysm.Outline.Color = color; pElem.Symbol = sysm; ESRI.ArcGIS.Display.ISimpleLineSymbol simpleLineSymbol = new ESRI.ArcGIS.Display.SimpleLineSymbolClass(); simpleLineSymbol.Color = color; ESRI.ArcGIS.Display.ISymbol symbol = simpleLineSymbol as ESRI.ArcGIS.Display.ISymbol; // Dynamic cast. ESRI.ArcGIS.Display.IRubberBand2 rubberBand = new ESRI.ArcGIS.Display.RubberLineClass(); ESRI.ArcGIS.Geometry.IGeometry geometry = rubberBand.TrackNew(screenDisplay, symbol); screenDisplay.SetSymbol(symbol); screenDisplay.DrawPolyline(geometry); screenDisplay.FinishDrawing(); //Start Buffering IConstructMultipoint myMultiPoint = new MultipointClass(); myMultiPoint.ConstructDivideLength(geometry as ICurve, 10000); IGeometryCollection geometryBag = new GeometryBagClass(); IGeometryCollection Rslt = new GeometryBagClass(); IPointCollection pointCollection = myMultiPoint as IPointCollection; object Missing = Type.Missing; for(int i = 0; i<pointCollection.PointCount ; i++ ) { geometryBag.AddGeometry(pointCollection.get_Point(i), ref Missing, ref Missing); } IGeometryBag enumGeometry = geometryBag as IGeometryBag; IBufferConstruction ipBufCon = new BufferConstruction(); IBufferConstructionProperties2 ipBufConProp = (IBufferConstructionProperties2)ipBufCon; ipBufConProp.UseGeodesicBuffering = true; ipBufConProp.UnionOverlappingBuffers = true; ipBufCon.ConstructBuffers((IEnumGeometry)enumGeometry, 500.0 * 1000.0, Rslt);IPolygon bufrPolygon = Rslt.get_Geometry(0) as IPolygon; //Fill the BufrPolygon IElement iElem = pElem as IElement; iElem.Geometry = bufrPolygon as IGeometry; IFillShapeElement pElemFillShp = pElem as IFillShapeElement;//Add the result as an element of the map pElemFillShp.Symbol = sysm; axMapControl1.ActiveView.GraphicsContainer.AddElement(pElemFillShp as IElement, 0); }
It's because you're not setting spatial reference on geometry bag.
I'm having the same problem (code below). Did you ever get a solution to this error? Thee error happens at bufferConstruction.ConstructBuffers(enumGeom, buffDist, bufferColl);. Throws this error: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
var map = ArcMap.Document.FocusMap;
var graphicsContainer = (IGraphicsContainer)map;
//get map unit
var outUnits = map.MapUnits;
var inUnits = esriUnits.esriMeters;
var unitConverter = new UnitConverter();
double buffDist = unitConverter.ConvertUnits(35, inUnits, outUnits);
var selection = (IEnumFeature)map.FeatureSelection;
selection.Reset();
var feature = selection.Next();
object missing = Type.Missing;
var geomColl = new GeometryBagClass();
geomColl.AddGeometry(feature.Shape, ref missing, ref missing);
var enumGeom = (IEnumGeometry)geomColl;
enumGeom.Reset();
var bufferConstruction = new BufferConstructionClass();
var bufferProps = (IBufferConstructionProperties2)bufferConstruction;
bufferProps.UseGeodesicBuffering = true;
var bufferColl = new GeometryBagClass();
bufferConstruction.ConstructBuffers(enumGeom, buffDist, bufferColl);
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.