static void Main(string[] args)
        {
            // Load the product code and version to the version manager
            ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop);

            //ESRI License Initializer generated code.
            m_AOLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeAdvanced },
                                                         new esriLicenseExtensionCode[] { });

            // Create geoprocessor. Overwrite true will replace existing output
            IGeoProcessor2 gp = new GeoProcessorClass();

            gp.OverwriteOutput = true;

            // Get the workspace from the user
            Console.WriteLine("Enter the path to folder where you copied the data folder.");
            Console.WriteLine("Example: C:\\AirportsAndGolf\\data");
            Console.Write(">");
            string wks = Console.ReadLine();

            // set the workspace to the value user entered
            gp.SetEnvironmentValue("workspace", wks + "\\" + "golf.gdb");

            // Add the custom toolbox to geoprocessor
            gp.AddToolbox(wks + "\\" + "Find Golf Courses.tbx");

            // Create a variant - data are in the workspace
            IVariantArray parameters = new VarArrayClass();

            parameters.Add("Airports");
            parameters.Add("8 Miles");
            parameters.Add("Golf");
            parameters.Add("GolfNearAirports");

            object sev = null;

            try
            {
                gp.Execute("GolfFinder", parameters, null);
                Console.WriteLine(gp.GetMessages(ref sev));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                string errorMsgs = gp.GetMessages(ref sev);
                Console.WriteLine(errorMsgs);
            }
            finally
            {
                Console.WriteLine("Hit Enter to quit");
                Console.ReadLine(); // pause the console to see messages
            }

            //ESRI License Initializer generated code.
            //Do not make any call to ArcObjects after ShutDownApplication()
            m_AOLicenseInitializer.ShutdownApplication();
        }
        static void Main(string[] args)
        {
            // Load the product code and version to the version manager
            ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop);

            //ESRI License Initializer generated code.
            m_AOLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeAdvanced },
            new esriLicenseExtensionCode[] { });

            // Create geoprocessor. Overwrite true will replace existing output
            IGeoProcessor2 gp = new GeoProcessorClass();
            gp.OverwriteOutput = true;

            // Get the workspace from the user
            Console.WriteLine("Enter the path to folder where you copied the data folder.");
            Console.WriteLine("Example: C:\\AirportsAndGolf\\data");
            Console.Write(">");
            string wks = Console.ReadLine();

            // set the workspace to the value user entered
            gp.SetEnvironmentValue("workspace", wks + "\\" + "golf.gdb");

            // Add the custom toolbox to geoprocessor
            gp.AddToolbox(wks + "\\" + "Find Golf Courses.tbx");

            // Create a variant - data are in the workspace
            IVariantArray parameters = new VarArrayClass();
            parameters.Add("Airports");
            parameters.Add("8 Miles");
            parameters.Add("Golf");
            parameters.Add("GolfNearAirports");

            object sev = null;

            try
            {
                gp.Execute("GolfFinder", parameters, null);
                Console.WriteLine(gp.GetMessages(ref sev));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                string errorMsgs = gp.GetMessages(ref sev);
                Console.WriteLine(errorMsgs);
            }
            finally
            {
                Console.WriteLine("Hit Enter to quit");
                Console.ReadLine(); // pause the console to see messages
            }

            //ESRI License Initializer generated code.
            //Do not make any call to ArcObjects after ShutDownApplication()
            m_AOLicenseInitializer.ShutdownApplication();
        }
Exemplo n.º 3
0
        //执行GP的数据修复功能
        //田晶添加20080916
        //修改,提高效率
        //靳军杰2011-11-30
        /// <summary>
        /// 修复面图层自相交错误
        /// </summary>
        /// <param name="sPath"></param>
        /// <returns></returns>
        public bool FeatureRepair(string sPath)
        {
            if (string.IsNullOrEmpty(sPath))
            {
                return(false);
            }

            IGeoProcessor pGP = new GeoProcessorClass();

            try
            {
                //GT_CARTO.XApplication.ProgressBar.ShowGifProgress(null);
                //GT_CARTO.XApplication.ProgressBar.ShowHint("正在预处理地类图斑数据...");
                //string sPath = pWks.PathName;
                pGP.OverwriteOutput = true;
                pGP.SetEnvironmentValue("workspace", (object)sPath);

                IGpEnumList pfds = pGP.ListFeatureClasses("", "Polygon", "Dataset");

                string sFeatClsName = pfds.Next();

                //IGeoProcessorResult pResult;

                while (!string.IsNullOrEmpty(sFeatClsName))
                {
                    if (!sFeatClsName.Contains("_Standard") &&
                        !sFeatClsName.Equals("TK", StringComparison.OrdinalIgnoreCase))
                    {
                        //要修复的FeatureClass路径
                        string        sInFeatureClassPath = string.Format("{0}\\dataset\\{1}", sPath, sFeatClsName);
                        IVariantArray pValues             = new VarArrayClass();
                        pValues.Add(sInFeatureClassPath);
                        pGP.Execute("RepairGeometry", pValues, null);
                        object obj = 2;
                        //GT_CONST.LogAPI.CheckLog.AppendErrLogs(pGP.GetMessages(ref obj));
                    }
                    sFeatClsName = pfds.Next();
                }
                return(true);
            }

            catch (Exception exp)
            {
                Hy.Common.Utility.Log.OperationalLogManager.AppendMessage(exp.ToString());

                //GT_CARTO.XApplication.ProgressBar.Hide();
                return(false);
            }
            finally
            {
                //GT_CARTO.XApplication.ProgressBar.Hide();
                Marshal.ReleaseComObject(pGP);
            }
        }
        public static void CopyFeatures(IFeatureClass feaCls)
        {
            IGeoProcessor2 geoProcessor2 = new GeoProcessorClass();
            geoProcessor2.OverwriteOutput = true;
            geoProcessor2.SetEnvironmentValue("workspace", @"e:\GP\California.gdb");

            IVariantArray parameters = new VarArrayClass();
            parameters.Add("Lakes");
            parameters.Add("origin_copy");

            geoProcessor2.Execute("CopyFeatures_management", parameters, null);
        }
Exemplo n.º 5
0
        //执行GP的数据修复功能
        //田晶添加20080916
        //修改,提高效率
        //靳军杰2011-11-30
        /// <summary>
        /// 修复面图层自相交错误
        /// </summary>
        /// <param name="sPath"></param>
        /// <returns></returns>
        public bool FeatureRepair(string sPath)
        {
            if (string.IsNullOrEmpty(sPath))
            {
                return false;
            }

            IGeoProcessor pGP = new GeoProcessorClass();
            try
            {
                //GT_CARTO.XApplication.ProgressBar.ShowGifProgress(null);
                //GT_CARTO.XApplication.ProgressBar.ShowHint("正在预处理地类图斑数据...");
                //string sPath = pWks.PathName;
                pGP.OverwriteOutput = true;
                pGP.SetEnvironmentValue("workspace", (object)sPath);

                IGpEnumList pfds = pGP.ListFeatureClasses("", "Polygon", "Dataset");

                string sFeatClsName = pfds.Next();

                //IGeoProcessorResult pResult;

                while (!string.IsNullOrEmpty(sFeatClsName))
                {
                    if (!sFeatClsName.Contains("_Standard") &&
                        !sFeatClsName.Equals("TK", StringComparison.OrdinalIgnoreCase))
                    {
                        //要修复的FeatureClass路径
                        string sInFeatureClassPath = string.Format("{0}\\dataset\\{1}", sPath, sFeatClsName);
                        IVariantArray pValues = new VarArrayClass();
                        pValues.Add(sInFeatureClassPath);
                        pGP.Execute("RepairGeometry", pValues, null);
                        object obj = 2;
                        //GT_CONST.LogAPI.CheckLog.AppendErrLogs(pGP.GetMessages(ref obj));
                    }
                    sFeatClsName = pfds.Next();
                }
                return true;
            }

            catch (Exception exp)
            {
                Hy.Common.Utility.Log.OperationalLogManager.AppendMessage(exp.ToString());

                //GT_CARTO.XApplication.ProgressBar.Hide();
                return false;
            }
            finally
            {
                //GT_CARTO.XApplication.ProgressBar.Hide();
                Marshal.ReleaseComObject(pGP);
            }
        }