Method for generating a flat buffer in GIS
In arcengine, there are two buffer generation methods: itopologicaloperator. buffer (double distance) and geopressor. buffer.
The first method cannot select a parameter. By default, the circle Header Buffer is generated. The second method requires a buffer for the layer, which is extremely inconvenient for operations on a single element, and the line_end_type parameter is set to "flat ", it cannot be generated. There is almost no explanation on the Internet.
After patiently searching, I finally found a good method on the Internet and recorded it for backup. The principle of this method is to translate the line into the bufferdistance in the positive direction, then translate the bufferdistance in the negative direction, connect all the points of the two lines, and then convert them into polygon.
The source code is as follows:
/// <Summary>
/// Flat Buffer
/// </Summary>
/// <Param name = "myline"> line </param>
/// <Param name = "bufferdis"> buffer distance </param>
/// <Returns> </returns>
Private ipolympus Gon flatbuffer (ipolympus myline, double bufferdis)
{
Object o = system. type. missing;
// Translate the input line twice (in both the positive and negative directions)
Iconstructcurve mycurve = new polylineclass ();
Mycurve. constructoffset (myline, bufferdis, ref o, ref O );
Ipointcollection pcol = mycurve as ipointcollection;
Iconstructcurve mycurve2 = new polylineclass ();
Mycurve2.constructoffset (myline,-1 * bufferdis, ref o, ref O );
// Flip all nodes of the line for the second Translation
Ipolympus line addline = mycurve2 as ipolympus;
Addline. reverseorientation ();
// Put all the nodes of the second line in the ipointcollection of the first line
Ipointcollection pcol2 = addline as ipointcollection;
Pcol. addpointcollection (pcol2 );
// Use the surface to initialize an ipointcollection.
Ipointcollection mypcol = new polygonclass ();
Mypcol. addpointcollection (pcol );
// Convert ipointcollection to a surface
Ipolympus Gon mypolygon = mypcol as ipolympus gon;
// Simplify node order
Mypolygon. simplifypreservefromto ();
Return mypolygon;
}
From: http://www.dev-club.net/xiangxixinxi/1087042010072906074115/2010112408204313.html