Here is some documentation that will allow for you to export any file information regarding the database.
Get file information via python
os.path.getatime(path)
Return the time of last access of path. The return value is a floating point number giving the number of seconds since the epoch (see the time module). Raise OSError if the file does not exist or is inaccessible.
os.path.getmtime(path)
Return the time of last modification of path. The return value is a floating point number giving the number of seconds since the epoch (see the time module). Raise OSError if the file does not exist or is inaccessible.
Changed in version 3.6: Accepts a path-like object.
os.path.getctime(path)
Return the system’s ctime which, on some systems (like Unix) is the time of the last metadata change, and, on others (like Windows), is the creation time for path. The return value is a number giving the number of seconds since the epoch (see the time module). Raise OSError if the file does not exist or is inaccessible.
os.path.getsize(path)
Return the size, in bytes, of path. Raise OSError if the file does not exist or is inaccessible.
Have people noticed that these statistics do not appear until metadata is built for the geodatabase and needs to be refreshed to get featurecounts and dates? That is the clue on how to get these details programatically. You can't read the imbedded metadata easily because it is stored as a BLOB, but you can export it to XML and then read it with Python. All the tools are there to export metadata and the standard python module Xtree can extract what you need. No need for ArcObjects at all.
1. arcpy.management.SynchronizeMetadata(....)
2.arcpy.conversion.ExportMetadata(...)
3. import xml.etree.ElementTree as ET
tree = ET.parse(xmlfile)
[get required elements]
wrt "the date modified for file geodatabase feature class cannot be displayed in ArcCatalog.": It works in in ArcCatalog 10.3:
(editor tracking is still a good idea).
Hi Lance,
Thanks for mentioning the Esri Idea related to this. I've promoted it and hope others will as well.
You may want to request this functionality (arcpy.Describe().modifiedDate, arcpy.Describe().fileSize) on the Esri Ideas site.
very nice, thanks, again! FYI, here's a good thread on producing human readable byte sizes: python - Reusable library to get human readable version of file size? - Stack Overflow
Things are slow right now at work so I found an answer to the second part of this question: how to get the file geodatabase table/feature class size. In Snippets.py, underneath the GetModifiedDate function, insert:
def GetFileSize(gdb, tableName, featureDataset): # Define a function which will convert bytes to a meaningful unit def convert_bytes(bytes): bytes = float(bytes) if bytes >= 1099511627776: terabytes = bytes / 1099511627776 size = '%.2f TB' % terabytes elif bytes >= 1073741824: gigabytes = bytes / 1073741824 size = '%.2f GB' % gigabytes elif bytes >= 1048576: megabytes = bytes / 1048576 size = '%.2f MB' % megabytes elif bytes >= 1024: kilobytes = bytes / 1024 size = '%.2f KB' % kilobytes else: size = '%.2 fb' % bytes return size # Setup GetStandaloneModules() InitStandalone() import comtypes.gen.esriSystem as esriSystem import comtypes.gen.esriGeoDatabase as esriGeoDatabase import comtypes.gen.esriDataSourcesGDB as esriDataSourcesGDB # Open the FGDB pWS = Standalone_OpenFileGDB(gdb) # Create empty Properties Set pPropSet = NewObj(esriSystem.PropertySet, esriSystem.IPropertySet) pPropSet.SetProperty("database", gdb) # Cast the FGDB as IFeatureWorkspace pFW = CType(pWS, esriGeoDatabase.IFeatureWorkspace) # Get the info for a stand-alone table if featureDataset == "standalone": # Open the table pTab = pFW.OpenTable(tableName) # Cast the table to an IDatasetFileStat object pDFS = CType(pTab, esriGeoDatabase.IDatasetFileStat) # Return the size return convert_bytes(pDFS.StatSize) else: # Open the feature class pTab = pFW.OpenFeatureClass(tableName) # Cast the table as a IDatasetFileStat pDFS = CType(pTab, esriGeoDatabase.IDatasetFileStat) # Return the size return convert_bytes(pDFS.StatSize)
It's very similar to the GetModifiedDate function, but uses a different property of the IDatasetFileStat object.
...Really though, this information ought to be accessible via something like
arcpy.Describe().modifiedDate
arcpy.Describe().fileSize
Great, thanks Micah!
Hi Matt,
I don't mind at all. Thanks for the shout-out. Happy scripting!
Micah
Hi Micah, thanks for this clear start to finish example of using python arcobjects. I hope you don't mind me taking the liberty of folding it into my (very slowly) growing py-arcobjects module(?)
arcplus/ao.py at master · maphew/arcplus · GitHub
Hello John,
Have you considered using editor tracking instead? This will create columns in the attribute table indicating the edits made to the feature class, this you can access using python.
About tracking an editor's changes to data—Help | ArcGIS for Desktop
Like mentioned in the previous posts, unless it is a shapefile, the date modified for file geodatabase feature class cannot be displayed in ArcCatalog. Even the edits made to the feature class, does not affect the time stamp on the geodatabase itself until all the locks are released (this is also considered an "edit" on the gdb) i.e. till the application is closed which may not be the time you stopped editing.
43164 - In ArcCatalog, why is the time stamp incorrect on the date modified field of a file geodatabase feature class?
Therefore, editor tracking is definitely better option if you want to track changes made to the feature class. Feature Compare essentially compares the properties of two feature classes in terms of geometry, attrribute, schema and spatial reference.
Hope this helps!
Thanks,
Best,
Vandana
Out of curiosity, what indicates that it will fail in a Citrix environment?
It will fail on your import comtypes statement(s)
Hi James,
No I haven't. I developed this solution as part of some R&D on a redesign of an SDE data loading process we have. We need to detect changes in datasets in a range of formats so we can determine which of them have been updated and need to be loaded to our SDE geodatabases. Our current app was set up by my supervisor in C# ArcObjects. It works well but has a few shortcomings and has proven tricky to maintain over the years.
Have you distributed this across your organization? I can see right away it will fail in a Citrix environment. Too bad because this type of programmatic access is pretty good to have!
Getting the modified date of a .gdb table/feature class took some real acrobatics, but I was finally able to get it done. I started out with zero ArcObjects experience but a good dose of Python and arcpy.
Step one was to carefully follow the instructions here:
How do I access ArcObjects from Python? - Geographic Information Systems Stack Exchange
and here:
python - ArcObjects + comtypes at 10.1 - Geographic Information Systems Stack Exchange
Once I got the "create point" code working (from the example in the first link), I opened up the Snippets.py code and inserted the following function under the *** Standalone *** section, where gdb is the full path to the gdb and tableName is the table name:
# Setup GetStandaloneModules() InitStandalone() import comtypes.gen.esriSystem as esriSystem import comtypes.gen.esriGeoDatabase as esriGeoDatabase import comtypes.gen.esriDataSourcesGDB as esriDataSourcesGDB # Open the FGDB pWS = Standalone_OpenFileGDB(gdb) # Create empty Properties Set pPropSet = NewObj(esriSystem.PropertySet, esriSystem.IPropertySet) pPropSet.SetProperty("database", gdb) # Cast the FGDB as IFeatureWorkspace pFW = CType(pWS, esriGeoDatabase.IFeatureWorkspace) # Open the table pTab = pFW.OpenTable(tableName) # Cast the table as a IDatasetFileStat pDFS = CType(pTab, esriGeoDatabase.IDatasetFileStat) # Get the date modified return pDFS.StatTime(2)def GetModifiedDate(gdb, tableName):
# Setup
GetStandaloneModules()
InitStandalone()
import comtypes.gen.esriSystem as esriSystem
import comtypes.gen.esriGeoDatabase as esriGeoDatabase
import comtypes.gen.esriDataSourcesGDB as esriDataSourcesGDB
# Open the FGDB
pWS = Standalone_OpenFileGDB(gdb)
# Create empty Properties Set
pPropSet = NewObj(esriSystem.PropertySet, esriSystem.IPropertySet)
pPropSet.SetProperty("database", gdb)
# Cast the FGDB as IFeatureWorkspace
pFW = CType(pWS, esriGeoDatabase.IFeatureWorkspace)
# Open the table
pTab = pFW.OpenTable(tableName)
# Cast the table as a IDatasetFileStat
pDFS = CType(pTab, esriGeoDatabase.IDatasetFileStat)
# Get the date modified
return pDFS.StatTime(2)
Finally, I created a script that implemented the function (set up for a custom script tool but could be used as a stand-alone as well):
import Snippets import datetime import arcpy import sys # User Params file_gdb = arcpy.GetParameterAsText(0) # Path to FGDB table_name = arcpy.GetParameterAsText(1) # Table or feature class name arcpy.env.workspace = file_gdb if file_gdb.split(".")[-1] != "gdb": arcpy.AddMessage("The input workspace is not a file geodatabase!") sys.exit() def doIt(file_gdb, table_name): # Call GetModifiedDate function to get the number of seconds num_seconds = Snippets.GetModifiedDate(file_gdb, arcpy.Describe(table_name).baseName) # Translate the number of seconds into a formatted date date_modified = datetime.datetime.fromtimestamp(num_seconds).strftime('%Y-%m-%d %H:%M:%S') # Report the result arcpy.AddMessage(date_modified) return date_modified doIt(file_gdb, arcpy.Describe(table_name).baseName)
I sincerely hope this helps! Thanks to all the people who got me to an actual solution.
I dont understand why my result object is coming up empty.
childfc = r"C:\Temp\MyGDB\Stores" parentfc = r"\\sharedrive\ParentGDB\Stores" result = arcpy.FeatureCompare_management(parentfc, childfc, "DID", "ATTRIBUTES_ONLY", "", "", "", "", "", "", "NO_CONTINUE_COMPARE") print "Comparison Result is: " + result.getOutput(1) result.GetOutput(1)
Comparison Result is: false u'false'
childfc = r"C:\Temp\MyGDB\Stores" parentfc = r"\\sharedrive\ParentGDB\Stores" result = arcpy.FeatureCompare_management(parentfc, childfc, "DID", "ATTRIBUTES_ONLY", "", "", "", "", "", "", "NO_CONTINUE_COMPARE") print "Comparison Result is: " + result result.GetOutput
Comparison Result is: <bound method Result.getOutput of <Result ''>>
I've never used ArcObjects via Python but you can: http://gis.stackexchange.com/questions/80/how-do-i-access-arcobjects-from-python
By the looks of this http://gis.stackexchange.com/questions/23914/how-to-get-the-size-of-a-file-geodatabase-feature-class-on-disk you could probably get at this info with ArcObects someway.edit: yup.. http://gis.stackexchange.com/questions/24242/how-to-programmatically-determine-the-size-of-a-feature-class-in-a-file-geodatab ArcObjects will get it done.
Unless its a shapefile, I don't believe there is currently a way to do this with arcpy in v10.1.
import glob def compactAndReportFGDB(fgdbPath): oldFgdbSize = 0 for file in glob.glob(fgdbPath + "\\*"): oldFgdbSize = oldFgdbSize + os.path.getsize(file) arcpy.Compact_management(fgdbPath) newFgdbSize = 0 for file in glob.glob(fgdbPath + "\\*"): newFgdbSize = newFgdbSize + os.path.getsize(file) compactPct = str(int((oldFgdbSize - newFgdbSize) / float(oldFgdbSize) * 100)) return compactPct
There doesn't appear to be a function in arcpy to return the file size of a feature class or it's date modified timestamp. Anyone have any idea how to do this? I know there is a property somewhere because you can setup ArcCatalog to display the information. However, I want to see it returned in a Python Script so that I can write a two-way synchronization function.
Membros conectados podem postar, seguir atualizações e mais. Novo aqui? Registre uma conta gratuita.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.