Accessing Personal Geodatabases with Python
From Wildsong
A "personal geodatabase" (PGDB) is a format used by ESRI ArcGIS software. It is really a Microsoft Access database so methods to access MS "MDB" files will allow you to directly read and write PGDB's.
I am creating this page right now.
Currently you can only update attributes with this method. If you have to update spatial data, use ArcObjects instead.
Sample ADO code
#!/usr/bin/env python import sys, os import win32com.client mdb = 'C:/AGIProduct/IncidentView_Data/Data/CA/Davis/IncidentView.mdb' dsn = 'PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=' + mdb + ';' if not os.path.exists(mdb) : print "File does not exist: " + mdb sys.exit(-1) conn = win32com.client.Dispatch(r'ADODB.Connection') conn.Open(dsn) # Create a record set for table called "Addresses" recordset = win32com.client.Dispatch(r'ADODB.Recordset') tablename = 'Addresses' recordset.Open('SELECT * FROM ' + tablename, conn, 1, 3) # Print names of fields in the table for x in range(recordset.Fields.Count) : n = recordset.Fields.Item(x).Name print n
Links
ADO -- http://www.mayukhbose.com/python/ado/ado-connection.php and http://www.markcarter.me.uk/computing/python/ado.html
ODBC -- ?? I'd use ODBC with Perl but I have not tapped into the right source for ODBC + Python yet apparently.
OLEDB -- http://pyoledb.datadmin.com/ This apparently does nothing! Don't bother.