码迷,mamicode.com
首页 > 其他好文 > 详细

SptialJoin样例函数

时间:2019-09-09 16:21:14      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:efi   tab   name   merger   init   路径   ide   eal   scl   

  在开发的Arcmap插件或软件时,调用SptialJoin工具时,经常程序经常会弹出异常。在这个随笔里面贴一个可以顺利运行的函数,方便后续的开发。

 

//tarFC 目标图层 joinFC 添加图层 path_spatialJoin 成果图层输出路径 

 private void SptialJoin(IFeatureClass tarFC, IFeatureClass joinFC, string path_spatialJoin)
        {
            int index_JoinOidFd = joinFC.Fields.FindField("ORIG_FID");
            IField joinFd = joinFC.Fields.get_Field(index_JoinOidFd);
            IFieldEdit pNewField = new FieldClass();
            pNewField.Name_2 = "Alp_Join";
            pNewField.Type_2 = esriFieldType.esriFieldTypeString;
            pNewField.Length_2 = 2000;

            int index_SrcTBYBHFd = tarFC.FindField("TBYBH");
            IField srcFd = tarFC.Fields.get_Field(index_SrcTBYBHFd);
            IFieldEdit pSrcField = new FieldClass();
            pSrcField.Name_2 = "TBYBH";
            pSrcField.Type_2 = esriFieldType.esriFieldTypeString;
            pSrcField.Length_2 = 100;


            IGPUtilities pGpUtilities = new GPUtilitiesClass();
            IArray pInputTables = new ArrayClass();
            IGPFieldMapping pFieldMapping = new GPFieldMappingClass();


            IDETable pInputTableB = new DETableClass();
            pInputTables.Add(pInputTableB);
            pFieldMapping.RemoveAll();
            pFieldMapping.Initialize(pInputTables, null);


            IGPFieldMap pFieldMap = new GPFieldMapClass();
            pFieldMap.MergeRule = esriGPFieldMapMergeRule.esriGPFieldMapMergeRuleJoin;
            pFieldMap.JoinDelimiter = ",";
            pFieldMap.AddInputField(pInputTableB, joinFd, -1, -1);
            pFieldMap.OutputField = pNewField as IField;
            pFieldMapping.AddFieldMap(pFieldMap);

            pFieldMap = new GPFieldMapClass();
            pFieldMap.MergeRule = esriGPFieldMapMergeRule.esriGPFieldMapMergeRuleFirst;
            pFieldMap.JoinDelimiter = ",";
            pFieldMap.AddInputField(pInputTableB,srcFd,-1,-1);
            pFieldMap.OutputField = pSrcField as IField;
            pFieldMapping.AddFieldMap(pFieldMap);

            GpHelper.SpatialJoin(tarFC, joinFC, path_spatialJoin, "JOIN_ONE_TO_ONE", "INTERSECT", "KEEP_ALL", pFieldMapping);
        }

  

SptialJoin样例函数

标签:efi   tab   name   merger   init   路径   ide   eal   scl   

原文地址:https://www.cnblogs.com/cuijy/p/11492346.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!