intersect 裁剪导出要素类

最近我在做一个需求:就是用一个图形裁剪导出要素类。最先用Clip工具,后面发现不对,用arcmap测试下,确实不是想要的结果,后面发现用intersect工具可以。但是intersect的参数设置比较不固定,需要进行多番测试,这两天试了很多方法,查了很多资料,最后是下面这种方式成功了。要使用IGpValueTableObject 对象。网上有使用字符串的,似乎不行。

 

/// <summary>
        /// 成功方式
        /// </summary>
        /// <param name="inputFeatClass">输入要素类</param>
        /// <param name="clipFeatClass">裁剪要素类</param>
        /// <param name="outShpFileName">不带.shp的文件名</param>
        private void IntersectResults(IFeatureClass inputFeatClass, IFeatureClass clipFeatClass, string outShpFileName)
        {
            IGpValueTableObject valTbl = new GpValueTableObjectClass();
            valTbl.SetColumns(2);
            object row = "";
            object rank = 1;

            row = inputFeatClass;
            valTbl.SetRow(0, ref row);
            valTbl.SetValue(0, 1, ref rank);

            row = clipFeatClass;
            valTbl.SetRow(1, ref row);
            rank = 2;
            valTbl.SetValue(1, 1, ref rank);

            Geoprocessor gp = new Geoprocessor();
            gp.OverwriteOutput = true;
            ESRI.ArcGIS.AnalysisTools.Intersect intersect = new ESRI.ArcGIS.AnalysisTools.Intersect();
            intersect.in_features = valTbl;
            intersect.out_feature_class = outShpFileName; 
            intersect.join_attributes = "NO_FID";
            intersect.output_type = "INPUT";
            if (gp.Execute(intersect, null) == null)
            {
                throw new DataOutputException(GetGpMessage(gp));
            }
                  }


下面是另外一种方式,但是我试了不行。

private void IntersectResults(string[] inShpFileNames, string outShpFileName)
        {
            
            string infeatues = "";
            foreach (string str in inShpFileNames)
            {
                if (infeatues != "")
                { infeatues += ";"; }
                infeatues += str;
            }
            Geoprocessor gp = new Geoprocessor();
            gp.OverwriteOutput = true;
            ESRI.ArcGIS.AnalysisTools.Intersect intersect = new ESRI.ArcGIS.AnalysisTools.Intersect();
            intersect.in_features = infeatues;// @"E:\数据\temp\New_Shapefile.shp;E:\数据\temp\New_Shapefile_Intersect.shp";
            intersect.out_feature_class = outShpFileName; //@"E:\数据\temp\intersectOne.shp";
            intersect.join_attributes = "NO_FID";
            intersect.output_type = "INPUT";
            if (gp.Execute(intersect, null) == null)
            {
                throw new DataOutputException(GetGpMessage(gp));
            }
            
        }


还有一种方式 我试了也不行:

private IFeatureClass Intersect(IFeatureClass inputfeatureclass, IFeatureClass cliplayerClass)
        {

            IBasicGeoprocessor basicGeoprocessor = new BasicGeoprocessorClass();
            IFeatureClassName utFeatClassName = new FeatureClassNameClass();
            outFeatClassName.FeatureType = esriFeatureType.esriFTSimple;
            outFeatClassName.ShapeFieldName = "Shape";
            outFeatClassName.ShapeType = inputfeatureclass.ShapeType;

            IDataset dataset = inputfeatureclass as IDataset;
            string utFileName = dataset.Name + GetNextFileIdName(m_ShpPath, dataset.Name).ToString();
            IWorkspaceName workspaceName = new WorkspaceNameClass();
            workspaceName.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapeFileWorkspaceFactory.1";
            workspaceName.PathName = m_ShpPath;
            IDatasetName datasetName = outFeatClassName as IDatasetName;
            datasetName.Name = outFileName;
            datasetName.WorkspaceName = workspaceName;


            return basicGeoprocessor.Intersect(inputfeatureclass as ITable, false, cliplayerClass as ITable, false, 0, outFeatClassName);
        }


 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值