Example #1
0
        private IGeoProcessorResult EraseOverlay(Geoprocessor gp)
        {
            //ESRI.ArcGIS.AnalysisTools.Erase erase = new ESRI.ArcGIS.AnalysisTools.Erase();
            //IFeatureLayer inputLayer = GetFeatureLayer(cbInputLayer.Text);
            //erase.in_features = inputLayer;
            //IFeatureLayer eraseLayer = GetFeatureLayer(cbOverLayLayer.Text);
            ////  string aaa = System.IO.Path.Combine(strOutputPath, "Erase.shp");
            //erase.out_feature_class = outputFullPath;
            //double tolerance = 0.1;
            //erase.cluster_tolerance = tolerance;
            ////erase.cluster_tolerance = tolerance;

            //IGeoProcessorResult results = (IGeoProcessorResult)gp.Execute(erase, null);

            IGpValueTableObject vtobject = new GpValueTableObjectClass();

            vtobject.SetColumns(1);
            object row = "";

            row = GetFeatureLayer(cbInputLayer.Text);
            vtobject.AddRow(ref row);
            row = GetFeatureLayer(cbOverLayLayer.Text);
            vtobject.AddRow(ref row);
            IVariantArray pVarArray = new VarArrayClass();

            pVarArray.Add(vtobject);


            pVarArray.Add(outputFullPath);
            double tolerance = 0.1;

            pVarArray.Add(tolerance);

            IGeoProcessorResult results = gp.Execute("Erase_analysis", pVarArray, null) as IGeoProcessorResult;

            return(results);
        }
Example #2
0
        private IGeoProcessorResult UnionOverlay1(Geoprocessor gp)
        {
            IGpValueTableObject vtobject = new GpValueTableObjectClass();

            vtobject.SetColumns(1);
            object row = "";

            row = GetFeatureLayer(cbInputLayer.Text);
            vtobject.AddRow(ref row);
            row = GetFeatureLayer(cbOverLayLayer.Text);
            vtobject.AddRow(ref row);
            IVariantArray pVarArray = new VarArrayClass();

            pVarArray.Add(vtobject);

            string resultname = null;

            if (resultName.Text != null)
            {
                resultname = resultName.Text + ".shp";
            }
            else
            {
                resultname = cbInputLayer.Text + "_" + cbOverLayLayer.Text + "_" + "Intersect.shp";
            }
            string outputFullPath = System.IO.Path.Combine(strOutputPath, resultname);

            pVarArray.Add(outputFullPath);
            pVarArray.Add(tolerance);

            IGeoProcessorResult results = gp.Execute("Union_analysis", pVarArray, null) as IGeoProcessorResult;

            System.Runtime.InteropServices.Marshal.ReleaseComObject(pVarArray);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(vtobject);

            return(results);
        }
Example #3
0
        private IGeoProcessorResult UnionOverlay(Geoprocessor gp)
        {
            IGpValueTableObject vtobject = new GpValueTableObjectClass();

            vtobject.SetColumns(1);
            object row = "";

            row = GetFeatureLayer(cbInputLayer.Text);
            vtobject.AddRow(ref row);
            row = GetFeatureLayer(cbOverLayLayer.Text);
            vtobject.AddRow(ref row);
            IVariantArray pVarArray = new VarArrayClass();

            pVarArray.Add(vtobject);
            pVarArray.Add(outputFullPath);


            IGeoProcessorResult results = gp.Execute("Union_analysis", pVarArray, null) as IGeoProcessorResult;

            System.Runtime.InteropServices.Marshal.ReleaseComObject(pVarArray);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(vtobject);

            return(results);
        }
Example #4
0
        private void btnBuffer_Click(object sender, EventArgs e)
        {
            //判断是否选择要素
            if (this.txtInputFeat.Text == "" || this.txtInputFeat.Text == null ||
                this.txtOverlayFeat.Text == "" || this.txtOverlayFeat.Text == null)
            {
                txtMessage.Text = "请设置叠置要素!";
                return;
            }
            ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
            //OverwriteOutput为真时,输出图层会覆盖当前文件夹下的同名图层
            gp.OverwriteOutput = true;


            //设置参与叠置分析的多个对象
            object inputFeat            = this.txtInputFeat.Text;
            object overlayFeat          = this.txtOverlayFeat.Text;
            IGpValueTableObject pObject = new GpValueTableObjectClass();

            pObject.SetColumns(2);
            pObject.AddRow(ref inputFeat);
            pObject.AddRow(ref overlayFeat);

            //获取要素名称
            string str     = System.IO.Path.GetFileName(this.txtInputFeat.Text);
            int    index   = str.LastIndexOf(".");
            string strName = str.Remove(index);

            //设置输出路径
            strOutputPath = txtOutputPath.Text;

            //叠置分析结果
            IGeoProcessorResult result = null;

            //创建叠置分析实例,执行叠置分析
            string strOverlay = cboOverLay.SelectedItem.ToString();

            try
            {
                //添加处理过程消息
                txtMessage.Text = "开始叠置分析……" + "\r\n";
                switch (strOverlay)
                {
                case "求交(Intersect)":
                    Intersect intersectTool = new Intersect();
                    //设置输入要素
                    intersectTool.in_features = pObject;
                    //设置输出路径
                    strOutputPath += strName + "_" + "_intersect.shp";
                    intersectTool.out_feature_class = strOutputPath;
                    //执行求交运算
                    result = gp.Execute(intersectTool, null) as IGeoProcessorResult;
                    break;

                case "求并(Union)":
                    Union unionTool = new Union();
                    //设置输入要素
                    unionTool.in_features = pObject;
                    //设置输出路径
                    strOutputPath += strName + "_" + "_union.shp";
                    unionTool.out_feature_class = strOutputPath;
                    //执行联合运算
                    result = gp.Execute(unionTool, null) as IGeoProcessorResult;
                    break;

                case "标识(Identity)":
                    Identity identityTool = new Identity();
                    //设置输入要素
                    identityTool.in_features       = inputFeat;
                    identityTool.identity_features = overlayFeat;
                    //设置输出路径
                    strOutputPath += strName + "_" + "_identity.shp";
                    identityTool.out_feature_class = strOutputPath;
                    //执行标识运算
                    result = gp.Execute(identityTool, null) as IGeoProcessorResult;
                    break;
                }
            }
            catch (System.Exception ex)
            {
                //添加处理过程消息
                txtMessage.Text += "叠置分析过程出现错误:" + ex.Message + "\r\n";
            }


            //判断叠置分析是否成功
            if (result.Status != ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded)
            {
                txtMessage.Text += "叠置失败!";
            }
            else
            {
                this.DialogResult = DialogResult.OK;
                txtMessage.Text  += "叠置成功!";
            }
        }
        //开始分析
        private void btnOK_Click(object sender, EventArgs e)
        {
            //判断是否选择要素
            if (this.txtInputLayer.Text == "" || this.txtInputLayer.Text == null ||
                this.txtOverlayLayer.Text == "" || this.txtOverlayLayer.Text == null)
            {
                txtMessage.Text = "请选择参加叠置分析的图层!";
                return;
            }
            ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
            //OverwriteOutput为真时,输出图层会覆盖当前文件夹下的同名图层
            gp.OverwriteOutput = true;

            //设置参与叠置分析的多个对象
            object inputFeat = this.txtInputLayer.Text;
            object overlayFeat = this.txtOverlayLayer.Text;
            IGpValueTableObject pObject = new GpValueTableObjectClass();
            pObject.SetColumns(2);
            pObject.AddRow(ref inputFeat);
            pObject.AddRow(ref overlayFeat);

            //获取要素名称
            string str = System.IO.Path.GetFileName(this.txtInputLayer.Text);
            int index = str.LastIndexOf(".");
            string strName = str.Remove(index);

            //设置输出路径
            strOutputPath = txtOutputLayerPath.Text;

            //叠置分析结果
            IGeoProcessorResult result = null;

            //创建叠置分析实例,执行叠置分析
            string strOverlay = cmbOverlayType.SelectedItem.ToString();
            try
            {
                //添加处理过程消息
                txtMessage.Text = "开始叠置分析……" + "\r\n";
                switch (strOverlay)
                {
                    case "叠置求交(Intersect)":
                        Intersect intersectTool = new Intersect();
                        //设置输入要素
                        intersectTool.in_features = pObject;
                        //设置输出路径
                        strOutputPath += strName + "_" + "_intersect.shp";
                        intersectTool.out_feature_class = strOutputPath;
                        //执行求交运算
                        result = gp.Execute(intersectTool, null) as IGeoProcessorResult;
                        break;
                    case "叠置求并(Union)":
                        Union unionTool = new Union();
                        //设置输入要素
                        unionTool.in_features = pObject;
                        //设置输出路径
                        strOutputPath += strName + "_" + "_union.shp";
                        unionTool.out_feature_class = strOutputPath;
                        //执行联合运算
                        result = gp.Execute(unionTool, null) as IGeoProcessorResult;
                        break;
                    case "叠置标识(Identity)":
                        Identity identityTool = new Identity();
                        //设置输入要素
                        identityTool.in_features = inputFeat;
                        identityTool.identity_features = overlayFeat;
                        //设置输出路径
                        strOutputPath += strName + "_" + "_identity.shp";
                        identityTool.out_feature_class = strOutputPath;
                        //执行标识运算
                        result = gp.Execute(identityTool, null) as IGeoProcessorResult;
                        break;
                }
            }
            catch (System.Exception ex)
            {
                //添加处理过程消息
                txtMessage.Text += "叠置分析过程出现错误:" + ex.Message + "\r\n";
            }

            //判断叠置分析是否成功
            if (result.Status != ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded)
                txtMessage.Text += "叠置失败!";
            else
            {
                this.DialogResult = DialogResult.OK;
                txtMessage.Text += "叠置成功!";
            }
        }
Example #6
0
        //进行叠置
        private bool DoIntersect(IFeatureClass pOldFeaCls, IFeatureClass pNewFeaCls, IGeometry pGeo)
        {
            _Progress.SetProgress("新旧图层叠置...");
            Application.DoEvents();
            Geoprocessor gp = new Geoprocessor();

            gp.OverwriteOutput = true;
            gp.AddOutputsToMap = false;
            IGpValueTableObject vtobject = new GpValueTableObjectClass();

            vtobject.SetColumns(1);

            IFeatureLayer pFeaturelayer = new FeatureLayerClass();

            pFeaturelayer.FeatureClass = pOldFeaCls;
            pFeaturelayer.Name         = pOldFeaCls.AliasName;

            if (pGeo != null)
            {
                ISpatialFilter pSpatialFilter = new SpatialFilterClass();
                pSpatialFilter.Geometry   = pGeo;
                pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                IFeatureSelection pFeaSelection = pFeaturelayer as IFeatureSelection;   //仅对选中的重点巡查线进行缓冲分析
                pFeaSelection.SelectFeatures(pSpatialFilter, esriSelectionResultEnum.esriSelectionResultNew, false);
            }
            if (_Progress != null)
            {
                if (_Progress.UserAskCancel)
                {
                    return(false);
                }
            }
            object pObj1 = pFeaturelayer;

            vtobject.AddRow(ref pObj1);

            IFeatureLayer pNewFeaturelayer = new FeatureLayerClass();

            pNewFeaturelayer.FeatureClass = pNewFeaCls;
            pNewFeaturelayer.Name         = pNewFeaCls.AliasName;

            if (pGeo != null)
            {
                ISpatialFilter pSpatialFilter = new SpatialFilterClass();
                pSpatialFilter.Geometry   = pGeo;
                pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                IFeatureSelection pFeaSelection = pNewFeaturelayer as IFeatureSelection;   //仅对选中的重点巡查线进行缓冲分析
                pFeaSelection.SelectFeatures(pSpatialFilter, esriSelectionResultEnum.esriSelectionResultNew, false);
            }
            if (_Progress != null)
            {
                if (_Progress.UserAskCancel)
                {
                    return(false);
                }
            }
            object pObj2 = pNewFeaturelayer;

            vtobject.AddRow(ref pObj2);

            ESRI.ArcGIS.AnalysisTools.Intersect intersect = new ESRI.ArcGIS.AnalysisTools.Intersect();
            intersect.in_features     = vtobject;
            intersect.join_attributes = "ALL";
            intersect.output_type     = "INPUT";

            intersect.out_feature_class = _MdbPath + "\\" + _MdbName + "\\" + _IntersectName;// _ResultPath + _TmpMdbName + "\\" + _IntersectName;
            if (_Progress != null)
            {
                if (_Progress.UserAskCancel)
                {
                    return(false);
                }
            }
            if (!RunTool(gp, intersect))
            {
                gp = null;
                return(false);
            }

            intersect.in_features = null;
            vtobject.RemoveRow(1);
            vtobject.RemoveRow(0);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(vtobject);
            try
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(intersect);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(gp);
            }
            catch (Exception err)
            { }

            vtobject  = null;
            intersect = null;
            gp        = null;

            return(true);
        }
        private void btnBuffer_Click(object sender, EventArgs e)
        {//判断是否选择要素
            if (this.texInputFeat.Text == "" || this.texInputFeat.Text == null || this.texOverlayFeat.Text == "" || this.texOverlayFeat.Text == null)
            {
                texMessage.Text = "请设置叠置要素!";
                return;
            }
            ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
            //overwriteOutput为真时,输出图层会覆盖当前文件夹下的同名的图层
            gp.OverwriteOutput = true;
            //设置参与叠置分析的多个对象
            object inputFeat            = this.texInputFeat.Text;
            object overlayFeat          = this.texOverlayFeat.Text;
            IGpValueTableObject pObject = new GpValueTableObjectClass();

            pObject.SetColumns(2);
            pObject.AddRow(ref inputFeat);
            pObject.AddRow(ref overlayFeat);
            //获取要素名称
            string str     = System.IO.Path.GetFileName(this.texInputFeat.Text);
            int    index   = str.LastIndexOf(".");
            string strName = str.Remove(index);

            //设置输出路径
            strOutputPath = tetOutputPath.Text;
            //叠置分析结果
            IGeoProcessorResult result = null;
            //创建叠置分析实例
            string strOverlay = cboOverLay.SelectedItem.ToString();

            try
            {
                //添加处理过程消息
                texMessage.Text = "开始叠置分析......" + "\r\n";
                switch (strOverlay)
                {
                case "求交(Intersect)":
                    Intersect intersectTool = new Intersect();
                    //设置输入要素
                    intersectTool.in_features = pObject;
                    //设置输出路径
                    //strOutputPath += strName + "_" + "_intersect.shp";
                    intersectTool.out_feature_class = strOutputPath;
                    intersectTool.output_type       = "ALL";
                    //执行求交运算
                    result = gp.Execute(intersectTool, null) as IGeoProcessorResult;
                    break;

                case "求并(Union)":
                    Union unionTool = new Union();
                    //设置输入要素
                    unionTool.in_features = pObject;
                    //设置输出路径
                    strOutputPath += strName + "_" + "_union.shp";
                    unionTool.out_feature_class = strOutputPath;
                    //执行联合运算
                    result = gp.Execute(unionTool, null) as IGeoProcessorResult;
                    break;

                case "擦除(Erase)":
                    //Identity identityTool = new Identity();
                    Erase eraseTool = new Erase();
                    //设置输入要素
                    eraseTool.in_features    = inputFeat;
                    eraseTool.erase_features = overlayFeat;
                    //设置输出路径
                    strOutputPath += strName + "-" + "_erase.shp";
                    eraseTool.out_feature_class = strOutputPath;
                    //执行标识结果
                    result = gp.Execute(eraseTool, null) as IGeoProcessorResult;
                    break;
                }
            }
            catch (System.Exception ex)
            {
                //添加处理过程消息
                texMessage.Text += "叠置分析过程出现错误:" + ex.Message + "\r\n";
            }
            //判断叠置分析是否成功

            if (result.Status != ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded)
            {
                texMessage.Text += "叠置失败!";
            }
            else
            {
                this.DialogResult = DialogResult.OK;
                texMessage.Text  += "叠置成功!";
                //int index1 = strOutputPath.LastIndexOf("\\");

                //this.mMapControl.AddShapeFile(strOutputPath.Substring(0, index1), strOutputPath.Substring(index1));
            }
        }