zoukankan      html  css  js  c++  java
  • ArcGis面要素空间连接,取相交面积最大者 C#

    核心代码:

      1         #region JoinWork_IntersectMax
      2         private void CreateNewFields_IntersectMax(IFeatureClass destFeatureClass,IFeatureClass sourceFeatureClass)
      3         {
      4             List<IField> fieldList = new List<IField>();
      5             foreach (var item in this.chkField.CheckedItems)
      6             {
      7                 IField field=sourceFeatureClass.Fields.get_Field( sourceFeatureClass.Fields.FindField(item.ToString()));
      8                 fieldList.Add(field);
      9             }
     10             string[] fieldArray = Utils.FieldUtils.GetFieldsNameArray(destFeatureClass);
     11             foreach (IField field in fieldList)
     12             {
     13                 if (!fieldArray.Contains(field.Name))
     14                 {
     15                     Utils.FieldUtils.CreateField(destFeatureClass, field.Type, field.Name, "Source_"+ field.Name, field.Length, field.Precision, field.Scale);
     16                 }
     17             }
     18         }
     19         private void GetFieldIndex(IFeatureClass destFeatureClass, IFeatureClass sourceFeatureClass, out List<int> destCLSFieldIDList, out  List<int> sourceCLSFieldIDList)
     20         {
     21             List<int> destIdList = new List<int>();
     22             List<int> sourceIdList = new List<int>();
     23             foreach (var item in this.chkField.CheckedItems)
     24             {
     25                 destIdList.Add( destFeatureClass.Fields.FindField(item.ToString()));
     26                 sourceIdList.Add( sourceFeatureClass.Fields.FindField(item.ToString()));
     27             }
     28             destCLSFieldIDList = destIdList;
     29             sourceCLSFieldIDList = sourceIdList;
     30         }
     31 
     32         private void  JoinWork_IntersectMax(IFeatureClass featureClassD, IFeatureClass featureClassS)
     33         {
     34             IFeatureCursor featureCursorD = null;
     35             IFeatureCursor featureCursorD_S = null;
     36             try
     37             {
     38                 int index = 1;
     39                 int count = featureClassD.FeatureCount(null);
     40                 Utils.UserArcMapProgressbar userArcMapProgressbar = new UserArcMapProgressbar(m_hookHelper);
     41                 userArcMapProgressbar.SetProgressbar(1,count, 1);
     42 
     43                 //create Fields
     44                 CreateNewFields_IntersectMax(featureClassD, featureClassS);
     45                 //get link field id list
     46                 List<int> destCLSFieldIdList;
     47                 List<int> sourceCLSFieldIdList;
     48                 GetFieldIndex(featureClassD, featureClassS, out destCLSFieldIdList, out sourceCLSFieldIdList);
     49 
     50                 Utils.UserWorkspace.FeatureWorkspace featureWorkspace = new Utils.UserWorkspace.FeatureWorkspace(featureClassD);
     51                 featureWorkspace.StartEdit(false);
     52 
     53                 featureCursorD = featureClassD.Update(null, true);
     54                 IFeature featureD = featureCursorD.NextFeature();
     55                 while (featureD != null)
     56                 {
     57                     userArcMapProgressbar.Position = index;
     58                     userArcMapProgressbar.Message = $"空间连接_相交,取重叠面积最大者_已处理:{index}/{count}";
     59                     userArcMapProgressbar.Step();
     60                     ISpatialFilter spatialFilterD_S = Utils.FilterUtils.SpatialFilter(featureD.Shape, esriSpatialRelEnum.esriSpatialRelIntersects);
     61                     featureCursorD_S = featureClassS.Search(spatialFilterD_S, true);
     62                     IFeature featureS = featureCursorD_S.NextFeature();
     63                     Dictionary<int, double> feature_Area = new Dictionary<int, double>();
     64                     while (featureS != null)
     65                     {
     66                         ITopologicalOperator topologicalOperatorD_S = featureD.Shape as ITopologicalOperator;
     67                         IGeometry geometryD_S = topologicalOperatorD_S.Intersect(featureS.Shape, esriGeometryDimension.esriGeometry2Dimension);
     68                         if (!feature_Area.ContainsKey(featureS.OID))
     69                             feature_Area.Add(featureS.OID, (geometryD_S as IArea).Area);
     70                         featureS = featureCursorD_S.NextFeature();
     71                     }
     72                     if (feature_Area.Count > 0)
     73                     {
     74                         IFeature featureGoal;
     75                         var matches = feature_Area.Where(item => item.Value == feature_Area.Values.Max());
     76                         featureGoal = featureClassS.GetFeature(matches.First().Key);
     77                         for (int i = 0; i < sourceCLSFieldIdList.Count; i++)
     78                         {
     79                             featureD.set_Value(destCLSFieldIdList[i], featureGoal.get_Value(sourceCLSFieldIdList[i]));
     80                         }
     81                         featureCursorD.UpdateFeature(featureD);
     82                     }
     83                     featureD = featureCursorD.NextFeature();
     84                     index++;
     85                 }
     86                 userArcMapProgressbar.Hide();
     87                 featureWorkspace.StopEdit(true);
     88             }
     89             catch (Exception exp)
     90             {
     91                 ErrorForm err = new ErrorForm(exp.Message + "
    " + exp.StackTrace);
     92                 err.Show();
     93             }
     94             finally
     95             {
     96                 System.Runtime.InteropServices.Marshal.FinalReleaseComObject(featureCursorD);
     97                 System.Runtime.InteropServices.Marshal.FinalReleaseComObject(featureCursorD_S);
     98             }
     99         }
    100         #endregion
  • 相关阅读:
    潭州课堂25班:Ph201805201 第十二课 new方法,定制属性访问,描述符与装饰器 (课堂笔记)
    潭州课堂25班:Ph201805201 第十一课 继承,多继承和魔术方法,属性和方法 (课堂笔记)
    Storm笔记
    java代码。继承。。。很戳我的心啊。。不太懂。super的真正用法
    java代码。从来没想过java里的继承是多么的难懂。如哲学
    java代码继承疑惑,请有心人解答
    java冒泡排序
    java数组复制
    java继承。顾不了
    java继承初级
  • 原文地址:https://www.cnblogs.com/yzhyingcool/p/11013145.html
Copyright © 2011-2022 走看看