How to convert an access table into geodatabase

13260
5
02-17-2011 01:18 AM
PrateekBansal
Emerging Contributor
I have a table in access database which has an x and Y value i need to convert this into File geodatabase now .Can anyone suggest how to go about it . Any help will be appreciated .

Thanks.
0 Kudos
5 Replies
KyungKim
Emerging Contributor
Hi,

In ArcMap, click Add Data button to add the table, right click the table, click Display XY Data menu, then follow the menus to select projection, etc.  With the XY event displayed on the map, right click it and export it into your File Geodatabase.

Kyung
0 Kudos
PrateekBansal
Emerging Contributor
Thanks Kyung ,

I am sorry I forgot to write that I need to achieve this through code.
0 Kudos
JoseSanchez
Frequent Contributor
With ArcCatalog go to your file geodatabase, create a new table and them point to the MsAccess table to import the structure. Right clik and select Load --> Load Data to upload the data from access to your file geodatabase
0 Kudos
KyungKim
Emerging Contributor
I have a table in access database which has an x and Y value i need to convert this into File geodatabase now .Can anyone suggest how to go about it . Any help will be appreciated .

Thanks.


Hi,

Years ago I created a VBA macro converting Excel to shapefile, with details below.  You may modify it as appropriate.  The macro first takes an Excel sheet to a personal geodatabase, then creates XY Event, then makes a shape file from it.  In your case, you may just start from creating XY Event from the table in geodatabase and then create a feature class from it, which may be simpler than the sample macro. 

Kyung

======

'Don't forget to add the reference ..

'Microsoft Access 11.0 object library
'Microsoft Office 12.0 Access database engine object library

Sub EXToShape()
   
    ' FROM EXCEL TO XY EVENT
   
    ' Part 1: Transfer Excel sheet to Access
     Dim strInputFileName As String
     strInputFileName = InputBox("Enter the input file name:")
     ' Open Access database and get outside Excel into the database
     Dim ACC As Access.Application
     Set ACC = CreateObject("Access.Application", "")
     ACC.OpenCurrentDatabase "C:\kkim\Bangladesh_project\" & strInputFileName & "\" & strInputFileName & ".mdb"
     DoCmd.TransferSpreadsheet acImport, 8, strInputFileName, "C:\kkim\Bangladesh_project\" & strInputFileName & "\" & strInputFileName & ".xls", True

    ' Part 2: Define the input data file in Access.
    Dim pWorkspaceName As IWorkspaceName
    Dim pTableName As ITableName
    Dim pDatasetName As IDatasetName
    ' Define the input table's workspace.
    Set pWorkspaceName = New WorkspaceName
    pWorkspaceName.PathName = "c:\kkim\Bangladesh_project\" & strInputFileName & "\" & strInputFileName & ".mdb"
    pWorkspaceName.WorkspaceFactoryProgID = "esriDataSourcesGDB.AccessWorkspaceFactory"
    ' Define the dataset.
    Set pTableName = New TableName
    Set pDatasetName = pTableName
    pDatasetName.Name = strInputFileName
    Set pDatasetName.WorkspaceName = pWorkspaceName
 
    ' Part 3: Define the event source.
    Dim pXYEvent2FieldsProperties As IXYEvent2FieldsProperties
    Dim pSpatialReferenceFactory As ISpatialReferenceFactory
    Dim pGeographicCoordinateSystem As IGeographicCoordinateSystem
    Dim pXYEventSourceName As IXYEventSourceName
    ' Set the event to fields properties.
    Set pXYEvent2FieldsProperties = New XYEvent2FieldsProperties
    With pXYEvent2FieldsProperties
        .XFieldName = "LONG"
        .YFieldName = "LAT"
        .ZFieldName = ""
    End With
    ' Set the spatial reference.
    Set pSpatialReferenceFactory = New SpatialReferenceEnvironment
    Set pGeographicCoordinateSystem = pSpatialReferenceFactory.CreateGeographicCoordinateSystem(esriSRGeoCS_WGS1984)
    ' Specify the event source and its properties.
    Set pXYEventSourceName = New XYEventSourceName
    With pXYEventSourceName
        Set .EventProperties = pXYEvent2FieldsProperties
        Set .SpatialReference = pGeographicCoordinateSystem
        Set .EventTableName = pTableName
    End With

    ' Part 4: Create a layer from the event source and display the layer.
    Dim pMxDoc As IMxDocument
    Dim pMap As IMap
    Dim pName As IName
    Dim pXYEventSource As IXYEventSource
    Dim pFLayer As IFeatureLayer
    Set pMxDoc = ThisDocument
    Set pMap = pMxDoc.FocusMap
    ' Open the event source.
    Set pName = pXYEventSourceName
    Set pXYEventSource = pName.Open
    ' Create a new feature layer and add the layer to the active map.
    Set pFLayer = New FeatureLayer
    Set pFLayer.FeatureClass = pXYEventSource
    pFLayer.Name = "XY Events"
    pMap.AddLayer pFLayer
    pMxDoc.ActiveView.Refresh
   
    ' NOW FROM EVENT TO SHAPE FILE
   
    ' Part 5: Define the output
    Dim pDatasetName1 As IDatasetName
    Dim pWorkspaceName1 As IWorkspaceName
    Set pWorkspaceName1 = New WorkspaceName
    pWorkspaceName1.PathName = "c:\kkim\Bangladesh_project\" & strInputFileName
    pWorkspaceName1.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory"
    Set pDatasetName1 = New FeatureClassName
    Set pDatasetName1.WorkspaceName = pWorkspaceName1
    pDatasetName1.Name = strInputFileName
       
    ' Part 6: Defining the input was done above at part 4 as pName = pXYEventSourceName
 
    ' Part 7: Perform data conversion.
    Dim pShpToFC As IFeatureDataConverter
    Set pShpToFC = New FeatureDataConverter
    pShpToFC.ConvertFeatureClass pName, Nothing, Nothing, pDatasetName1, Nothing, Nothing, "", 1000, Application.hWnd

    ' Part 8: Display the created shape file
    Dim pWorkspaceFactory As IWorkspaceFactory
    Dim pFeatureWorkspace As IFeatureWorkspace
    Dim pFeatureLayer As IFeatureLayer
    Dim pFeatureClass As IFeatureClass
    ' Specify the workspace and the shape file
    Set pWorkspaceFactory = New ShapefileWorkspaceFactory
    Set pFeatureWorkspace = pWorkspaceFactory.OpenFromFile("c:\kkim\Bangladesh_project\" & strInputFileName, 0)
    Set pFeatureClass = pFeatureWorkspace.OpenFeatureClass(strInputFileName)
    Set pFeatureLayer = New FeatureLayer
    Set pFeatureLayer.FeatureClass = pFeatureClass
    pFeatureLayer.Name = pDatasetName1.Name
    ' Add the feature layer to the active map.
    pMap.AddLayer pFeatureLayer
    ' Delete the XYEvent layer
    pMap.DeleteLayer pFLayer
    ' Refresh the active view.
    pMxDoc.ActiveView.Refresh
    pMxDoc.UpdateContents
   
End Sub

===========
0 Kudos
PatrickBrooke
Emerging Contributor
With ArcCatalog go to your file geodatabase, create a new table and them point to the MsAccess table to import the structure. Right clik and select Load --> Load Data to upload the data from access to your file geodatabase


This is the perfect soultion!!! Thanks for posting it, saved me a bunch of time!!
0 Kudos