Accessing Personal Geodatabases with Python: Difference between revisions
From Wildsong
Jump to navigationJump to search
Brian Wilson (talk | contribs) m →Links |
Brian Wilson (talk | contribs) m →Links |
||
Line 5: | Line 5: | ||
Currently you can only update attributes with this method. If you have to update spatial data, use ArcObjects instead. | Currently you can only update attributes with this method. If you have to update spatial data, use ArcObjects instead. | ||
== Sample ADO code == | |||
<pre> | |||
#!/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 | |||
</pre> | |||
== Links == | == Links == | ||
Line 15: | Line 44: | ||
ODBC -- ?? I'd use ODBC with Perl but I have not tapped into the right source for ODBC + Python yet apparently. | 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/ | OLEDB -- http://pyoledb.datadmin.com/ does nothing! |
Revision as of 22:11, 31 December 2007
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
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/ does nothing!