arcengine 調用arctoolbox功能的舉例 spatialJoin

廢話不多說,code是王道。

其中str1、str2兩個參數是target路徑、join路徑 


 private void spatialJoin(Geoprocessor gp, string str1, string str2)

        {
            ESRI.ArcGIS.AnalysisTools.SpatialJoin sj = new ESRI.ArcGIS.AnalysisTools.SpatialJoin();


            saveName("spatialJoin", getFileName(str1) + "_SpatialJoin.shp");


            sj.target_features = str1;


            sj.join_features = str2;


            sj.out_feature_class = getPathName(str1) + "_SpatialJoin.shp";


            sj.join_operation = "JOIN_ONE_TO_ONE";


            sj.match_option = "INTERSECTS";


            sj.join_type = "KEEP_ALL";


            if (sj.join_features != null || sj.target_features != null)
            {
                IGeoProcessorResult results = null;


                results = (IGeoProcessorResult)gp.Execute(sj, null);


                IGPUtilities pGPUtil = new GPUtilitiesClass();


                IFeatureClass pFC;


                IQueryFilter pQF;


                pGPUtil.DecodeFeatureLayer(results.GetOutput(0), out pFC, out pQF);


                int count = pFC.FeatureCount(null);      //統計Feature對象個數


                IFeatureCursor pCursor = pFC.Insert(true);   //提取FeatureCursor對象


                IFeatureLayer pFeatureLayer = new FeatureLayerClass();


                pFeatureLayer.FeatureClass = pFC;


                axMapControl1.Map.AddLayer(pFeatureLayer); 


                result5.Text = "Spatial Join 完成!";


            }
            else
                MessageBox.Show("請選擇圖層");
        }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章