Public Sub addPhotoToGeoDatabase(ByVal theGTagInfo As geoTaggedInfo) Try Dim ptable As ITable ' Create a file geodatabase workspace factory. Dim factoryType As Type = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory") Dim workspaceFactory As IWorkspaceFactory = CType(Activator.CreateInstance(factoryType), IWorkspaceFactory) ' Create a file geodatabase. Dim workspaceName As IWorkspaceName = workspaceFactory.OpenFromFile("G:\PublicWk\geoTagging\pwPhotoDatabaseTest.gdb", 0) ' Open the geodatabase using the name object. Dim Name As ESRI.ArcGIS.esriSystem.IName = CType(workspaceName, ESRI.ArcGIS.esriSystem.IName) Dim workspace As IWorkspace = CType(Name.Open(), IWorkspace) ' Cast the workspace to the IWorkspaceEdit2 interface. Dim workspaceEdit As IWorkspaceEdit = CType(workspace, IWorkspaceEdit) ' Start an edit session. An undo/redo stack isn't necessary in this case. workspaceEdit.StartEditing(False) ' Start an edit operation. workspaceEdit.StartEditOperation() ptable = workspace.OpenTable("tblGeotaggedPhotos") ' Create a row. The row's attribute values should be set here and if ' a feature is being created, the shape should be set as well. Dim row As IRow = ptable.CreateRow() row.Value("Latitude") = theGTagInfo.latitude row.Value("Longitude") = theGTagInfo.longitude row.Value("Descrip") = theGTagInfo.description row.Value("Keywords") = theGTagInfo.keywords row.Value("gTagByUser") = theGTagInfo.taggedByUserName row.Value("gTagByFullName") = theGTagInfo.tageedByFullName row.Value("DateGeotagged") = theGTagInfo.dateTagged row.Value("FileName") = theGTagInfo.filename row.Value("FullPath") = theGTagInfo.fullpath row.Store() ' Save the edit operation. To cancel an edit operation, the AbortEditOperation ' method can be used. workspaceEdit.StopEditOperation() ' Stop the edit session. The saveEdits parameter indicates the edit session ' will be committed. workspaceEdit.StopEditing(True) ptable = Nothing row = Nothing workspace = Nothing workspaceEdit = Nothing factoryType = Nothing workspaceFactory = Nothing Catch ex As Exception globalErrorHandler(ex) End Try End Sub
Imports ESRI.ArcGIS.Geodatabase Imports ESRI.ArcGIS.Carto
Dim workspaceName As IWorkspaceName = workspaceFactory.OpenFromFile("G:\PublicWk\geoTagging\pwPhotoDatabaseTest.gdb", 0)
ERROR DESCRIPTION: Unable to cast COM object of type 'System.__ComObject' to interface type 'ESRI.ArcGIS.Geodatabase.IWorkspaceName'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{FADD975C-E36F-11D1-AA81-00C04FA33A15}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
TYPE OF ERROR: System.InvalidCastException
STACK TRACE: at geoTagPhotos2.usrFunctions.addPhotoToGeoDatabase(geoTaggedInfo theGTagInfo) in C:\Visual Studio 2008\Projects\geoTagPhotos2\geoTagPhotos2\usrFunctions.vb:line 407
Solved! Go to Solution.
Public Sub addPhotoToGeoDatabase(ByVal theGTagInfo As geoTaggedInfo) Try Dim ptable As ITable Dim dbPath As String = "G:\PublicWk\geoTagging\pwPhotoDatabaseTest.gdb" ' Create a file geodatabase workspace factory. Dim factoryType As Type = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory") Dim WorkspaceFactory As IWorkspaceFactory = New ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactory Dim Workspace As IFeatureWorkspace = CType(WorkspaceFactory.OpenFromFile(dbPath, 0), IFeatureWorkspace) ' Cast the workspace to the IWorkspaceEdit2 interface. Dim workspaceEdit As IWorkspaceEdit = CType(workspace, IWorkspaceEdit) ' Start an edit session. An undo/redo stack isn't necessary in this case. workspaceEdit.StartEditing(False) ' Start an edit operation. workspaceEdit.StartEditOperation() ptable = workspace.OpenTable("tblGeotaggedPhotos") ' Create a row. The row's attribute values should be set here and if ' a feature is being created, the shape should be set as well. Dim row As IRow = ptable.CreateRow() row.Value(ptable.FindField("Latitude")) = theGTagInfo.latitude row.Value(ptable.FindField("Longitude")) = theGTagInfo.longitude row.Value(ptable.FindField("Descrip")) = theGTagInfo.description row.Value(ptable.FindField("Keywords")) = theGTagInfo.keywords row.Value(ptable.FindField("gTagByUser")) = theGTagInfo.taggedByUserName row.Value(ptable.FindField("gTagByFullName")) = theGTagInfo.tageedByFullName row.Value(ptable.FindField("gTagDate")) = theGTagInfo.dateTagged row.Value(ptable.FindField("FileName")) = theGTagInfo.filename row.Value(ptable.FindField("FullPath")) = theGTagInfo.fullpath row.Store() ' Save the edit operation. To cancel an edit operation, the AbortEditOperation ' method can be used. workspaceEdit.StopEditOperation() ' Stop the edit session. The saveEdits parameter indicates the edit session ' will be committed. workspaceEdit.StopEditing(True) Catch ex As Exception globalErrorHandler(ex) End Try End Sub