Пример #1
0
        private IGeoProcessorResult IntersectOverlay3(Geoprocessor gp)
        {
            //Intersect_analysis (in_features, out_feature_class, join_attributes, cluster_tolerance, output_type)

            IGpValueTableObject vtobject = new GpValueTableObjectClass();

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

            row = strInputLayer + " " + inputLevel.ToString();
            vtobject.AddRow(ref row);
            row = strOverLayer + " " + overlayLevel.ToString();
            vtobject.AddRow(ref row);
            IVariantArray pVarArray = new VarArrayClass();

            pVarArray.Add(vtobject);
            string outputFullPath = System.IO.Path.Combine(strOutputPath, strInputLayer + "_" + strOverLayer + "_" + "Intersect");

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

            // Execute the Intersect tool.
            IGeoProcessorResult results = gp.Execute("intersect_analysis", pVarArray, null) as IGeoProcessorResult;

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

            return(results);
        }
        private IGeoProcessorResult IntersectOverlay(Geoprocessor gp)
        {
            string pOutPutFullPath = System.IO.Path.Combine(m_OutPutPath, m_InputLayer + "_" + m_OverlayLayer + "_" + "Intersect");

            IGpValueTableObject pGpValueTableObject = new GpValueTableObjectClass();

            pGpValueTableObject.SetColumns(2);

            object pRow = null;

            pRow = m_InputLayer + " " + m_InputLayerPrecisionLevel;
            pGpValueTableObject.AddRow(ref pRow);
            pRow = m_OverlayLayer + " " + m_OverlayLayerPrecisionLevel;
            pGpValueTableObject.AddRow(ref pRow);

            IVariantArray pVariantArray = new VarArrayClass();

            pVariantArray.Add(pGpValueTableObject);
            pVariantArray.Add(pOutPutFullPath);
            pVariantArray.Add(m_OutputAttributeType);
            pVariantArray.Add(m_Tolerance);
            pVariantArray.Add(m_OutputFeatureType);

            IGeoProcessorResult pGPResult = (IGeoProcessorResult)gp.Execute("intersect_analysis", pVariantArray, null);

            return(pGPResult);
        }
Пример #3
0
        private IGeoProcessorResult UnionOverlay(Geoprocessor gp)
        {
            //Union_analysis (in_features, out_feature_class, join_attributes, cluster_tolerance, gaps)

            IGpValueTableObject vtobject = new GpValueTableObjectClass();

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

            row = GetFeatureLayer(strInputLayer);
            vtobject.AddRow(ref row);
            row = GetFeatureLayer(strOverLayer);
            vtobject.AddRow(ref row);
            IVariantArray pVarArray = new VarArrayClass();

            pVarArray.Add(vtobject);
            string outputFullPath = System.IO.Path.Combine(strOutputPath, strInputLayer + "_" + strOverLayer + "_" + "Union.shp");

            pVarArray.Add(outputFullPath);
            pVarArray.Add(strJoinAttributeType);
            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);
        }
        private IGeoProcessorResult UnionOverlay(Geoprocessor gp)
        {
            //Union_analysis (in_features, out_feature_class, join_attributes, cluster_tolerance, gaps)

            string pOutPutFullPath = System.IO.Path.Combine(m_OutPutPath, m_InputLayer + "_" + m_OverlayLayer + "_" + "Union");

            IGpValueTableObject pGpValueTableObject = new GpValueTableObjectClass();

            pGpValueTableObject.SetColumns(2);

            object pRow = "";

            pRow = m_InputLayer + " " + m_InputLayerPrecisionLevel;
            pGpValueTableObject.AddRow(ref pRow);
            pRow = m_OverlayLayer + " " + m_OverlayLayerPrecisionLevel;
            pGpValueTableObject.AddRow(ref pRow);

            IVariantArray pVariantArray = new VarArrayClass();

            pVariantArray.Add(pGpValueTableObject);
            pVariantArray.Add(pOutPutFullPath);
            pVariantArray.Add(m_OutputAttributeType);
            pVariantArray.Add(m_Tolerance);



            IGeoProcessorResult pGPResult = gp.Execute("Union_analysis", pVariantArray, null) as IGeoProcessorResult;

            return(pGPResult);
        }
Пример #5
0
        private IGeoProcessorResult IntersectOverlay(Geoprocessor gp)
        {
            //Intersect_analysis (in_features, out_feature_class, join_attributes, cluster_tolerance, output_type)

            IGpValueTableObject vtobject = new GpValueTableObjectClass();

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

            row = GetFeatureLayer(strInputLayer);
            vtobject.AddRow(ref row);
            row = GetFeatureLayer(strOverLayer);
            vtobject.AddRow(ref row);
            IVariantArray pVarArray = new VarArrayClass();

            pVarArray.Add(vtobject);
            string outputFullPath = System.IO.Path.Combine(strOutputPath, strInputLayer + "_" + strOverLayer + "_" + "Intersect");

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

            // Execute the Intersect tool.
            IGeoProcessorResult results = gp.Execute("intersect_analysis", pVarArray, null) as IGeoProcessorResult;

            return(results);
        }
Пример #6
0
        /// <summary>
        /// Moves points or vertices to coincide exactly with the vertices, edges, or end points of other features.
        /// Snapping rules can be specified to control whether the input vertices are snapped to the nearest vertex, edge, or
        /// endpoint within a specified distance
        /// </summary>
        /// <param name="source">The input features whose vertices will be snapped to the vertices, edges, or end points of other
        /// features. The input features can be points, multipoints, lines, or polygons.</param>
        /// <param name="snap">The features that the input features' vertices will be snapped to. These features can be points,
        /// multipoints, lines, or polygons.</param>
        /// <param name="snapType">The type of feature part that the input features' vertices can be snapped to (END | VERTEX |
        /// EDGE).</param>
        /// <param name="distance">The distance within which the input features' vertices will be snapped to the nearest vertex,
        /// edge, or end point.</param>
        /// <param name="units">The units.</param>
        /// <param name="trackCancel">The track cancel.</param>
        /// <param name="eventHandler">The events.</param>
        public static void Snap(this IFeatureClass source, IFeatureClass snap, SnapType snapType, double distance, esriUnits units, ITrackCancel trackCancel, IGeoProcessorEvents eventHandler)
        {
            IUnitConverter converter = new UnitConverterClass();
            object         row       = string.Format("{0} {1} '{2} {3}'", snap.GetAbsolutePath(), snapType.ToString().ToUpperInvariant(), distance, converter.EsriUnitsAsString(units, esriCaseAppearance.esriCaseAppearanceUpper, true));

            IGpValueTableObject table = new GpValueTableObjectClass();

            table.SetColumns(3);
            table.AddRow(ref row);

            source.Snap(table, trackCancel, eventHandler);
        }
Пример #7
0
        private void btnIntersect_Click(object sender, EventArgs e)
        {
            IGpValueTableObject valTbl = new GpValueTableObjectClass();

            valTbl.SetColumns(2);
            object row  = "";
            object rank = 1;

            //row = inputFeatClass;
            row = pdicLayer[this.comboBoxEx1.SelectedItem.ToString()];
            valTbl.SetRow(0, ref row);
            valTbl.SetValue(0, 1, ref rank);

            //row = clipFeatClass;
            row = pdicLayer[this.comboBoxEx2.SelectedItem.ToString()];
            valTbl.SetRow(1, ref row);
            rank = 2;
            valTbl.SetValue(1, 1, ref rank);



            //构造Geoprocessor
            Geoprocessor gp = new Geoprocessor();

            gp.OverwriteOutput = true;
            //设置参数
            ESRI.ArcGIS.AnalysisTools.Intersect intersect = new ESRI.ArcGIS.AnalysisTools.Intersect();
            //intersect.in_features = @"F:\foshan\Data\wuqutu_b.shp;F:\foshan\Data\world30.shp";
            //intersect.in_features = this.comboBoxEx1.SelectedItem + ";" + this.comboBoxEx2.SelectedItem;
            //intersect.in_features = pdic[this.comboBoxEx1.SelectedItem.ToString()] + ";" + pdic[this.comboBoxEx2.SelectedItem.ToString()];
            intersect.in_features = valTbl;
            //intersect.out_feature_class = @"E:\intersect.shp";
            intersect.out_feature_class = this.textBoxX3.Text;
            intersect.join_attributes   = "ALL";
            intersect.output_type       = "INPUT";

            //执行Intersect工具
            //RunTool(gp, intersect, null);

            try
            {
                gp.Execute(intersect, null);
                //ReturnMessages(geoprocessor);
                MessageBox.Show("Intersect分析完成!");
            }
            catch (Exception err)
            {
                //Console.WriteLine(err.Message);
                MessageBox.Show(err.Message);
                //ReturnMessages(geoprocessor);
            }
        }
        /// <param name="pFeatureClass1">相交要素1</param>
        /// <param name="pFeatureClass2">相交要素2</param>
        /// <param name="gdbPath">数据库路径</param>
        private IFeatureClass Intersect(IFeatureClass pFeatureClass1, IFeatureClass pFeatureClass2, string gdbPath)
        {
            IFeatureClass pOutFeatureClass = null;

            try
            {
                //调用GP

                ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
                gp.OverwriteOutput = true;

                //多个对象的输入:使用IGpValueTableObject接口,该接口可以设置
                IGpValueTableObject vtobject = new GpValueTableObjectClass();
                object pFeature1             = pFeatureClass1;
                object pFeature2             = pFeatureClass2;
                vtobject.SetColumns(2);
                vtobject.AddRow(ref pFeature1);
                vtobject.AddRow(ref pFeature2);

                ESRI.ArcGIS.AnalysisTools.Intersect pIntersect = new ESRI.ArcGIS.AnalysisTools.Intersect();
                pIntersect.in_features       = vtobject;
                pIntersect.out_feature_class = System.Environment.CurrentDirectory + @"\temp\" + "temp.shp";
                pIntersect.output_type       = "Input";

                IGeoProcessorResult2 result = (IGeoProcessorResult2)gp.Execute(pIntersect, null);

                if (result.Status != ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded)
                {
                    MessageBox.Show("操作失败!");
                    return(null);
                }
                else
                {
                    //获取结果;
                    IFeatureClass resultFClass = gp.Open(result.ReturnValue) as IFeatureClass;
                    IDataset      pDataset     = resultFClass as IDataset;
                    //目标数据库;
                    IWorkspaceFactory factory         = new FileGDBWorkspaceFactoryClass();
                    IWorkspace        objectWorkspace = factory.OpenFromFile(gdbPath, 0);

                    string fileName = pFeatureClass1.AliasName + "_" + pFeatureClass2.AliasName;
                    pOutFeatureClass = IFeatureDataConverter_ConvertFeatureClass(pDataset.Workspace, objectWorkspace, pDataset.Name, fileName);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("操作失败!");
                return(null);
            }
            return(pOutFeatureClass);
        }
Пример #9
0
        private void btnIntersect_Click(object sender, EventArgs e)
        {//添加两个以上图层时才允许叠置
            if (this.axMapControl1.LayerCount < 2)
            {
                return;
            }
            ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
            //OverwriteOutput为真时,输出图层会覆盖当前文件夹下的同名图层
            gp.OverwriteOutput = true;
            //创建重置分析实例
            Intersect intersectTool = new Intersect();
            //获取mapcontrol中的前两个图层
            ILayer plnputLayer1 = this.axMapControl1.get_Layer(0);
            ILayer plnputLayer2 = this.axMapControl1.get_Layer(1);
            //转换为object类型
            object inputfeature1 = plnputLayer1;
            object inputfeature2 = plnputLayer2;
            //设置叠置分析的多个对象
            IGpValueTableObject pObject = new GpValueTableObjectClass();

            pObject.SetColumns(2);
            pObject.AddRow(ref inputfeature1);
            pObject.AddRow(ref inputfeature2);
            intersectTool.in_features = pObject;
            //设置输出路径
            string strTempPath   = @"D:\Temp";
            string strOutputPath = strTempPath + plnputLayer1.Name + "_" + plnputLayer2.Name + "_Intersect.shp";

            intersectTool.out_feature_class = strOutputPath;
            //执行叠置分析
            IGeoProcessorResult result = null;

            result = gp.Execute(intersectTool, null) as IGeoProcessorResult;
            //判断叠置分析是否成功
            if (result.Status != ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded)
            {
                MessageBox.Show("叠置求交失败!!");
            }
            else
            {
                MessageBox.Show("叠置求交成功!!");
                int index = strOutputPath.LastIndexOf("\\");
                this.axMapControl1.AddShapeFile(strOutputPath.Substring(0, index), strOutputPath.Substring(index));
            }
        }
Пример #10
0
        private IGeoProcessorResult IntersectOverlay(Geoprocessor gp)
        {
            IGpValueTableObject vtobject = new GpValueTableObjectClass();

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

            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);

            // Execute the Intersect tool.
            IGeoProcessorResult results = gp.Execute("intersect_analysis", pVarArray, null) as IGeoProcessorResult;

            return(results);
        }
Пример #11
0
        private IGeoProcessorResult BufferOverlayAnalysisOneLayer(string layerName, Geoprocessor gp)
        {
            //Intersect_analysis (in_features, out_feature_class, join_attributes, cluster_tolerance, output_type)
            txtMessages.Text += "输入图层: " + layerName + "\r\n";
            txtMessages.Text += "叠置图层: " + bufferedFeatureClassName + "\r\n";
            txtMessages.Text += "可能要较长时间,请稍候... " + "\r\n";

            IGpValueTableObject vtobject = new GpValueTableObjectClass();

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

            //row1 = layerName + " " + inputLevel.ToString();
            row1 = GetFeatureLayer(layerName);
            vtobject.AddRow(ref row1);
            object row2 = "";
            string outputFullOverlay = System.IO.Path.Combine(strOutputPath, bufferedFeatureClassName);

            row2 = outputFullOverlay + ".shp";
            vtobject.AddRow(ref row2);

            IVariantArray pVarArray = new VarArrayClass();

            pVarArray.Add(vtobject);
            //string outputFullPath = System.IO.Path.Combine(strOutputPath, layerName + "_" + bufferedFeatureClassName + "_" + "BufferOverlay.shp");
            string outputFullPath = System.IO.Path.Combine(strOutputPath, layerName + "_" + "BufferOverlay.shp");

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

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

            txtMessages.Text += layerName + "图层与" + bufferedFeatureClassName + "图层叠置处理完毕!" + "\r\n";

            return(results);
        }
Пример #12
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);
        }
Пример #13
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);
        }
Пример #14
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);
        }
Пример #15
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 += "叠置成功!";
            }
        }
Пример #17
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));
            }
        }