private bool ProjectFeatureClassHARNtoWGS(string SourceFeatures, string OutputFeatures, string OutputProjectionDefinitionFile) { ESRI.ArcGIS.esriSystem.IVariantArray geoprocessorVariantArray = null; PDX.BTS.DataMaintenance.MaintTools.GeneralUtilities generalUtilities = null; ESRI.ArcGIS.Geoprocessing.GeoProcessor projectDataGeoProcessor = null; try { // Let the user know what is happening. if (ProcessMessage != null) { ProcessMessage(" + Initializing the Projection Operation..."); } // Specify the parameters for the export of this Feature Class to the Output File Geodatabase. geoprocessorVariantArray = new ESRI.ArcGIS.esriSystem.VarArrayClass(); geoprocessorVariantArray.Add(SourceFeatures); geoprocessorVariantArray.Add(OutputFeatures); geoprocessorVariantArray.Add(OutputProjectionDefinitionFile); geoprocessorVariantArray.Add("NAD_1983_HARN_To_WGS_1984"); // Determine the ArcGIS Install Path so that the Projector Toolbox can be opened to be used. generalUtilities = new PDX.BTS.DataMaintenance.MaintTools.GeneralUtilities(); string installPath = generalUtilities.DetermineArcGISDesktopInstallPath(); // Make sure the Install Path was determined successfully before moving on. if (System.String.IsNullOrEmpty(installPath)) { // Let the user know that the ArcGIS Desktop Install Path could not be determined. if (ErrorMessage != null) { ErrorMessage("Could not Determine the ArcGIS Desktop Install Path to Initialize the Projection Toolbox. The MaintTools.FeatureClassUtilities.ProjectFeatureClassHARNtoWGS() Method failed!"); } // Return FALSE to the calling method to indicate that this method failed. return false; } // Instantiate the Geoprocessing Object that will be used to export this Annotatioin Feature Class to the Output File Geodatabase. projectDataGeoProcessor = new ESRI.ArcGIS.Geoprocessing.GeoProcessorClass(); projectDataGeoProcessor.AddToolbox(System.IO.Path.Combine(installPath, @"ArcToolbox\Toolboxes\Data Management Tools.tbx")); // Let the user know what is happening. if (ProcessMessage != null) { ProcessMessage(" + Performing the Projection Operation..."); } // Perform the Projection in a TRY Block so that any COM or IO Errors can be identified and handled. try { // Perform the export. projectDataGeoProcessor.Execute("Project_Management", geoprocessorVariantArray, null); // Write the messages from the Projection Tool to the process log file. if (ProcessMessage != null) { int toolMessageCount = projectDataGeoProcessor.MessageCount; int currentToolMessageIndex = 0; ProcessMessage(""); ProcessMessage(" + Project Feature Class Operation Messages..."); while (currentToolMessageIndex < toolMessageCount) { // Write the current message to the log file. ProcessMessage(" >> " + projectDataGeoProcessor.GetMessage(currentToolMessageIndex)); // Increment the Tool Message Index Counter. currentToolMessageIndex++; } } } catch (System.IO.IOException ioException) { // Determine the Line Number from which the exception was thrown. System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(ioException, true); System.Diagnostics.StackFrame stackFrame = stackTrace.GetFrame(stackTrace.FrameCount - 1); int lineNumber = stackFrame.GetFileLineNumber(); // Let the User know that the Dissolve Operation Failed. if (ErrorMessage != null) { ErrorMessage("The Project Feature Class Operation in the ProjectFeatureClassHARNtoWGS() Method Failed with error message - " + ioException.Message + " (" + ioException.Source + " Line: " + lineNumber.ToString() + ")!"); } // Return FALSE to the calling routine ito indicate that this process failed. return false; } catch (System.Runtime.InteropServices.COMException comException) { // Determine the Line Number from which the exception was thrown. System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(comException, true); System.Diagnostics.StackFrame stackFrame = stackTrace.GetFrame(stackTrace.FrameCount - 1); int lineNumber = stackFrame.GetFileLineNumber(); // Let the User know that the Dissolve Operation Failed. if (ErrorMessage != null) { ErrorMessage("The Project Feature Class Operation in the ProjectFeatureClassHARNtoWGS() Method Failed with error message - " + comException.Message + " (" + comException.ErrorCode + " Line: " + lineNumber.ToString() + ")!"); } // Return FALSE to the calling routine ito indicate that this process failed. return false; } } catch (System.Exception caught) { // Determine the Line Number from which the exception was thrown. System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(caught, true); System.Diagnostics.StackFrame stackFrame = stackTrace.GetFrame(stackTrace.FrameCount - 1); int lineNumber = stackFrame.GetFileLineNumber(); // Let the User know that this process failed. if (ErrorMessage != null) { ErrorMessage("The MaintTools.FeatureClassUtilities.ProjectFeatureClassHARNtoWGS() Method failed with error message: " + caught.Message + " (Line: " + lineNumber.ToString() + ")!"); } // Return FALSE to the calling routine to indicate that this process failed. return false; } finally { } // If the process made it to here it was successful so return TRUE to the calling method. return true; }
public bool ExportGeodatabaseAnnotationFeatureClassToFileGeoDB(ESRI.ArcGIS.Geodatabase.IFeatureWorkspace InputFeatureWorkspace, ESRI.ArcGIS.Geodatabase.IFeatureClass InputFeatureClass, string OutputFeatureClassName, string OutputFileGeoDBPath, string OutputFileGeoDBName) { ESRI.ArcGIS.Geodatabase.IWorkspace inputWorkspace = null; ESRI.ArcGIS.esriSystem.IPropertySet inputPropertySet = null; System.Type inputFactoryType = null; System.Object inputFactoryObject = null; ESRI.ArcGIS.Geodatabase.IWorkspaceFactory inputWorkspaceFactory = null; ESRI.ArcGIS.Geodatabase.IWorkspaceName inputWorkspaceName = null; ESRI.ArcGIS.Geodatabase.IDataset inputDataset = null; ESRI.ArcGIS.esriSystem.VarArray geoprocessorVariantArray = null; PDX.BTS.DataMaintenance.MaintTools.GeneralUtilities generalUtilities = null; ESRI.ArcGIS.Geoprocessing.GeoProcessor geoProcessor = null; try { // QI to the Input Workspace. inputWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)InputFeatureWorkspace; // Build a Property Set for the Current Workspace. inputPropertySet = new ESRI.ArcGIS.esriSystem.PropertySetClass(); inputPropertySet = inputWorkspace.ConnectionProperties; // The Folks at ESRI were not smart enough to handle a Property Set that did not include a Server Name so if there is not one in this propertyset dummy one in. if (inputPropertySet.GetProperty("Instance").ToString().ToUpper().IndexOf("SDE:SQLSERVER:") != -1) { // Determine the server name from the "Instance" Property of the Property Set. string inputServerName = inputPropertySet.GetProperty("Instance").ToString(); while (inputServerName.IndexOf(@":") != -1) { // Strip the first character from the Input Server Name. inputServerName = inputServerName.Substring(1); } // If the Server Name Includes an Instance Value, strip that from the server name. while (inputServerName.IndexOf(@"\") != -1) { // Strip the last character from the Input Server Name. inputServerName = inputServerName.Substring(0, (inputServerName.Length - 1)); } // Add a Server Property to the Property Set. inputPropertySet.SetProperty("Server", inputServerName); } // Determine which directory the Temporary SDE Connection File should be created in. string temporaryDirectory = null; if (System.IO.Directory.Exists(@"D:\Temp")) { // Set the Temporary Directory to 'D:\TEMP\'. temporaryDirectory = @"D:\Temp\"; } else { // Check to see if there is a 'C:\TEMP' Directory. if (System.IO.Directory.Exists(@"C:\Temp")) { // Set the Temporary Directory to 'C:\Temp\' temporaryDirectory = @"C:\Temp\"; } else { // Set the Temporary Directory to 'C:\'. temporaryDirectory = @"C:\"; } } // Make sure the Output Temporary Connection File does not already exist before attempting to create a new one. if (System.IO.File.Exists(temporaryDirectory + OutputFeatureClassName + "SDEConn.sde")) { // Delete the existing File. System.IO.File.Delete(temporaryDirectory + OutputFeatureClassName + "SDEConn.sde"); } // Create the Temporary SDE Connection File that will be used to specify the Input Annotation Features for this export operation. inputFactoryType = System.Type.GetTypeFromProgID("esriDataSourcesGDB.SDEWorkspaceFactory"); inputFactoryObject = System.Activator.CreateInstance(inputFactoryType); inputWorkspaceFactory = (ESRI.ArcGIS.Geodatabase.IWorkspaceFactory)inputFactoryObject; inputWorkspaceName = inputWorkspaceFactory.Create(temporaryDirectory, OutputFeatureClassName + "SDEConn.sde", inputPropertySet, 0); // Specify the parameters for the export of this Feature Class to the Output File Geodatabase. inputDataset = (ESRI.ArcGIS.Geodatabase.IDataset)InputFeatureClass; string processDatasetName = null; if (inputDataset.Name.IndexOf(inputWorkspaceName.ConnectionProperties.GetProperty("Database").ToString()) > -1) { // Drop the Server name from the Name before using it. processDatasetName = inputDataset.Name.Substring(inputWorkspaceName.ConnectionProperties.GetProperty("Database").ToString().Length + 1); } else { // Use the Name as is. processDatasetName = inputDataset.Name.ToString(); } // Create a Field Mapping for this export. string inputAnnotationFeatures = inputWorkspaceName.PathName.ToString() + @"\" + processDatasetName; ESRI.ArcGIS.Geoprocessing.IGPUtilities geoprocessingUtilities = new ESRI.ArcGIS.Geoprocessing.GPUtilitiesClass(); ESRI.ArcGIS.Geodatabase.IDETable inputTable = (ESRI.ArcGIS.Geodatabase.IDETable)geoprocessingUtilities.MakeDataElement(inputAnnotationFeatures, null, null); ESRI.ArcGIS.esriSystem.IArray inputTables = new ESRI.ArcGIS.esriSystem.ArrayClass(); inputTables.Add(inputTable); ESRI.ArcGIS.Geoprocessing.IGPFieldMapping fieldMapping = new ESRI.ArcGIS.Geoprocessing.GPFieldMappingClass(); // Go through the fields in the Input Table and add them to the Field Mapping. object missing = Type.Missing; for (int i = 0; i < inputTable.Fields.FieldCount; i++) { if ((inputTable.Fields.get_Field(i).Type != ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeOID) && (inputTable.Fields.get_Field(i).Type != ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeGeometry)) { ESRI.ArcGIS.Geoprocessing.IGPFieldMap currentFieldMap = new ESRI.ArcGIS.Geoprocessing.GPFieldMapClass(); currentFieldMap.AddInputField(inputTable, inputTable.Fields.get_Field(i), -1, -1); fieldMapping.AddFieldMap(currentFieldMap); currentFieldMap = null; } } // Build the Variant Array that will be used to pass the parameters necessary for the export to the toolbox object. geoprocessorVariantArray = new ESRI.ArcGIS.esriSystem.VarArrayClass(); geoprocessorVariantArray.Add(inputAnnotationFeatures); geoprocessorVariantArray.Add(System.IO.Path.Combine(OutputFileGeoDBPath, OutputFileGeoDBName + ".gdb")); geoprocessorVariantArray.Add(OutputFeatureClassName); geoprocessorVariantArray.Add(null); geoprocessorVariantArray.Add(fieldMapping); geoprocessorVariantArray.Add(null); // Determine the ArcGIS Install Path so that the Projector Toolbox can be opened to be used. generalUtilities = new PDX.BTS.DataMaintenance.MaintTools.GeneralUtilities(); string installPath = generalUtilities.DetermineArcGISDesktopInstallPath(); // Make sure the Install Path was determined successfully before moving on. if (System.String.IsNullOrEmpty(installPath)) { // Let the user know that the ArcGIS Desktop Install Path could not be determined. if (ErrorMessage != null) { ErrorMessage("Could not Determine the ArcGIS Desktop Install Path to Initialize the Projection Toolbox. The MaintTools.FeatureClassUtilities.ProjectFeatureClassHARNtoWGS() Method failed!"); } // Return FALSE to the calling method to indicate that this method failed. return false; } // Instantiate the Geoprocessing Object that will be used to export this Annotatioin Feature Class to the Output File Geodatabase. geoProcessor = new ESRI.ArcGIS.Geoprocessing.GeoProcessorClass(); geoProcessor.AddToolbox(System.IO.Path.Combine(installPath, @"ArcToolbox\Toolboxes\Conversion Tools.tbx")); // Perform the Export in a TRY Block so that any COM or IO Errors can be identified and handled. try { // Perform the export. geoProcessor.Execute("FeatureClassToFeatureClass_Conversion", geoprocessorVariantArray, null); // Write the messages from the Feature Class to Feature Class tool log file. int toolMessageCount = geoProcessor.MessageCount; int currentToolMessageIndex = 0; if (ProcessMessage != null) { ProcessMessage(" - Feature Class to Feature Class Operation Messages..."); } while (currentToolMessageIndex < toolMessageCount) { // Write the current message to the log file. if (ProcessMessage != null) { ProcessMessage(" + " + geoProcessor.GetMessage(currentToolMessageIndex)); } // Increment the Tool Message Index Counter. currentToolMessageIndex++; } } catch (System.IO.IOException ioException) { // Determine the Line Number from which the exception was thrown. System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(ioException, true); System.Diagnostics.StackFrame stackFrame = stackTrace.GetFrame(stackTrace.FrameCount - 1); int lineNumber = stackFrame.GetFileLineNumber(); // Let the User know that the Dissolve Operation Failed. if (ErrorMessage != null) { ErrorMessage("The Feature Class to Feature Class Operation in the MaintTools.FeatureClassUtilities.ExportGeodatabaseAnnotationFeatureClassToFileGeoDB() Method Failed with error message - " + ioException.Message + " (" + ioException.Source + " Line: " + lineNumber.ToString() + ")!"); } int toolMessageCount = geoProcessor.MessageCount; int currentToolMessageIndex = 0; if (ProcessMessage != null) { ProcessMessage("The information from the Geoprocessor is:"); } while (currentToolMessageIndex < toolMessageCount) { // Write the current message to the log file. if (ProcessMessage != null) { ProcessMessage(" + " + geoProcessor.GetMessage(currentToolMessageIndex)); } // Increment to Toold Message Index Counter. currentToolMessageIndex++; } // Return FALSE to the calling routine ito indicate that this process failed. return false; } catch (System.Runtime.InteropServices.COMException comException) { // Determine the Line Number from which the exception was thrown. System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(comException, true); System.Diagnostics.StackFrame stackFrame = stackTrace.GetFrame(stackTrace.FrameCount - 1); int lineNumber = stackFrame.GetFileLineNumber(); // Let the User know that the Dissolve Operation Failed. if (ErrorMessage != null) { ErrorMessage("The Feature Class to Feature Class Operation in the MaintTools.FeatureClassUtilities.ExportGeodatabaseAnnotationFeatureClassToFileGeoDB() Method Failed with error message - " + comException.Message + " (" + comException.ErrorCode + " Line: " + lineNumber.ToString() + ")!"); } int toolMessageCount = geoProcessor.MessageCount; int currentToolMessageIndex = 0; if (ProcessMessage != null) { ProcessMessage("The information from the Geoprocessor is:"); } while (currentToolMessageIndex < toolMessageCount) { // Write the current message to the log file. if (ProcessMessage != null) { ProcessMessage(" + " + geoProcessor.GetMessage(currentToolMessageIndex)); } // Increment to Toold Message Index Counter. currentToolMessageIndex++; } // Return FALSE to the calling routine ito indicate that this process failed. return false; } // Delete the SDE Connection File since it is no longer needed. if (System.IO.File.Exists(temporaryDirectory + OutputFeatureClassName + "SDEConn.sde")) { // Delete the existing File. System.IO.File.Delete(temporaryDirectory + OutputFeatureClassName + "SDEConn.sde"); } } catch (System.Exception caught) { // Determine the Line Number from which the exception was thrown. System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(caught, true); System.Diagnostics.StackFrame stackFrame = stackTrace.GetFrame(stackTrace.FrameCount - 1); int lineNumber = stackFrame.GetFileLineNumber(); // Let the User know that this process failed. if (ErrorMessage != null) { ErrorMessage("The MaintTools.FeatureClassUtilities.ExportGeodatabaseAnnotationFeatureClassToFileGeoDB() Method failed with error message: " + caught.Message + " (Line: " + lineNumber.ToString() + ")!"); } // Return FALSE to the calling routine to indicate that this process failed. return false; } finally { // If the Input Workspace Object has been Instantiated, close it. if (inputWorkspace != null) { // Close the Input Workspace Object. inputWorkspace = null; } // If the Input Property Set Object was instantiated, close it. if (inputPropertySet != null) { inputPropertySet = null; } // If the Input Factory Type Object was instantiated, close it. if (inputFactoryType != null) { inputFactoryType = null; } // If the Input Factory Object was instantiated, close it. if (inputFactoryObject != null) { inputFactoryObject = null; } // If the Input Workspace Factory Object was instantiated, close it. if (inputWorkspaceFactory != null) { inputWorkspaceFactory = null; } // If the Input Workspace Name Object was instantiated, close it. if (inputWorkspaceName != null) { inputWorkspaceName = null; } // If the Input Dataset name Object was instantiated, close it. if (inputDataset != null) { inputDataset = null; } // If the Geoprocessor Variant Array Object was instantiated, close it. if (geoprocessorVariantArray != null) { geoprocessorVariantArray.RemoveAll(); geoprocessorVariantArray = null; } // If the General Utilities Object was instantiated, close it. if (generalUtilities != null) { generalUtilities = null; } // If the Geoprocessor Object was instantiated, close it. if (geoProcessor != null) { geoProcessor = null; } } // If the process made it to here it was successful so return TRUE to the calling method. return true; }
/// <summary> /// Indexes the specified Field in the Feature Class. /// </summary> /// <param name="IndexFeatureClass"> /// An ESRI Geodatabase Feature Class Object for the Feature Class that contains the Field that is to be indexed. /// </param> /// <param name="IndexFieldName"> /// The Name of the Field in the Class that is to be indexed. /// </param> /// <returns> /// TRUE if the Field was successfully indexed. /// FALSE if the Field was not successfully indexed. /// </returns> public bool IndexedFieldInFeatureClass(ESRI.ArcGIS.Geodatabase.IFeatureClass IndexFeatureClass, string IndexFieldName) { PDX.BTS.DataMaintenance.MaintTools.GeneralUtilities generalUtilities = null; ESRI.ArcGIS.Geodatabase.ITable inputTable = null; ESRI.ArcGIS.esriSystem.VarArray geoprocessorVariantArray = null; ESRI.ArcGIS.Geoprocessing.IGeoProcessor geoprocessor = null; try { // If the specified Field exists in the Feature Class, index it. if (IndexFeatureClass.Fields.FindField(IndexFieldName) != -1) { // Instantiate the CGIS General Utilities Object that will be used to determine the ArcGIS Install Path on the server. generalUtilities = new PDX.BTS.DataMaintenance.MaintTools.GeneralUtilities(); // Determine the ArcGIS Install Path so that the Projector Toolbox can be opened to be used. generalUtilities = new PDX.BTS.DataMaintenance.MaintTools.GeneralUtilities(); string installPath = generalUtilities.DetermineArcGISDesktopInstallPath(); // Make sure the Install Path was determined successfully before moving on. if (System.String.IsNullOrEmpty(installPath)) { // Let the user know that the ArcGIS Desktop Install Path could not be determined. if (ErrorMessage != null) { ErrorMessage("Could not Determine the ArcGIS Desktop Install Path to Initialize the Projection Toolbox. The MaintTools.FeatureClassUtilities.IndexedFieldInFeatureClass() Method failed!"); } // Return FALSE to the calling method to indicate that this method failed. return false; } //QI to the Input Table. inputTable = (ESRI.ArcGIS.Geodatabase.ITable)IndexFeatureClass; // Build the Variant Array that will hold the parameters to be passed to the Geoprocessing Tool. geoprocessorVariantArray = new ESRI.ArcGIS.esriSystem.VarArrayClass(); geoprocessorVariantArray.Add(inputTable); geoprocessorVariantArray.Add(IndexFieldName); //geoprocessorVariantArray.Add(indexFeatureClassIndexField); geoprocessorVariantArray.Add(IndexFieldName + @"_idx"); geoprocessorVariantArray.Add("NON_UNIQUE"); geoprocessorVariantArray.Add("NON_ASCENDING"); // Instantiate the Geoprocessing Object that will be used to Index the Specified Field in the Feature Class. geoprocessor = new ESRI.ArcGIS.Geoprocessing.GeoProcessorClass(); geoprocessor.AddToolbox(System.IO.Path.Combine(installPath, @"ArcToolbox\Toolboxes\Data Management Tools.tbx")); // Perform the Index Field Operation in a TRY Block so that any COM or IO Errors can be identified and handled. try { // Perform the Add Index Operation. geoprocessor.Execute("AddIndex_Management", geoprocessorVariantArray, null); // Write the messages from the Add Index tool log file. int toolMessageCount = geoprocessor.MessageCount; int currentToolMessageIndex = 0; if (ProcessMessage != null) { ProcessMessage(" - Add Index Operation Messages..."); } while (currentToolMessageIndex < toolMessageCount) { // Write the current message to the log file. if (ProcessMessage != null) { ProcessMessage(" + " + geoprocessor.GetMessage(currentToolMessageIndex)); } // Increment the Tool Message Index Counter. currentToolMessageIndex++; } } catch (System.IO.IOException ioException) { // Determine the Line Number from which the exception was thrown. System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(ioException, true); System.Diagnostics.StackFrame stackFrame = stackTrace.GetFrame(stackTrace.FrameCount - 1); int lineNumber = stackFrame.GetFileLineNumber(); // Let the User know that the Add Index Operation Failed. if (ErrorMessage != null) { ErrorMessage("The Add Attribute Index Operation in the MaintTools.FeatureClassUtilities.IndexedFieldInFeatureClass() Method Failed with error message - " + ioException.Message + " (" + ioException.Source + " Line: " + lineNumber.ToString() + ")!"); } int toolMessageCount = geoprocessor.MessageCount; int currentToolMessageIndex = 0; if (ProcessMessage != null) { ProcessMessage("The information from the Geoprocessor is:"); } while (currentToolMessageIndex < toolMessageCount) { // Write the current message to the log file. if (ProcessMessage != null) { ProcessMessage(" + " + geoprocessor.GetMessage(currentToolMessageIndex)); } // Increment to Tool Message Index Counter. currentToolMessageIndex++; } // Return FALSE to the calling routine ito indicate that this process failed. return false; } catch (System.Runtime.InteropServices.COMException comException) { // Determine the Line Number from which the exception was thrown. System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(comException, true); System.Diagnostics.StackFrame stackFrame = stackTrace.GetFrame(stackTrace.FrameCount - 1); int lineNumber = stackFrame.GetFileLineNumber(); // Let the User know that the Dissolve Operation Failed. if (ErrorMessage != null) { ErrorMessage("The Add Attribute Index Operation in the MaintTools.FeatureClassUtilities.IndexedFieldInFeatureClass() Method Failed with error message - " + comException.Message + " (" + comException.ErrorCode + " Line: " + lineNumber.ToString() + ")!"); } int toolMessageCount = geoprocessor.MessageCount; int currentToolMessageIndex = 0; if (ProcessMessage != null) { ProcessMessage("The information from the Geoprocessor is:"); } while (currentToolMessageIndex < toolMessageCount) { // Write the current message to the log file. if (ProcessMessage != null) { ProcessMessage(" + " + geoprocessor.GetMessage(currentToolMessageIndex)); } // Increment to Tool Message Index Counter. currentToolMessageIndex++; } // Return FALSE to the calling routine ito indicate that this process failed. return false; } } else { // Let the user know that the Field does not exist in the Feature Class and will not be indexed. if (ProcessMessage != null) { ProcessMessage(" - The field - " + IndexFieldName.ToUpper() + " could not be found in the " + IndexFeatureClass.AliasName + " Feature Class and will not be indexed..."); } } } catch (System.Exception caught) { // Determine the Line Number from which the exception was thrown. System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(caught, true); System.Diagnostics.StackFrame stackFrame = stackTrace.GetFrame(stackTrace.FrameCount - 1); int lineNumber = stackFrame.GetFileLineNumber(); // Let the User know that this method failed. if (ErrorMessage != null) { ErrorMessage("The MaintTools.FeatureClassUtilities.IndexedFieldInFeatureClass() Method failed with error message - " + caught.Message + " (Line: " + lineNumber.ToString() + ")!"); } // Return FALSE to the calling Method to indicate that this Method failed. return false; } finally { // If the Geoprocessor Object was instantiated, close it. if (geoprocessor != null) { geoprocessor = null; } // If the Geoprocessor Variant Array Object was instantiated, close it. if (geoprocessorVariantArray != null) { geoprocessorVariantArray = null; } // If the Input Table Object was instantiated, close it. if (inputTable != null) { inputTable = null; } // If the CGIS Data Maintenance General Utilities Object was instantiated, close it. if (generalUtilities != null) { generalUtilities = null; } } // If the process made it to here, it was successful so return a "TRUE" to the calling method. return true; }
/// <summary> /// Deletes all features from the specified feature class. /// </summary> /// <param name="DeleteFeatureClass"> /// An Object Pointer to the Feature Class that is to be emptied. /// </param> /// <returns> /// TRUE if the features were successfully deleted. /// FALSE if the process failed to delete the features from the dataset. /// </returns> public bool EmptyGeodatabaseFeatureClass(ESRI.ArcGIS.Geodatabase.IFeatureClass DeleteFeatureClass) { PDX.BTS.DataMaintenance.MaintTools.GeneralUtilities generalUtilities = null; ESRI.ArcGIS.esriSystem.IVariantArray geoprocessorVariantArray = null; ESRI.ArcGIS.Geoprocessing.IGeoProcessor geoProcessor = null; try { // Determine the ArcGIS Install Path so that the Data Management Toolbox can be opened to be used. generalUtilities = new PDX.BTS.DataMaintenance.MaintTools.GeneralUtilities(); string installPath = generalUtilities.DetermineArcGISDesktopInstallPath(); // Make sure the Install Path was determined successfully before moving on. if (System.String.IsNullOrEmpty(installPath)) { // Let the user know that the ArcGIS Desktop Install Path could not be determined. if (ErrorMessage != null) { ErrorMessage("Could not Determine the ArcGIS Desktop Install Path to Initialize the Data Management Toolbox. The MaintTools.FeatureClassUtilities.EmptyGeodatabaseFeatureClass() Method failed!"); } // Return FALSE to the calling method to indicate that this method failed. return false; } // Build the Variant Array that will be used to pass the parameters necessary for the delete to the toolbox object. geoprocessorVariantArray = new ESRI.ArcGIS.esriSystem.VarArrayClass(); geoprocessorVariantArray.Add(DeleteFeatureClass); // Instantiate the Geoprocessing Object that will be used to delete the features from the feature class. geoProcessor = new ESRI.ArcGIS.Geoprocessing.GeoProcessorClass(); geoProcessor.AddToolbox(System.IO.Path.Combine(installPath, @"ArcToolbox\Toolboxes\Data Management Tools.tbx")); // Perform the Export in a TRY Block so that any COM or IO Errors can be identified and handled. try { // Perform the export. geoProcessor.Execute("DeleteFeatures_management", geoprocessorVariantArray, null); // Write the messages from the Delete Features tool log file. int toolMessageCount = geoProcessor.MessageCount; int currentToolMessageIndex = 0; if (ProcessMessage != null) { ProcessMessage(" - Delete Features Operation Messages..."); } while (currentToolMessageIndex < toolMessageCount) { // Write the current message to the log file. if (ProcessMessage != null) { ProcessMessage(" + " + geoProcessor.GetMessage(currentToolMessageIndex)); } // Increment the Tool Message Index Counter. currentToolMessageIndex++; } } catch (System.IO.IOException ioException) { // Determine the Line Number from which the exception was thrown. System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(ioException, true); System.Diagnostics.StackFrame stackFrame = stackTrace.GetFrame(stackTrace.FrameCount - 1); int lineNumber = stackFrame.GetFileLineNumber(); // Let the User know that the Delete Features Operation Failed. if (ErrorMessage != null) { ErrorMessage("The Delete Features Operation in the MaintTools.FeatureClassUtilities.EmptyGeodatabaseFeatureClass() Method Failed with error message - " + ioException.Message + " (" + ioException.Source + " Line: " + lineNumber.ToString() + ")!"); } int toolMessageCount = geoProcessor.MessageCount; int currentToolMessageIndex = 0; if (ProcessMessage != null) { ProcessMessage("The information from the Geoprocessor is:"); } while (currentToolMessageIndex < toolMessageCount) { // Write the current message to the log file. if (ProcessMessage != null) { ProcessMessage(" + " + geoProcessor.GetMessage(currentToolMessageIndex)); } // Increment to Toold Message Index Counter. currentToolMessageIndex++; } // Return FALSE to the calling routine ito indicate that this process failed. return false; } catch (System.Runtime.InteropServices.COMException comException) { // Determine the Line Number from which the exception was thrown. System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(comException, true); System.Diagnostics.StackFrame stackFrame = stackTrace.GetFrame(stackTrace.FrameCount - 1); int lineNumber = stackFrame.GetFileLineNumber(); // Let the User know that the Delete Features Operation Failed. if (ErrorMessage != null) { ErrorMessage("The Delete Features Operation in the MaintTools.FeatureClassUtilities.EmptyGeodatabaseFeatureClass() Method Failed with error message - " + comException.Message + " (" + comException.ErrorCode + " Line: " + lineNumber.ToString() + ")!"); } int toolMessageCount = geoProcessor.MessageCount; int currentToolMessageIndex = 0; if (ProcessMessage != null) { ProcessMessage("The information from the Geoprocessor is:"); } while (currentToolMessageIndex < toolMessageCount) { // Write the current message to the log file. if (ProcessMessage != null) { ProcessMessage(" + " + geoProcessor.GetMessage(currentToolMessageIndex)); } // Increment to Toold Message Index Counter. currentToolMessageIndex++; } // Return FALSE to the calling routine ito indicate that this process failed. return false; } } catch (System.Exception caught) { // Determine the Line Number from which the exception was thrown. System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(caught, true); System.Diagnostics.StackFrame stackFrame = stackTrace.GetFrame(stackTrace.FrameCount - 1); int lineNumber = stackFrame.GetFileLineNumber(); // Let the User know that this process failed. if (ErrorMessage != null) { ErrorMessage("The MaintTools.FeatureClassUtilities.EmptyGeodatabaseFeatureClass() Method failed with error message: " + caught.Message + " (Line: " + lineNumber.ToString() + ")!"); } // Return FALSE to the calling routine to indicate that this process failed. return false; } finally { // If the Geoprocessor Object was instantiated, close it. if (geoProcessor != null) { geoProcessor = null; } // If the Geoprocessor Variant Array Object was instantiated, close it. if (geoprocessorVariantArray != null) { geoprocessorVariantArray = null; } // If the BTS General Utilities Object was instantiated, close it. if (generalUtilities != null) { generalUtilities = null; } } // If the process made it to here, it was successful so return TRUE to the calling method. return true; }