listGeodatabases()

3165
10
Jump to solution
02-06-2011 11:46 PM
LotharUlferts
New Contributor III
I'm trying to create a listGeodatabases() method, simular to the gp.listxx-family.
All works fine, except this:
I can't differ a *.mdb created by Access from those created by ArcCatalog.
gp.describe(databasePath).DataType always returns 'Workspace'.

Can anyone help?
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
LotharUlferts
New Contributor III

Hy,

after a long time I fond a soloution in the workspace 'release'-property:

arcpy.Describe(PGDB-WS)  returns something like u'3,0,0'

while arcpy.Describe(pure_MSACCESS-WS) returns somethinge like this u'400558244,2616584,323869160'

That's ok for me.

View solution in original post

0 Kudos
10 Replies
AndrewChapkowski
Esri Regular Contributor
Check out the ListWorkspaces() and Describe data.

ListWorkspaces() allows you to specify if you want to find file geodatabase, personal geodatabase, sde, etc...

You can also use Describe() to get the workspace properties also.
0 Kudos
LotharUlferts
New Contributor III
hi andrew, thanks for your speedy reply.

Check out the ListWorkspaces() and Describe data.

ListWorkspaces() allows you to specify if you want to find file geodatabase, personal geodatabase, sde, etc...

Thats the goal: To differ ACCES-MBS from ArcGIS-MDBs.
gp.ListWorkspaces('*','Access') returns both typs.
You can also use Describe() to get the workspace properties also.

I couldn't find a property on which an ACCES-MDB gives another value then the ArcGIS-MDB.
I tested this on the data in the attached example.zip.
0 Kudos
AndrewChapkowski
Esri Regular Contributor
I don't believe there is any difference between the MS Access databases. If it's created by esri or if it's create my MS Access, it's all the same file.  The difference is that a spatial database has a specific set of tables in it.

You can try using a library like pyodbc and look at the tables in the database.  If it has the spatial tables, then you know it's a spatial personal geodatabase.

Another solution too, would be to use file geodatabases to store spatial data instead of personal geodatabases.
0 Kudos
LotharUlferts
New Contributor III
I don't believe there is any difference between the MS Access databases. If it's created by esri or if it's create my MS Access, it's all the same file.  The difference is that a spatial database has a specific set of tables in it.[....] Another solution too, would be to use file geodatabases to store spatial data instead of personal geodatabases.

Unfortunatly my script is operating in folder with unknown content. And in each GDB of this folder one FeatureClass has to be created to summerize something. DBs created with Access causes an error.

You can try using a library like pyodbc and look at the tables in the database.  If it has the spatial tables, then you know it's a spatial personal geodatabase.

That's a good solution. I try this  hint and perhaps I can announce a solution.
0 Kudos
NiklasNorrthon
Occasional Contributor III
Why not just try to create that feature class, and if it doesn't work, just assume it's an access db. Something like:

mdb_list = gp.ListWorkspaces('*', 'Access')
for each mdb in mdb_list:
    try:
        gp.CreateFeatureClass(your_arguments)
    except WhateverExceptionYouGetWithWrongTypeOfMDBs:
        pass # Just ignore (or maybe you should log something)
0 Kudos
LoganPugh
Occasional Contributor III
Why not just try to create that feature class, and if it doesn't work, just assume it's an access db. Something like:

mdb_list = gp.ListWorkspaces('*', 'Access')
for each mdb in mdb_list:
    try:
        gp.CreateFeatureClass(your_arguments)
    except WhateverExceptionYouGetWithWrongTypeOfMDBs:
        pass # Just ignore (or maybe you should log something)


This seems error-prone and potentially very slow.

ESRI should provide a built-in method to determine whether an MDB file is a PGDB or a regular Access database.

See also:
Finding All Geodatabases Inside Main Folder and Subfolders
0 Kudos
RDHarles
Occasional Contributor
Add this simple line of code to check for Access:

 
...
if gdb.endswith(".mdb"):
...
0 Kudos
LoganPugh
Occasional Contributor III
Add this simple line of code to check for Access:

 
...
if gdb.endswith(".mdb"):
...


That will still return true for both personal geodatabases which are Access-based and use the .mdb file extension, and plain Access MDB databases which are not geodatabases.
0 Kudos
LotharUlferts
New Contributor III

Hy,

after a long time I fond a soloution in the workspace 'release'-property:

arcpy.Describe(PGDB-WS)  returns something like u'3,0,0'

while arcpy.Describe(pure_MSACCESS-WS) returns somethinge like this u'400558244,2616584,323869160'

That's ok for me.

0 Kudos