コード例 #1
0
        /// <summary>
        /// Run the Geoprocessing model
        /// </summary>
        /// <param name="modelParametersHybridDictionary">A HybridDictionary that contains all of the arguments to run the model</param>
        /// <returns>A message of how well the model executed</returns>
        /// <remarks></remarks>
        public static System.String ExecuteCustomGeoprocessingFunction(System.Collections.Specialized.HybridDictionary modelParametersHybridDictionary)
        {
            try
            {
                // Create a Geoprocessor object
                ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();

                // Set the OverwriteOutput setting to True
                gp.OverwriteOutput = true;

                // Create a new instance of our custom model
                MYCUSTOMTOOLBOX.GolfFinder myModel = new MYCUSTOMTOOLBOX.GolfFinder();

                // Set the custom models parameters.
                myModel.BufferDistance             = modelParametersHybridDictionary["BufferDistance"];
                myModel.AIRPORT                    = modelParametersHybridDictionary["Airports"];
                myModel.GOLF                       = modelParametersHybridDictionary["Golf"];
                myModel.AirportBuffer              = modelParametersHybridDictionary["AirportBuffer"];
                myModel.Golf_Courses_Near_Airports = modelParametersHybridDictionary["GolfNearAirports"];

                // Execute the model and obtain the result from the run
                ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult geoProcessorResult = (ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult)gp.Execute(myModel, null);

                if (geoProcessorResult == null)
                {
                    // We have an error running the model.
                    // If the run fails a Nothing (VB.NET) or null (C#) is returned from the gp.Execute
                    object sev      = 2;
                    string messages = gp.GetMessages(ref sev);
                    return(messages);
                }
                else
                {
                    // The model completed successfully
                    return("Output successful. The shapefiles are locacted at: " + geoProcessorResult.ReturnValue.ToString());
                }
            }
            catch (Exception ex)
            {
                // Catch any other errors
                return("Error running the model. Debug the application and test again.");
            }
        }
コード例 #2
0
        public bool CopyFeatures(string InFeatureClass, string OutFeatureClass, bool Messages = false)
        {
            ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
            gp.OverwriteOutput = true;
            IGeoProcessorResult myresult = new GeoProcessorResultClass();
            object sev = null;

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

            // Populate the variant array with parameter values.
            parameters.Add(InFeatureClass);
            parameters.Add(OutFeatureClass);

            // Execute the tool.
            try
            {
                myresult = (IGeoProcessorResult)gp.Execute("CopyFeatures_management", parameters, null);
                // Wait until the execution completes.
                while (myresult.Status == esriJobStatus.esriJobExecuting)
                    Thread.Sleep(1000);
                    // Wait for 1 second.
                if (Messages)
                {
                    MessageBox.Show("Process complete");
                }
                gp = null;
                return true;
            }
            catch (Exception ex)
            {
                if (Messages)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    MessageBox.Show(gp.GetMessages(ref sev));
                }
                gp = null;
                return false;
            }
        }
コード例 #3
0
        /// <summary>
        /// Run the Geoprocessing model
        /// </summary>
        /// <param name="modelParametersHybridDictionary">A HybridDictionary that contains all of the arguments to run the model</param>
        /// <returns>A message of how well the model executed</returns>
        /// <remarks></remarks>
        public static System.String ExecuteCustomGeoprocessingFunction(System.Collections.Specialized.HybridDictionary modelParametersHybridDictionary)
        {

            try
            {

                // Create a Geoprocessor object
                ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();

                // Set the OverwriteOutput setting to True
                gp.OverwriteOutput = true;

                // Create a new instance of our custom model
                MYCUSTOMTOOLBOX.GolfFinder myModel = new MYCUSTOMTOOLBOX.GolfFinder();

                // Set the custom models parameters.
                myModel.BufferDistance = modelParametersHybridDictionary["BufferDistance"];
                myModel.AIRPORT = modelParametersHybridDictionary["Airports"];
                myModel.GOLF = modelParametersHybridDictionary["Golf"];
                myModel.AirportBuffer = modelParametersHybridDictionary["AirportBuffer"];
                myModel.Golf_Courses_Near_Airports = modelParametersHybridDictionary["GolfNearAirports"];

                // Execute the model and obtain the result from the run
                ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult geoProcessorResult = (ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult)gp.Execute(myModel, null);

                if (geoProcessorResult == null)
                {
                    // We have an error running the model. 
                    // If the run fails a Nothing (VB.NET) or null (C#) is returned from the gp.Execute
                    object sev = 2;
                    string messages = gp.GetMessages(ref sev);
                    return messages;
                }
                else
                {
                    // The model completed successfully
                    return "Output successful. The shapefiles are locacted at: " + geoProcessorResult.ReturnValue.ToString();
                }

            }
            catch (Exception ex)
            {
                // Catch any other errors
                return "Error running the model. Debug the application and test again.";
            }

        }