Beispiel #1
0
        public static void BufferAnalysis(IFeatureLayer layer, string path, double radius, string radius_unit)
        {
            Geoprocessor gp = new Geoprocessor();
                      gp.OverwriteOutput = true;

                        //create a new instance of a buffer tool
            ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer(layer, path, Convert.ToString(radius) + " " + radius_unit);

                                                          //ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer(layer, this.OutputPath, "100"+" "+"Meters" );
                                                          //以下这些设置,那么选择要素呢??。。
                        buffer.dissolve_option = "ALL";   //这个要设成ALL,否则相交部分不会融合
                      buffer.line_side         = "FULL";  //默认是"FULL",最好不要改否则出错
                     buffer.line_end_type      = "ROUND"; //默认是"ROUND",最好不要改否则出错

                                                          //execute the buffer tool (very easy :-))
                        IGeoProcessorResult results = null;
                        try
                            {
                                    results = (IGeoProcessorResult)gp.Execute(buffer, null);
                                    MessageBox.Show("缓冲区建立成功!");

                               
                }
                        catch (Exception ex)
                            {
                                    MessageBox.Show("缓冲区建立失败!");

                                   // txtMessages.Text += "Failed to buffer layer: " + layer.Name + "\r\n";
                               
                }
        }
Beispiel #2
0
 /// <summary>
 /// Raster导入GDB
 /// </summary>
 /// <param name="in_Raster">输入Raster</param>
 /// <param name="gdb_Path">库完整路径</param>
 /// <param name="rst_Name">库内文件名</param>
 /// <param name="result">运行结果</param>
 /// <returns></returns>
 public static bool ImportRasterToGDB(IRaster in_Raster, string gdb_Path, string rst_Name, out string result)
 {
     try
     {
         ESRI.ArcGIS.DataManagementTools.CopyRaster cr = new ESRI.ArcGIS.DataManagementTools.CopyRaster();
         cr.in_raster         = in_Raster;
         cr.out_rasterdataset = gdb_Path + "/" + GetNameGDB(gdb_Path, rst_Name);
         cr.background_value  = 0;
         Geoprocessor gp = new Geoprocessor();
         gp.OverwriteOutput = true;
         IGeoProcessorResult gpr = gp.Execute(cr, null) as IGeoProcessorResult;
         if (gpr != null && gpr.Status == esriJobStatus.esriJobSucceeded)
         {
             result = "Success";
             return(true);
         }
         else
         {
             result = "Failure";
             return(false);
         }
     }
     catch (Exception e)
     {
         result = e.Message;
         return(false);
     }
 }
Beispiel #3
0
 /// <summary>
 /// FeatureClass导入GDB
 /// </summary>
 /// <param name="in_features">输入FeatureClass</param>
 /// <param name="gdb_Path">库完整路径</param>
 /// <param name="feat_Name">库内文件名</param>
 /// <param name="result">运行结果</param>
 /// <returns></returns>
 public static bool ImportFeaturesToGDB(IFeatureClass in_features, string gdb_Path, string feat_Name, out string result)
 {
     try
     {
         ESRI.ArcGIS.DataManagementTools.CopyFeatures cfs = new ESRI.ArcGIS.DataManagementTools.CopyFeatures();
         cfs.in_features       = in_features;
         cfs.out_feature_class = gdb_Path + "//" + GetNameGDB(gdb_Path, feat_Name);
         Geoprocessor gp = new Geoprocessor();
         gp.OverwriteOutput = true;
         IGeoProcessorResult gpr = gp.Execute(cfs, null) as IGeoProcessorResult;
         if (gpr != null && gpr.Status == esriJobStatus.esriJobSucceeded)
         {
             result = "Success";
             return(true);
         }
         else
         {
             result = "Failure";
             return(false);
         }
     }
     catch (Exception e)
     {
         result = e.Message;
         return(false);
     }
 }
        public virtual bool Execute(Geoprocessor gp)
        {
            if (gp == null)
            {
                gp = new Geoprocessor();
            }

            bool rbc = false;

            gp.OverwriteOutput = true;
            gp.AddOutputsToMap = false;
            //输入参数 end
            gp.ClearMessages();
            IGeoProcessorResult results = (IGeoProcessorResult)gp.Execute(this.Process, null);

            if (results != null && results.Status == esriJobStatus.esriJobSucceeded)
            {
                object sf = new object();
                Message += gp.GetMessages(ref sf);
                rbc      = true;
            }
            else
            {
                Message = "执行失败.";
                object sf = new object();
                Message += gp.GetMessages(ref sf);
                rbc      = false;
            }
            if (gp != null)
            {
                gp = null;
            }
            return(rbc);
        }
Beispiel #5
0
        public bool RunTool(string toolName, IVariantArray parameters, ITrackCancel TC, bool showResultDialog)
        {
            GeoProcessor        gp     = new GeoProcessor();
            IGeoProcessorResult result = null;

            // Execute the tool
            try
            {
                result = (IGeoProcessorResult)gp.Execute(toolName, parameters, TC);
                string re = result.GetOutput(0).GetAsText();
                if (showResultDialog)
                {
                    ReturnMessages(result, "");
                }
                if (result.MaxSeverity == 2) //error
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            catch (COMException err)
            {
                MessageBox.Show(err.Message + " in RunTool");
                ReturnMessages(result, "");
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message + " in RunTool");
                ReturnMessages(result, "");
            }
            return(false);
        }
Beispiel #6
0
        private IGeoProcessorResult EraseOverlay(Geoprocessor gp)
        {
            //Erase_analysis (in_features, erase_features, out_feature_class, cluster_tolerance)
            ESRI.ArcGIS.AnalysisTools.Erase erase = new ESRI.ArcGIS.AnalysisTools.Erase();
            IFeatureLayer inputLayer = GetFeatureLayer(strInputLayer);

            erase.in_features = inputLayer;
            IFeatureLayer eraseLayer = GetFeatureLayer(strOverLayer);

            erase.erase_features = eraseLayer;
            string outputFullPath = System.IO.Path.Combine(strOutputPath, strInputLayer + "_" + strOverLayer + "_" + "Erase.shp");

            erase.out_feature_class = outputFullPath;
            erase.cluster_tolerance = tolerance;

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

            //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 + "_" + "Erase.shp");
            //pVarArray.Add(outputFullPath);
            //pVarArray.Add(tolerance);

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

            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);
        }
Beispiel #8
0
        private IGeoProcessorResult UnionOverlay2(Geoprocessor gp)
        {
            //Union_analysis (in_features, out_feature_class, join_attributes, cluster_tolerance, gaps)

            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 + "_" + "Union");

            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);
        }
        // Skapar aspektlager.
        public IRasterLayer createAspect(System.String inRaster, System.String outPath)
        {
            if (aspect != null)
            {
                return(aspect);
            }

            IRasterLayer rLayer = new RasterLayer();

            if (inRaster == "" || outPath == "")
            {
                MessageBox.Show("Check your rasters");
            }
            else
            {
                Geoprocessor gp = new Geoprocessor();
                gp.OverwriteOutput = true;
                //gp.AddOutputsToMap = false;

                Aspect aspectTool = new Aspect();
                aspectTool.in_raster  = inRaster;
                aspectTool.out_raster = outPath;

                IGeoProcessorResult geoProcessorResult = (IGeoProcessorResult)gp.Execute(aspectTool, null);
                rLayer.CreateFromFilePath(outPath);
                aspect = rLayer;
            }
            return(rLayer);
        }
Beispiel #11
0
        private void button1_Click(object sender, EventArgs e)
        {
            Geoprocessor gp = new Geoprocessor();

            gp.OverwriteOutput = true;
            gp.AddOutputsToMap = true;
            //DisplayEnvironmentPameters(gp);
            IGeoProcessorResult results = null;

            results = UnionOverlay1(gp);

            try
            {
                //将结果添加到当前地图中
                FileInfo info = new FileInfo(outputFullPath);
                string   path = outputFullPath.Substring(0, outputFullPath.Length - info.Name.Length);
                axMapControl1.AddShapeFile(path, info.Name);
                axMapControl1.Refresh(esriViewDrawPhase.esriViewGeography, null, null);
                this.Close();
            }
            catch (Exception ee)
            {
                MessageBox.Show("出错:" + ee.Message);
            }
        }
Beispiel #12
0
            //注册要素类
            /// <summary>
            /// 返回true说明FeatureClass存在,返回false说明不存在,重新创建
            /// </summary>
            /// <param name="IN_ShapePath"></param>
            /// <returns></returns>
            private bool PRV_AddFeatureClass(string IN_ShapePath)
            {
                string            Temp_Direction         = System.IO.Path.GetDirectoryName(IN_ShapePath);            //该Shp文件的目录
                string            Temp_Name              = System.IO.Path.GetFileNameWithoutExtension(IN_ShapePath); //该Shp文件的名称
                IWorkspaceFactory Temp_ShapeWorkFactory  = new ShapefileWorkspaceFactory();
                IFeatureWorkspace Temp_ShapeWorkspace    = Temp_ShapeWorkFactory.OpenFromFile(Temp_Direction, 0) as IFeatureWorkspace;
                IWorkspaceFactory Temp_AccessWorkFactory = new AccessWorkspaceFactory();
                IFeatureWorkspace Temp_Workspace         = Temp_AccessWorkFactory.OpenFromFile(S_MDBFile, 0) as IFeatureWorkspace;

                IFeatureClassContainer tem_FeatureClassContainer = (IFeatureClassContainer)FDS_Featuredataset;
                IEnumFeatureClass      pEnumFeatureClass         = (IEnumFeatureClass)tem_FeatureClassContainer.Classes;
                IFeatureClass          tem_FeatureClass          = pEnumFeatureClass.Next();

                while (null != tem_FeatureClass)
                {
                    if (Temp_Name == tem_FeatureClass.AliasName)
                    {// return true;
                    }
                    tem_FeatureClass = pEnumFeatureClass.Next();
                }

                IFeatureClass Temp_FeatureClass        = Temp_ShapeWorkspace.OpenFeatureClass(Temp_Name);
                FeatureClassToFeatureClass Temp_FCToFC = new FeatureClassToFeatureClass(IN_ShapePath, S_MDBFile + "\\" + FDS_Featuredataset.Name, Temp_Name);//将Shp文件导入要素数据集

                GP_Progress = GP_Tool.ExecuteAsync(Temp_FCToFC);
                TH_TimeSpan = new Thread(PRV_GetStatus);//开辟线程计时
                TH_TimeSpan.Start();
                TH_TimeSpan.Join();

                return(false);
                // IFeatureClassContainer ss = (FDS_Featuredataset.Workspace as IFeatureWorkspace).OpenFeatureDataset(FDS_Featuredataset.Name) as IFeatureClassContainer;
                //  Console.WriteLine("完成");
            }
Beispiel #13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="inFeaClass"></param>
        /// <param name="clipFeaClass"></param>
        /// <param name="outFeaClass"></param>
        /// <param name="sMsg"></param>
        /// <returns></returns>
        public bool ExtractByMask(string inFeaClass, string clipFeaClass, string outFeaClass, out string sMsg)
        {
            sMsg = string.Empty;
            bool result;

            try
            {
                //Geoprocessor GP = new Geoprocessor();
                // GP.OverwriteOutput = true;
                ESRI.ArcGIS.SpatialAnalystTools.ExtractByMask MaskTool = new ESRI.ArcGIS.SpatialAnalystTools.ExtractByMask();
                MaskTool.in_raster    = inFeaClass;
                MaskTool.in_mask_data = clipFeaClass;
                MaskTool.out_raster   = outFeaClass;
                //GP.Execute(MaskTool,null);
                //return true;
                IGeoProcessorResult geoProcessorResult = this.m_gp.Execute(MaskTool, null) as IGeoProcessorResult;
                sMsg += GetGPMessages(this.m_gp);
                if (geoProcessorResult.Status == esriJobStatus.esriJobSucceeded)
                {
                    sMsg  += "裁剪成功!";
                    result = true;
                }
                else
                {
                    sMsg  += "裁剪失败!";
                    result = false;
                }
            }
            catch (Exception ex)
            {
                sMsg   = sMsg + "抛出异常!" + ex.Message;
                result = false;
            }
            return(result);
        }
Beispiel #14
0
        private void simpleButton4_Click(object sender, EventArgs e)
        {
            if (this.comboBoxEditInputRaster2.Text.ToString() == "" || this.comboBoxEditOutputRaster.Text.ToString() == "")
            {
                MessageBox.Show("请输入参数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            string strResultsDBPath = m_pGDBHelper.GetResultsDBPath();

            if (Utilities.GDBUtilites.CheckNameExist(strResultsDBPath, this.comboBoxEditOutputRaster.Text.ToString()) == false)
            {
                //执行R2V分析
                ILayer pInputLayer1 = null;

                for (int i = 0; i < m_pMapCtrl.LayerCount; i++)
                {
                    if (m_pMapCtrl.get_Layer(i).Name == this.comboBoxEditInputRaster2.Text.ToString())
                    {
                        pInputLayer1 = m_pMapCtrl.get_Layer(i);
                    }
                }

                if (pInputLayer1 != null)
                {
                    IRasterLayer pRasterLayer1 = pInputLayer1 as IRasterLayer;

                    IGeoProcessor2 pGP = new GeoProcessorClass();
                    pGP.AddToolbox(m_pGDBHelper.GetToolboxPath());

                    IVariantArray gpParameters = new VarArrayClass();
                    gpParameters.Add(pRasterLayer1.Raster);

                    gpParameters.Add(m_pGDBHelper.GetResultsDBPath() + "\\" + this.comboBoxEditOutputRaster.Text.ToString());

                    IGeoProcessorResult pGeoProcessorResult = pGP.Execute("Raster2Vector", gpParameters, null);
                    if (pGeoProcessorResult.Status == esriJobStatus.esriJobSucceeded)
                    {
                        if (this.checkBox1.Checked)
                        {
                            //IWorkspaceFactory2 pWKF = new FileGDBWorkspaceFactoryClass();
                            //IFeatureL pFW = (IFeatureWorkspace)pWKF.OpenFromFile(m_pGDBHelper.GetResultsDBPath() + "\\" + this.comboBoxEditOutputRaster.Text.ToString(), 0);
                            //IRasterWorkspaceEx pRasterWKEx = (IRasterWorkspaceEx)pWKF.OpenFromFile(m_pGDBHelper.GetResultsDBPath(), 0);
                            //IRasterDataset3 pRasterDataset = pRasterWKEx.OpenRasterDataset(this.comboBoxEditOutputRaster.Text.ToString()) as IRasterDataset3;

                            //Utilities.MapUtilites.AddRasterLayer(m_pMapCtrl.ActiveView, pRasterDataset, null);
                        }
                        MessageBox.Show("转换完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                MessageBox.Show("已存在同名数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
        }
        public static void ClipRaster(string inRaster, string inClipFeature, string outTempRaster)
        {
            Clip clipTool = new Clip();

            //set clip parameters
            clipTool.in_raster  = inRaster;
            clipTool.out_raster = outTempRaster;

            //clip extent
            clipTool.in_template_dataset = inClipFeature;

            Geoprocessor gp = new Geoprocessor();

            gp.OverwriteOutput = true;
            gp.AddOutputsToMap = false;

            try
            {
                IGeoProcessorResult result = (IGeoProcessorResult)gp.ExecuteAsync(clipTool);

                while (result.Status != esriJobStatus.esriJobSucceeded)
                {
                    //Console.WriteLine(result.Status.ToString());
                    System.Threading.Thread.Sleep(100);
                }
            }
            catch (Exception ex)
            {
                object level = 0;
                Console.WriteLine(gp.GetMessages(ref level));
                Console.WriteLine(" Failed to clip raster using ESRI clip tool " + ex.Message);
            }
        }
Beispiel #16
0
        private void EraseRun(IFeatureClass in_features, IFeatureClass erase_features, object out_feature_class)
        {
//            IAoInitialize m_AoInitialize = new AoInitializeClass();
//            esriLicenseStatus licenseStatus = esriLicenseStatus.esriLicenseUnavailable;
//
//            licenseStatus = m_AoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);


            Erase erase = new Erase()
            {
                in_features       = in_features,
                erase_features    = erase_features,
                out_feature_class = out_feature_class
            };

            Geoprocessor processor = new Geoprocessor();

            processor.OverwriteOutput = true;



            try
            {
                IGeoProcessorResult result = processor.Execute(erase, new TrackCancelClass()) as IGeoProcessorResult;
            }
            catch (Exception e)
            {
                Show(e.ToString());
                throw;
            }
        }
Beispiel #17
0
        private IGeoProcessorResult CreateBuffer(Geoprocessor gp)
        {
            strBufferLayer = cboBufferLayer.Text;
            //Buffer_analysis (in_features, out_feature_class, buffer_distance_or_field, line_side, line_end_type, dissolve_option, dissolve_field)
            ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer();
            IFeatureLayer bufferLayer = GetFeatureLayer(strBufferLayer);

            buffer.in_features = bufferLayer;


            string outputFullPath = System.IO.Path.Combine(strOutputPath, textBox1.Text);

            buffer.out_feature_class        = outputFullPath;
            buffer.buffer_distance_or_field = bufferDistanceField + " " + (string)comboBox1.SelectedItem;

            buffer.line_side       = strSideType;
            buffer.line_end_type   = strEndType;
            buffer.dissolve_option = strDissolveType;
            buffer.dissolve_field  = strDissolveFields;

            IGeoProcessorResult results          = (IGeoProcessorResult)gp.Execute(buffer, null);
            IFeatureLayer       pOutputFeatLayer = new FeatureLayerClass();

            outputFeatureName = textBox1.Text;


            FileInfo info = new FileInfo(outputFeatureName);
            string   path = outputFeatureName.Substring(0, outputFeatureName.Length - info.Name.Length);

            axMapControl1.AddShapeFile(path, info.Name);
            axMapControl1.Refresh(esriViewDrawPhase.esriViewGeography, null, null);

            return(results);
        }
Beispiel #18
0
        private static bool RunTool(IGPProcess process, ITrackCancel TC, out IEnumerable <string> messages)
        {
            if (gp == null)
            {
                gp = new Geoprocessor
                {
                    AddOutputsToMap = false
                };

                gp.SetEnvironmentValue(environmentName, temporaryWorkspace);
            }

            gp.OverwriteOutput = true; // Set the overwrite output option to true
            bool result = true;

            try
            {
                IGeoProcessorResult pResult = (IGeoProcessorResult)gp.Execute(process, null);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                result = false;
            }

            messages = ReturnMessages(gp).ToArray();
            return(result);
        }
Beispiel #19
0
        /// <summary>
        /// 传输矢量
        /// </summary>
        /// <param name="task"></param>
        public static void CopyFeatures(string sourceFileName, string destFileName, RenameMode renameMode)
        {
            FeatureReadHelper inputReadHelper            = new FeatureReadHelper(sourceFileName);
            FeatureReadHelper outputReadHelper           = new FeatureReadHelper(destFileName);
            string            outputNameWithoutExtention = string.Empty;

            if (renameMode.Equals(RenameMode.Overwrite))
            {
                outputReadHelper.Delete(outputReadHelper.NameWithoutExtension + outputReadHelper.Extension);
                outputNameWithoutExtention = outputReadHelper.NameWithoutExtension;
            }
            else
            {
                outputNameWithoutExtention = inputReadHelper.AccumulativeName;
            }

            ESRI.ArcGIS.DataManagementTools.CopyFeatures CpyFeat = new ESRI.ArcGIS.DataManagementTools.CopyFeatures(sourceFileName, outputReadHelper.Directory + "\\" + outputNameWithoutExtention);
            Geoprocessor gp = new Geoprocessor();

            gp.OverwriteOutput = true;
            IGeoProcessorResult gpResult = gp.Execute(CpyFeat, null) as IGeoProcessorResult;

            if (gpResult == null || gpResult.Status == esriJobStatus.esriJobFailed)
            {
                for (int i = 0; i < gpResult.MessageCount; i++)
                {
                    MessageBox.Show(gpResult.GetMessage(i));
                }
            }
        }
Beispiel #20
0
        private IGeoProcessorResult CreateBuffer(Geoprocessor gp)
        {
            txtMessages.Text += "Creating Buffer: " + "\r\n";
            txtMessages.Update();
            ESRI.ArcGIS.AnalysisTools.Buffer buffer = new ESRI.ArcGIS.AnalysisTools.Buffer();
            IFeatureLayer bufferLayer = GetFeatureLayer(strBufferLayer);

            buffer.in_features       = bufferLayer;
            bufferedFeatureClassName = strBufferLayer + "_" + "Buffer";
            string outputFullPath = System.IO.Path.Combine(strOutputPath, bufferedFeatureClassName);

            buffer.out_feature_class        = outputFullPath;
            buffer.buffer_distance_or_field = bufferDistanceField;
            buffer.line_side       = strSideType;
            buffer.line_end_type   = strEndType;
            buffer.dissolve_option = strDissolveType;
            buffer.dissolve_field  = strDissolveFields;
            IGeoProcessorResult results = (IGeoProcessorResult)gp.Execute(buffer, null);

            buffer            = null;
            txtMessages.Text += ReturnMessages(gp);
            txtMessages.Text += "Buffer Created! " + "\r\n";
            ScrollToBottom(txtMessages);
            txtMessages.Update();
            return(results);
        }
Beispiel #21
0
        private IFeatureClass RunProcessGetFeatureClass(IGPProcess inProcess, ITrackCancel inCancel, string ignoreMessage)
        {
            IFeatureClass       fc     = null;
            IQueryFilter        qf     = null;
            IGeoProcessorResult result = null;
            IGPUtilities        util   = null;

            try
            {
                string toolbox = inProcess.ToolboxName;
                mLog.Debug("inside run process");
                mLog.Debug("the process I want to run is " + inProcess.ToolName);
                mLog.Debug("the tool box is " + toolbox);
                myProcessor.OverwriteOutput = true;
                result = (IGeoProcessorResult)myProcessor.Execute(inProcess, null);
                ReturnMessages(myProcessor);
                //if result is null then there are no viable areas
                if (result != null)
                {
                    util = new GPUtilitiesClass();
                    util.DecodeFeatureLayer(result.GetOutput(0), out fc, out qf);
                    ReturnMessages(myProcessor, ignoreMessage);
                }
            }
            catch (Exception ex)
            {
                eLog.Debug(ex);
                ReturnMessages(myProcessor);
            }
            return(fc);
        }
 public void createVoronoiDiagram(string layername)
 {
     try
     {
         Geoprocessor gp = new Geoprocessor();
         gp.OverwriteOutput = false;
         IFeatureClass pInputFeatureClass = ChkMarkPoint.getFeatureLayer(layername).FeatureClass;
         MessageBox.Show("Choose the Save File of Voronoi Diagram");
         AutoChooseFile acf          = new AutoChooseFile();
         string         saveFilePath = acf.saveFullPathName();
         //CreateThiessenPolygons pCTP = new CreateThiessenPolygons(pInputFeatureClass, @"F:\Voronoi Land Cover\LC Voronoi.shp");
         CreateThiessenPolygons pCTP = new CreateThiessenPolygons(pInputFeatureClass, @saveFilePath);
         pCTP.fields_to_copy = "ALL";
         IGeoProcessorResult pGPR = gp.Execute(pCTP, null) as IGeoProcessorResult;
         for (int i = 0; i < gp.MessageCount; i++)
         {
             ChkMarkPoint.changeText(gp.GetMessage(i));
         }
         //IFeatureClass pOutFeatureClass = gp.Open(pGPR.ReturnValue) as IFeatureClass;
         //IFeatureLayer pFeatureLayer = new FeatureLayerClass();
         //pFeatureLayer.Name = "Voronoi";
         //pFeatureLayer.FeatureClass = pOutFeatureClass;
         //ChkMarkPoint.Mapcontr.Map.AddLayer(pFeatureLayer as ILayer);
         //ChkMarkPoint.Mapcontr.Refresh();
     }
     catch (System.Exception e)
     {
         ChkMarkPoint.changeText(e.Message);
     }
 }
Beispiel #23
0
        public bool SetNoData(string inRaster, int excludeValue, string outRaster, out string msg)
        {
            msg = string.Empty;
            bool result = true;
            //IGeoDataset geoDataSet = null;
            IGeoProcessorResult geoProcessorResult = null;

            try
            {
                ESRI.ArcGIS.SpatialAnalystTools.SetNull setNull = new ESRI.ArcGIS.SpatialAnalystTools.SetNull();
                //geoDataSet = EngineAPI.OpenRasterFile(inRaster) as IGeoDataset;
                setNull.in_conditional_raster       = inRaster;
                setNull.in_false_raster_or_constant = inRaster;
                setNull.where_clause = "VALUE <> " + excludeValue;
                setNull.out_raster   = outRaster;
                //geoProcessorResult = this.m_gp.Execute(setNull, null) as IGeoProcessorResult;
                //msg += GetGPMessages(this.m_gp);
                //Geoprocessor m_gp = new Geoprocessor() { OverwriteOutput = true };
                geoProcessorResult = m_gp.Execute(setNull, null) as IGeoProcessorResult;
                msg += GetGPMessages(m_gp);
                if (geoProcessorResult.Status != esriJobStatus.esriJobSucceeded)
                {
                    result = false;
                }
                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                Marshal.ReleaseComObject(geoProcessorResult);
            }
        }
Beispiel #24
0
        /// <summary>
        /// GP cal area
        /// </summary>
        /// <param name="inFile">输入shp</param>
        /// <param name="outFile">输出shp</param>
        public bool CalArea(string inFile, string outFile, out string msg)
        {
            msg = string.Empty;
            bool result = true;
            IGeoProcessorResult geoProcessorResult = null;

            try
            {
                ESRI.ArcGIS.SpatialStatisticsTools.CalculateAreas pCalArea = new ESRI.ArcGIS.SpatialStatisticsTools.CalculateAreas();
                pCalArea.Input_Feature_Class  = inFile;
                pCalArea.Output_Feature_Class = outFile;
                //this.m_gp.Execute(pCalArea, null);
                ////geoProcessorResult = this.m_gp.Execute(pCalArea, null) as IGeoProcessorResult;
                //msg += GetGPMessages(this.m_gp);
                //Geoprocessor m_gp = new Geoprocessor() { OverwriteOutput = true };
                geoProcessorResult = m_gp.Execute(pCalArea, null) as IGeoProcessorResult;
                msg += GetGPMessages(m_gp);
                if (geoProcessorResult.Status != esriJobStatus.esriJobSucceeded)
                {
                    result = false;
                }
                return(result);
            }
            catch (Exception ex)
            {
                throw new Exception("统计面积失败:\r\n" + ex.Message);
            }
            finally
            {
                //if (geoProcessorResult != null)
                //    Marshal.ReleaseComObject(geoProcessorResult);
            }
        }
        private IGeoProcessorResult UnionOverlay(Geoprocessor gp)
        {
            IGpValueTableObject vtobject = new GpValueTableObject()
                                           as IGpValueTableObject;

            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);
        }
Beispiel #26
0
        public bool ZonalStatistics(string inZone, string zoneField, string inValue, string staticType, string outFile, out string msg)
        {
            msg = string.Empty;
            bool result = true;
            //IGeoDataset geoDataSet = null;
            IGeoProcessorResult geoProcessorResult = null;

            try
            {
                ESRI.ArcGIS.SpatialAnalystTools.ZonalStatistics zonal = new ESRI.ArcGIS.SpatialAnalystTools.ZonalStatistics();
                zonal.in_zone_data    = inZone;
                zonal.zone_field      = zoneField;
                zonal.in_value_raster = inValue;
                zonal.statistics_type = staticType;
                zonal.out_raster      = outFile;
                geoProcessorResult    = m_gp.Execute(zonal, null) as IGeoProcessorResult;
                msg += GetGPMessages(m_gp);
                if (geoProcessorResult.Status != esriJobStatus.esriJobSucceeded)
                {
                    result = false;
                }
                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                Marshal.ReleaseComObject(geoProcessorResult);
            }
        }
        private IGeoProcessorResult IntersectOverlay(Geoprocessor gp)
        {
            IGpValueTableObject vtobject = new GpValueTableObject()
                                           as IGpValueTableObject;

            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);
            IGeoProcessorResult results = gp.Execute(
                "intersect_analysis", pVarArray, null) as IGeoProcessorResult;

            return(results);
        }
Beispiel #28
0
        /// <param name="pFeatureClass">融合要素</param>
        /// <param name="dissField">融合字段</param>
        private IFeatureClass Dissolve(IFeatureClass pFeatureClass, string dissField)
        {
            IFeatureClass pOutFeatureClass = null;

            try
            {
                if (this.gp == null)
                {
                    this.gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
                }

                ESRI.ArcGIS.DataManagementTools.Dissolve pDissolve = new ESRI.ArcGIS.DataManagementTools.Dissolve();
                this.gp.OverwriteOutput     = true;
                pDissolve.in_features       = pFeatureClass;
                pDissolve.dissolve_field    = dissField;
                pDissolve.out_feature_class = System.Environment.CurrentDirectory + @"\temp\Dissolve.shp";
                pDissolve.multi_part        = "true"; //跨区域融合;
                IGeoProcessorResult result = (IGeoProcessorResult)gp.Execute(pDissolve, null);

                if (result.Status != ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded)
                {
                    return(null);
                }
                else
                {
                    pOutFeatureClass = this.gp.Open(result.ReturnValue) as IFeatureClass;
                }
            }
            catch (System.Exception ex)
            {
                return(null);
            }
            return(pOutFeatureClass);
        }
Beispiel #29
0
        /// <summary>
        /// Copies the feature class.
        /// </summary>
        /// <param name="inputPaths">The input paths.</param>
        /// <param name="outPutPath">The out put path.</param>
        /// <param name="outputHasMValues"></param>
        /// <param name="outputHasZValues"></param>
        /// <returns></returns>
        public IGeoProcessorResult CopyFeatureClass(string inputPaths, string outPutPath, bool outputHasZValues, bool outputHasMValues)
        {
            try
            {
                CopyFeatures pCopyFeature = new CopyFeatures(inputPaths, outPutPath);
                Geoprocessor GP           = new Geoprocessor();
                GP.OverwriteOutput    = true;
                GP.TemporaryMapLayers = false;


                if (outputHasZValues)
                {
                    object obj = GP.GetEnvironmentValue("OutputZFlag"); //设置Output has Z Values
                    GP.SetEnvironmentValue("OutputZFlag", "DEFAULT");
                }

                if (outputHasMValues)
                {
                    object obj = GP.GetEnvironmentValue("OutputMFlag");                    //设置Output has M Values
                    GP.SetEnvironmentValue("OutputMFlag", "DEFAULT");
                }

                IGeoProcessorResult result = GP.Execute(pCopyFeature, null) as IGeoProcessorResult;
                //GT_CONST.LogAPI.CheckLog.AppendErrLogs(result.Status.ToString());
                //GT_CONST.LogAPI.CheckLog.AppendErrLogs(result.GetMessages(0));
                return(result);
            }
            catch (Exception exp)
            {
                Hy.Common.Utility.Log.OperationalLogManager.AppendMessage(exp.ToString());

                return(null);
            }
        }
Beispiel #30
0
        /// <summary>
        /// 栅格传输
        /// </summary>
        /// <param name="task"></param>
        public static void CopyRaster(TransferTask task)
        {
            RasterReadHelper inputReadHelper            = new RasterReadHelper(task.SourceFileName);
            RasterReadHelper outputReadHelper           = new RasterReadHelper(task.DestFileName);
            string           outputNameWithoutExtention = string.Empty;

            if (task.RenameMode.Equals(RenameMode.Overwrite))
            {
                outputReadHelper.Delete(outputReadHelper.NameWithoutExtension + outputReadHelper.Extension);
                outputNameWithoutExtention = outputReadHelper.NameWithoutExtension;
            }
            else
            {
                outputNameWithoutExtention = inputReadHelper.AccumulativeName;
            }

            ESRI.ArcGIS.DataManagementTools.CopyRaster CpyRst = new ESRI.ArcGIS.DataManagementTools.CopyRaster(task.SourceFileName, outputReadHelper.Directory + "\\" + outputNameWithoutExtention);
            Geoprocessor gp = new Geoprocessor();

            gp.SetEnvironmentValue("Compression", inputReadHelper.RstDs.CompressionType);
            gp.OverwriteOutput = true;
            IGeoProcessorResult gpResult = gp.Execute(CpyRst, null) as IGeoProcessorResult;

            if (gpResult == null || gpResult.Status == esriJobStatus.esriJobFailed)
            {
                for (int i = 0; i < gpResult.MessageCount; i++)
                {
                    MessageBox.Show(gpResult.GetMessage(i));
                }
            }
        }
 public string getMessages(IGeoProcessorResult result)
 {
     StringBuilder x = new StringBuilder();
     for (int i = 0; i < result.MessageCount; i++)
     {
         x.AppendLine(result.GetMessage(i));
     }
     return x.ToString();
 }
 public string getOutput(IGeoProcessorResult result, int index)
 {
     return result.GetOutput(index).GetAsText();
 }
 public int getOutputCount(IGeoProcessorResult result)
 {
     return result.OutputCount;
 }
 /// <summary>
 /// Returns all geoprocessing messages
 /// </summary>
 /// <param name="gpRslt">the geoprocessign result</param>
 /// <returns>a string of all messages</returns>
 private string getMessages(IGeoProcessorResult gpRslt)
 {
     StringBuilder sB = new StringBuilder();
     for (int i = 0; i < gpRslt.MessageCount; i++)
     {
         sB.Append(gpRslt.GetMessage(i));
     }
     return sB.ToString();
 }