Example #1
0
        private void iToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Initialize the geoprocessor.
            IGeoProcessor2 gp = new GeoProcessorClass();

            gp.OverwriteOutput = true;
            // Add the BestPath toolbox.
            gp.AddToolbox(tbxPath);

            // Generate the array of parameters.
            IVariantArray parameters = new VarArrayClass();

            parameters.Add(FileGDBPath + "\\LotIds");
            parameters.Add("100 Feet");
            parameters.Add(FileGDBPath + "\\LotIds_BufferCustomArray1");


            object sev = null;

            try
            {
                // Execute the model tool by name.
                gp.Execute("Model2", parameters, null);

                Console.WriteLine(gp.GetMessages(ref sev));
            }
            catch (Exception ex)
            {
                // Print geoprocessing execution error messages.
                Console.WriteLine(gp.GetMessages(ref sev));
            }
        }
Example #2
0
        private void iVariantArray方式ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IGeoProcessor2 gp = new GeoProcessorClass();

            gp.OverwriteOutput = true;

            IGeoProcessorResult result = new GeoProcessorResultClass();

            // Create a variant array to hold the parameter values.
            IVariantArray parameters = new VarArrayClass();

            object sev = null;

            try
            {
                // Populate the variant array with parameter values.
                parameters.Add(FileGDBPath + "\\LotIds");
                parameters.Add(FileGDBPath + "\\LotIds_BufferArray");
                parameters.Add("100 Feet");

                // Execute the tool.
                result = gp.Execute("Buffer_analysis", parameters, null);

                // Print geoprocessring messages.
                Console.WriteLine(gp.GetMessages(ref sev));
            }

            catch (Exception ex)
            {
                // Print a generic exception message.
                Console.WriteLine(ex.Message);
                // Print geoprocessing execution error messages.
                Console.WriteLine(gp.GetMessages(ref sev));
            }
        }
        public static void BufferAnalysis(IFeatureClass feacls,string dist)
        {
            IGeoProcessor2 gp = new GeoProcessorClass();
            gp.OverwriteOutput = true;

            IGeoProcessorResult result = new GeoProcessorResultClass();

            //gp.SetEnvironmentValue("workspace", @"e:\data");

            IVariantArray vararr = new VarArrayClass();
            object sev = null;
            try
            {
                vararr.Add(feacls);
                vararr.Add(@"e:\data\wwwwwww.shp");
                vararr.Add(dist);

                result = gp.Execute("Buffer_analysis", vararr, null);

                while (result.Status == esriJobStatus.esriJobExecuting)
                    Thread.Sleep(1000);

                MessageBox.Show(gp.GetMessages(ref sev));
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
                MessageBox.Show(gp.GetMessages(ref sev));
            }
        }
        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();
        }
Example #5
0
        private void btn_CalibrateRoute_Click(object sender, EventArgs e)
        {
            // Create the geoprocessor.
            IGeoProcessor2 gp = new GeoProcessorClass();

            gp.OverwriteOutput = true;

            IGeoProcessorResult result = new GeoProcessorResultClass();

            // Create a variant array to hold the parameter values.
            IVariantArray parameters = new VarArrayClass();

            object sev = null;

            string wholeName = RouteBox.Text;

            string[] arrayName = wholeName.Split('\\');
            string   gdbName   = arrayName.GetGDBPath();
            string   outName   = gdbName + "\\test\\CalibrateRoute2";

            Console.WriteLine(outName);

            try
            {
                // Populate the variant array with parameter values.
                parameters.Add(@RouteBox.Text);
                parameters.Add("ProjectID");
                parameters.Add(PointBox.Text);
                parameters.Add("SvyLineID");
                parameters.Add("distance");
                parameters.Add(@outName);

                // Execute the tool.
                result = gp.Execute("CalibrateRoutes_lr ", parameters, null);

                // Wait until the execution completes.
                while (result.Status == esriJobStatus.esriJobExecuting)
                {
                    Thread.Sleep(1000);
                }
                // Wait for 1 second.

                // Print geoprocessring messages.
                Console.WriteLine(gp.GetMessages(ref sev));
            }

            catch (Exception ex)
            {
                // Print a generic exception message.
                Console.WriteLine(ex.Message);

                // Print geoprocessing execution error messages.
                Console.WriteLine(gp.GetMessages(ref sev));
            }
            MessageBox.Show("线性参考完成!");
        }
        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();
        }
Example #7
0
        /// <summary>
        /// 拷贝要素类
        /// </summary>
        /// <param name="sourcePath">需要拷贝的要素类路径</param>
        /// <param name="targetPath">拷贝要素类的路径</param>
        static private IFeatureClass CopyFeatureClass(string sourcePath, string targetPath)
        {
            Console.WriteLine("拷贝要素类");
            IWorkspace        workspace;
            IFeatureWorkspace featureWorkspace;
            IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactoryClass();
            string            path_dir         = System.IO.Path.GetDirectoryName(targetPath);

            workspace        = workspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(targetPath), 0);
            featureWorkspace = workspace as IFeatureWorkspace;

            if (File.Exists(targetPath))                                                         //存在该路径,则在文件夹中找到文件并删除
            {
                string        fileName = System.IO.Path.GetFileNameWithoutExtension(targetPath); //文件名称
                DirectoryInfo root     = new DirectoryInfo(path_dir);
                foreach (FileInfo f in root.GetFiles())
                {
                    if (f.Name.Split('.')[0] == fileName)
                    {
                        string filepath = f.FullName;
                        File.Delete(filepath);
                    }
                }
            }

            //拷贝要素类
            IGeoProcessor2 gp = new GeoProcessorClass();

            gp.OverwriteOutput = true;
            IGeoProcessorResult result     = new GeoProcessorResultClass();
            IVariantArray       parameters = new VarArrayClass();
            object sev = null;

            try
            {
                parameters.Add(sourcePath);
                parameters.Add(targetPath);
                result = gp.Execute("Copy_management", parameters, null);
                Console.WriteLine(gp.GetMessages(ref sev));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(gp.GetMessages(ref sev));
            }

            string        name         = System.IO.Path.GetFileName(targetPath);
            IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(name);

            return(featureClass);
        }