美文网首页
1. arcengine拓扑:叠加分析实现(c#)

1. arcengine拓扑:叠加分析实现(c#)

作者: 清远_03d9 | 来源:发表于2019-08-19 14:27 被阅读0次

    直接上demo

    using ESRI.ArcGIS.Geoprocessor;
    using ESRI.ArcGIS.Geoprocessing;
    using ESRI.ArcGIS.DataManagementTools;
    using ESRI.ArcGIS.AnalysisTools;
      /// <summary>
            /// 计算fc1叠加fc2分析,并将两个图层间有压盖的两个要素合并为一条记录,存储到outputName,图层间求合并 ---GPToolAPI
            /// </summary>
            /// <param name="fc1"></param>
            /// <param name="fc2"></param>
            /// <param name="outputName"></param>
            /// <param name="tolerance"></param>
            /// <returns></returns>
            public static bool UnionFeatureClass(string fc1, string fc2, string outputName, double tolerance)
            {
                Geoprocessor GP = new Geoprocessor();
                Union pUnion = new Union();
                IGeoProcessorResult result = null;
                try
                {
                    pUnion.in_features = fc1 + ";" + fc2;
                    pUnion.out_feature_class = outputName;
                    pUnion.join_attributes = "ALL";
                    if (tolerance != 0)
                        pUnion.cluster_tolerance = tolerance.ToString() + " Meters";
    
                    GP.OverwriteOutput = true;
                    GP.TemporaryMapLayers = false;
                    result = (IGeoProcessorResult)GP.Execute(pUnion, null);
                    object sev = 2;
                    string messages = GP.GetMessages(ref sev);
                    if (result != null)
                        return true;
                    else
                        return false;
                }
                catch
                {
                    string str = ReturnMessages(GP);
                    return false;
                }
                finally
                {
                    if (pUnion != null)
                    {
    
                        pUnion = null;
    
                    }
                    if (result != null)
                    {
    
                        result = null;
    
                    }
                    if (GP != null)
                    {
    
                        GP = null;
    
                    }
                    GC.Collect();
                    GC.WaitForFullGCComplete();
                }
    
                //return GP.Execute(pUnion, null) as IGeoProcessorResult;
            }
    
    

    2. 处理错误信息

     /// <summary>
            /// 处理错误信息
            /// </summary>
            /// <param name="gp"></param>
            /// <returns></returns>
            private static string ReturnMessages(Geoprocessor gp)
            {
                string ms = "";
                if (gp.MessageCount > 0)
                {
                    for (int Count = 0; Count <= gp.MessageCount - 1; Count++)
                    {
                        ms += "$" + gp.GetMessage(Count) + "\n\n";
                    }
                }
    
                if (ms.Contains("Succeeded") || ms.Contains("成功"))
                {
                    //MarkConfig(true);
                    return "";
                }
                return ms;
            }
    

    相关文章

      网友评论

          本文标题:1. arcengine拓扑:叠加分析实现(c#)

          本文链接:https://www.haomeiwen.com/subject/alyssctx.html