前言

  使用多环缓冲区工具需要将程序初始化为Advanced许可,否则会报错“参数无效”;各个缓冲距离之间用英文分号分隔。

绑定许可

ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop);            
IAoInitialize m_AoInitialize = new AoInitializeClass();
esriLicenseStatus m_LicenseStatus = esriLicenseStatus.esriLicenseUnavailable;
if (m_AoInitialize.IsProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeAdvanced) == esriLicenseStatus.esriLicenseAvailable)
{
    m_LicenseStatus = m_AoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeAdvanced);
}
else
{
    MessageBox.Show("许可不可用!");
    Application.Exit();
}

代码

MultipleRingBuffer gpTool = new MultipleRingBuffer(cmbInFeature.Text, txtOutFeature.Text, pBufferDis);   //pBufferDis示例: 100;200;400

//缓冲单位
switch (cmbUnit.Text)
{
    case "默认":
        gpTool.Buffer_Unit = "Default";
        break;
    case "":
        gpTool.Buffer_Unit = "Meters";
        break;
    case "千米":
        gpTool.Buffer_Unit = "Kilometers";
        break;
    case "分米":
        gpTool.Buffer_Unit = "Decimeters";
        break;
    case "厘米":
        gpTool.Buffer_Unit = "Centimeters";
        break;
    case "毫米":
        gpTool.Buffer_Unit = "Millimeters";
        break;
    case "十进制度":
        gpTool.Buffer_Unit = "DecimalDegrees";
        break;
    default:
        gpTool.Buffer_Unit = "Default";
        break;
}

//字段名
if (string.IsNullOrWhiteSpace(txtField.Text))
    gpTool.Field_Name = "distance";
else
    gpTool.Field_Name = txtField.Text;

//融合类型
switch (cmbDissolve.Text)
{
    case "NONE":
        gpTool.Dissolve_Option = "NONE";
        break;
    case "ALL":
        gpTool.Dissolve_Option = "ALL";
        break;
}

//是否仅外部面
if (chkOutside.Checked)
    gpTool.Outside_Polygons_Only = "OUTSIDE_ONLY";
else
    gpTool.Outside_Polygons_Only = "FULL";

Geoprocessor gp = new Geoprocessor();
try
{
    gp.Execute(gpTool, null);
    IFeatureLayer pLayer = new FeatureLayerClass();
    IFeatureClass pFeaCls = gp.Open(gpTool.Output_Feature_class) as IFeatureClass;
    pLayer.FeatureClass = pFeaCls;
    pLayer.Name = pFeaCls.AliasName;
    //序列化
    return SerializeUtil.Serialized(pLayer);
}
catch (Exception ex)
{
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < gp.MessageCount; i++)
    {
        sb.AppendLine(gp.GetMessage(i));
    }
    sb.AppendLine(ex.Message);
    XtraMessageBox.Show(sb.ToString());
    return null;
}

PS:偶然发现,程序初始化为EngineOrDesktop和Desktop时,普通文件夹工作空间IWorkspaceName.Category的返回值不同。初始化为EngineOrDesktop时返回Shapefiles;初始化为Desktop时返回Shapefile。