getting value for a personal Geodatabase memo field using a SearchCursor

877
5
02-10-2012 08:41 AM
David_JAnderson
New Contributor III
I working on a Python script to extract data from the feature class metadata.  Perusing the personal geodatabase I see that GDB_items is the table with the metadata and that metadata is in a field name Documentation.  I open up a search cursor on the gdb_items table.  Then access the Documentation field.  The cursor has values no value for this field.  Checking back in MS Access I see that the datatype is MEMO.
pseudo code:
cursor=arcpy.SearchCursor(SomeFeatureClass)
for row in cursor:
   print row.Name,row.Documentation

produces
Name None

Any idea as to why a memo field is not coming across in a Search cursor?
Tags (2)
0 Kudos
5 Replies
ChrisSnyder
Regular Contributor III
It's probably not the memo field type, but rather the table you are trying to read. All those GDB_* tables in a PGDB are 'off limits' to the high level ESRI geoprocessing objects. You would have to use some other non-ESRI module to read these GDB_* tables... That said, there are a bunch of ways to read Access databases (and the GDB_* tables) directly: http://stackoverflow.com/questions/853370/what-do-i-need-to-read-microsoft-access-databases-using-py...
0 Kudos
David_JAnderson
New Contributor III
Before I started experimenting I too thought that the GDB_ tables would no be accessible using the ESRI tools and that I would have to use a ODBC or COM/DAO interface into the database.  Which I didn't want to do as that is not portable across personal and file geodatabases.  I had a few minutes, so I thought I would try to see if I could do it with arcpy.  I found that I could open both a Search and Update cursor on the GDB_Items table.  I can loop over the table and print out the values for every field in the table except the fields with a memo data type.  Which indicates to me that there is something in the memo type that is not being dealt with adequately.
0 Kudos
ChrisSnyder
Regular Contributor III
My bad... You are totally correct! However, in v9.3 I can apparently read the values of Memo fields. In the example below, the SRTEXT field in the GDB_SpatialRefs table is reported as a Memo field in Access. I dont have a 'GDB_Items' table in my v9.3 PGDB, so maybe it's the table? Maybe it works to read memo fields in v9.3 and not in a v10.0 PGDB?

tbl = r"D:\csny490\temp\test.mdb\GDB_SpatialRefs"
>>> lmpy.listFields(tbl)
NAME                                              TYPE           LENGTH         SCALE          PRECISION      
----------------------------------------------------------------------------------------------------
SRID                                              OID            4              0              0              
SRTEXT                                            String         2147483647     0              0              
FalseX                                            Double         8              0              0              
FalseY                                            Double         8              0              0              
XYUnits                                           Double         8              0              0              
FalseZ                                            Double         8              0              0              
ZUnits                                            Double         8              0              0              
FalseM                                            Double         8              0              0              
MUnits                                            Double         8              0              0              
IsHighPrecision                                   Integer        4              0              0              
XYTolerance                                       Double         8              0              0              
ZTolerance                                        Double         8              0              0              
MTolerance                                        Double         8              0              0              


>>> lmpy.listRecords(tbl)
RECORD #1
----------------------------------------------------------------------------------------------------
SRID: 1
SRTEXT: PROJCS["NAD_1983_HARN_StatePlane_Washington_South_FIPS_4602_Feet",GEOGCS["GCS_North_American_1983_HARN",DATUM["D_North_American_1983_HARN",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["False_Easting",1640416.666666667],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-120.5],PARAMETER["Standard_Parallel_1",45.83333333333334],PARAMETER["Standard_Parallel_2",47.33333333333334],PARAMETER["Latitude_Of_Origin",45.33333333333334],UNIT["Foot_US",0.3048006096012192]]
FalseX: -117498300.0
FalseY: -98850300.0
XYUnits: 609.601219202
FalseZ: -100000.0
ZUnits: 1.0
FalseM: -100000.0
MUnits: 1.0
IsHighPrecision: 1
XYTolerance: 0.00328083333333
ZTolerance: 2.0
MTolerance: 2.0

LISTED 1 RECORDS
>>>  
0 Kudos
ChrisSnyder
Regular Contributor III
So I tried in v10.0 and I am guessing that some of the Memo fields are somehow read protected.

tbl2 = "C:\\csny490\\temp\\test.mdb\\GDB_Items"

print arcpy.SearchCursor(tbl2, "Path = '\landscapes'").next().Type #Type field is a Memo field, and it works... 
{70737809-852C-4A03-9E22-2CECEA5B9BFA}

>>> print arcpy.SearchCursor(tbl2, "Path = '\landscapes'").next().Documentation
None

>>> print arcpy.SearchCursor(tbl2, "Path = '\landscapes'").next().Definition 
None


Workaround: Parse the output .xml format file of the ExportMetadata_conversion() tool?
0 Kudos
David_JAnderson
New Contributor III
Thanks for taking the time to test.  I confirmed your results that a memo field on a feature class can be accessed fine but the GDB_Items table ones are being treated differently by arcpy.
Drat.
I also tried in 9.3 to see if I could access the GDB_UserMetadata table.  In that table the XML column with the metadata is blocked from being read.  In a normal FC, a memo field can be read.  So this is not new behavior in 10.

When I started this work I tried the ExportMetadata tool first.  I was getting erratic and unpredictable results at least on the messy metadata that I have.  The cleaning up of which is the point of this exercise.  So I thought about just going straight to the data and using one of the Python XML interfaces to read the data.  Looks like the arcpy interface won't work.  At least with Python there are now other ways to get at the data.
0 Kudos