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 + "\r\n" + 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

原文地址:https://www.cnblogs.com/yzhyingcool/p/11013145.html

时间: 2024-11-06 07:18:45

ArcGis面要素空间连接,取相交面积最大者 C#的相关文章

将位图导入为ArcGIS面要素

本文根据笔者经验,介绍一种从位图图像导入ArcGIS称为要素的方法.这种方法适用于从现有出版物图片中获取地理信息的情况. 首先要说明的是,从位图导入要素是非常非常不精确的方式,如果有其它数据来源,那么就不应该采用此方法. 另外,如果位图包含的内容相对简单,区域结构紧凑不零散,则可以考虑ArcMap绘制地图,而不用此方法. 为让表述更直观,笔者从百度卫星地图截取了 辽宁省康平县 西泡子水库附近的区域,作为操作的说明. 00_orign 1. 制作灰度图 为便于在ArcMap中处理,将原始图像的色彩

ArcGIS Engine中空间参照(地理坐标)相关方法总结转

ArcGIS Engine中空间参照(地理坐标)相关方法总结 来自:http://blog.csdn.net/u011170962/article/details/38776101 1.创建空间参考 [csharp] view plain copy print? /// <summary> /// 根据prj文件创建空间参考 /// </summary> /// <param name="strProFile">空间参照文件</param>

HDU 5120 Intersection (求圆环相交面积)

题意:给定圆环的内径r和外径R,以及2个相同圆环的圆心,求两个圆环的相交面积. 思路: S = A大B大 - A大B小 - A小B大 + A小B小.(A表示A环,大表示大圆,B同) 1 #include <iostream> 2 #include <queue> 3 #include <stack> 4 #include <cstdio> 5 #include <vector> 6 #include <map> 7 #include

HDOJ Intersection 5120【环相交面积】

Intersection Time Limit: 4000/4000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) Total Submission(s): 949    Accepted Submission(s): 360 Problem Description Matt is a big fan of logo design. Recently he falls in love with logo made

HDU2056 Rectangles【水题】【相交面积】

Rectangles Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 15823    Accepted Submission(s): 5061 Problem Description Given two rectangles and the coordinates of two points on the diagonals of e

多边形相交面积模板

1 /* 2 类型:多边形相交面积模板 3 */ 4 5 #include<cstdio> 6 #include<iostream> 7 #include<algorithm> 8 #include<cstring> 9 #include<cmath> 10 using namespace std; 11 #define maxn 510 12 const double eps=1E-8; 13 int sig(double d){ 14 ret

NYOJ 1186 心理阴影(两个圆环的相交面积)

心理阴影 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述       自从shanghai reginal后,zkc学长的心理就有了阴影.什么不敢水题,不敢gj,不敢放松...(各种不敢).同样的你们的zsj学长也是这样的.并且他们的心理阴影是一样一样的. 已知一个人的心理阴影为一个环形,那么求你们的zkc学长和zjs学长站在一起的时候的心理阴影的重叠面积. 输入 T组数据 r,R表示是内圆半径和外圆半径. x1,y1 zkc学长站的位置(抽象为一个点) x2,y2

两张表一对多的连接,取多记录表中最新的一条数据

select sn, pname, srnum, rerepairtime, rn from ( select sn,pname, srnum, rerepairtime,row_number() over(partition by assetsid order by rerepairtime desc) rn from atzserreportb ) where rn = 1 两张表一对多的连接,取多记录表中最新的一条数据

HDU 1798 两圆相交面积

Tell me the area Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1755    Accepted Submission(s): 535 Problem Description There are two circles in the plane (shown in the below picture), there is