/// <summary> /// /// </summary> /// <param name="sShapeFile"></param> /// <param name="sShakeMapID"></param> /// <param name="sFileGDB"></param> /// <param name="sTargetFCName"></param> public bool ImportShapeFileToGeoDB(string sShapeFile, string sShakeMapID, string sFileGDB, string sTargetFCName, StringDictionary sdeSD) { IWorkspace pWS = null; IFeatureClass targetFC; ArcObjects pArcObjects = new ArcObjects(); FileInfo fi; IFeatureClass sourceFC; IFeatureCursor sourceCursor = null; try { // Initialize License m_AOLicenseInitializer = new LicenseInitializer(); m_AOLicenseInitializer.InitializeApplication(new ESRI.ArcGIS.esriSystem.esriLicenseProductCode[] { ESRI.ArcGIS.esriSystem.esriLicenseProductCode.esriLicenseProductCodeEngine }, new ESRI.ArcGIS.esriSystem.esriLicenseExtensionCode[] { }); // Get workspace from FGDB or SDE if (sFileGDB.Length > 0) { pWS = pArcObjects.FileGdbWorkspaceFromPath(sFileGDB); } else { IPropertySet pPropSet = new PropertySetClass(); pPropSet.SetProperty("SERVER", sdeSD["SERVER"]); pPropSet.SetProperty("INSTANCE", sdeSD["INSTANCE"]); pPropSet.SetProperty("DATABASE", sdeSD["DATABASE"]); pPropSet.SetProperty("USER", sdeSD["USER"]); pPropSet.SetProperty("PASSWORD", sdeSD["PASSWORD"]); pPropSet.SetProperty("VERSION", sdeSD["VERSION"]); pWS = pArcObjects.ConnectToTransactionalVersion(pPropSet); } // Make sure we have workspace if (pWS == null) { return(false); } // Get target feature class targetFC = pArcObjects.GetFeatureClass(pWS, sTargetFCName); // Make sure we have target feature class if (targetFC == null) { return(false); } // Set FileInfo object to shape file fi = new FileInfo(sShapeFile); // Make sure we have fileInfo object if (fi == null) { return(false); } // Parse out ShapeFile name without extension string sShapeFileName = fi.Name.Substring(0, fi.Name.Length - (fi.Name.Length - fi.Name.LastIndexOf('.'))); // Get source featue class from shape file sourceFC = GetFeatureClassFromShapefileOnDisk(fi.DirectoryName, sShapeFileName); // Set source feature cursor. sourceCursor = sourceFC.Search(null, false); // Insert features InsertFeaturesUsingCursor(targetFC, sourceCursor, sShakeMapID); return(true); } catch (Exception ex) { return(false); } finally { System.Runtime.InteropServices.Marshal.ReleaseComObject(sourceCursor); sourceCursor = null; System.Runtime.InteropServices.Marshal.ReleaseComObject(pWS); pWS = null; //Do not make any call to ArcObjects after ShutDownApplication() if (m_AOLicenseInitializer != null) { m_AOLicenseInitializer.ShutdownApplication(); } m_AOLicenseInitializer = null; GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); } }
/// <summary> /// /// </summary> /// <param name="sShapeFile"></param> /// <param name="sShakeMapID"></param> /// <param name="sFileGDB"></param> /// <param name="sTargetFCName"></param> public bool ImportShapeFileToGeoDB(string sShapeFile, string sShakeMapID, string sFileGDB, string sTargetFCName, StringDictionary sdeSD) { IWorkspace pWS = null; IFeatureClass targetFC; ArcObjects pArcObjects = new ArcObjects(); FileInfo fi; IFeatureClass sourceFC; IFeatureCursor sourceCursor = null; try { // Initialize License m_AOLicenseInitializer = new LicenseInitializer(); m_AOLicenseInitializer.InitializeApplication(new ESRI.ArcGIS.esriSystem.esriLicenseProductCode[] { ESRI.ArcGIS.esriSystem.esriLicenseProductCode.esriLicenseProductCodeEngine }, new ESRI.ArcGIS.esriSystem.esriLicenseExtensionCode[] { }); // Get workspace from FGDB or SDE if (sFileGDB.Length > 0) { pWS = pArcObjects.FileGdbWorkspaceFromPath(sFileGDB); } else { IPropertySet pPropSet = new PropertySetClass(); pPropSet.SetProperty("SERVER", sdeSD["SERVER"]); pPropSet.SetProperty("INSTANCE", sdeSD["INSTANCE"]); pPropSet.SetProperty("DATABASE", sdeSD["DATABASE"]); pPropSet.SetProperty("USER", sdeSD["USER"]); pPropSet.SetProperty("PASSWORD", sdeSD["PASSWORD"]); pPropSet.SetProperty("VERSION", sdeSD["VERSION"]); pWS = pArcObjects.ConnectToTransactionalVersion(pPropSet); } // Make sure we have workspace if (pWS == null) { return false; } // Get target feature class targetFC = pArcObjects.GetFeatureClass(pWS, sTargetFCName); // Make sure we have target feature class if (targetFC == null) { return false; } // Set FileInfo object to shape file fi = new FileInfo(sShapeFile); // Make sure we have fileInfo object if (fi == null) { return false; } // Parse out ShapeFile name without extension string sShapeFileName = fi.Name.Substring(0, fi.Name.Length - (fi.Name.Length - fi.Name.LastIndexOf('.'))); // Get source featue class from shape file sourceFC = GetFeatureClassFromShapefileOnDisk(fi.DirectoryName, sShapeFileName); // Set source feature cursor. sourceCursor = sourceFC.Search(null, false); // Insert features InsertFeaturesUsingCursor(targetFC, sourceCursor, sShakeMapID); return true; } catch (Exception ex) { return false; } finally { System.Runtime.InteropServices.Marshal.ReleaseComObject(sourceCursor); sourceCursor = null; System.Runtime.InteropServices.Marshal.ReleaseComObject(pWS); pWS = null; //Do not make any call to ArcObjects after ShutDownApplication() if (m_AOLicenseInitializer != null) m_AOLicenseInitializer.ShutdownApplication(); m_AOLicenseInitializer = null; GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); } }