ArcEngine 平头缓冲区

源起

数据处理过程中,发现圆头的缓冲区会多出来一截,如果用线的缓冲区和另外一条线求交点,那么求出的交点会跑到线的外侧与实际不否,以下代码是生成平头缓冲区的代码。

解决方案

实现平头缓冲区主要使用IBufferConstruction接口实现,以下代码是我的解决思路,供大家参考,如果好用记得给我点赞哈

public static IGeometry buffer(IGeometry pGeometry, double dis)
{
    ITopologicalOperator5 topolOperator = pGeometry as ITopologicalOperator5;
    topolOperator.Simplify();
    //这块我是地理坐标系,输入的缓冲区距离是10米,需要转换到度
    double distance = ConvertUnit(dis, esriUnits.esriMeters, esriUnits.esriDecimalDegrees);
    IGeometry bufferGeometry = FlatBuffer(pGeometry as IPolyline, distance);
    return bufferGeometry;
}

private static IGeometry FlatBuffer(IGeometry pGeometry, double dis)
{
    IPolyline5 polyline = pGeometry as IPolyline5;
    IGeometryBag geoBag = new GeometryBagClass();
    geoBag.SpatialReference = pGeometry.SpatialReference;
    IGeometryCollection geometryCollection = geoBag as IGeometryCollection;
    geometryCollection.AddGeometry(polyline);
    IEnumGeometry pInputGeometrys = geometryCollection as IEnumGeometry;
    IBufferConstruction pBufferConstruction = new BufferConstructionClass();
    IBufferConstructionProperties2 pBufferProps = pBufferConstruction as IBufferConstructionProperties2;
    pBufferProps.SideOption = esriBufferConstructionSideEnum.esriBufferFull;
    pBufferProps.EndOption = esriBufferConstructionEndEnum.esriBufferFlat;
    
    //如果构建缓冲区出错,可以修改如下两句为false、true再试试
    pBufferProps.UnionOverlappingBuffers = true;
    pBufferProps.GenerateCurves = false;
    
    IGeometryCollection outputBuffers = new GeometryBagClass();
    pBufferConstruction.ConstructBuffers(pInputGeometrys, dis, outputBuffers);

    IPolygon pResultPolygon = new PolygonClass();
    ITopologicalOperator2 pTopoOp = pResultPolygon as ITopologicalOperator2;
    IEnumGeometry pOutputGeometrys = outputBuffers as IEnumGeometry;
    pTopoOp.ConstructUnion(pOutputGeometrys);

    System.Runtime.InteropServices.Marshal.ReleaseComObject(pInputGeometrys);
    System.Runtime.InteropServices.Marshal.ReleaseComObject(pOutputGeometrys);
    return pResultPolygon;
}

附一张效果图:
ArcEngine 平头缓冲区_第1张图片

可能会遇到的问题

  1. 直接引用参考资料1中的代码,大数据量下可能会遇到如下问题an error occurred during the buffer operation,这块我个人认为产生此问题的原因可能是代码的写法不对以及内存没有及时的释放造成的,建议参考我上面代码的写法。

  2. The coordinates or measures are out of bounds,针对这块的解决方案:

    1. 对FeatureClass重新计算空间范围
    2. 修改缓冲区的相关参数,如下
        pBufferProps.UnionOverlappingBuffers = false;
    	pBufferProps.GenerateCurves = true;
    

参考资料:
4. Engine中实现平头缓冲
5. GitHub用到缓冲区的参考代码
6. 实现平头缓冲
7. GIS 中生成平头缓冲区的方法(此方法会产生孔洞,不建议使用)
8. ArcEngine 缓冲区
9. Arcobjects ConstructBuffers produces Error -2147220889?

你可能感兴趣的:(ArcEngine)