Prior, (I can confirm in version 2.8), I could check the LRS metadata using a query to the LRS_METADATA table in a Enterprise geodatabase.
import xml.etree.ElementTree as ET
import arcpy
import os
arcpy.env.workspace = r""
arcpy.env.workspace = r"U:\Documents\ArcGIS\Projects\UPDM2018\LIN0228\UPDM2018_DataOwner.sde"
def is_table_in_LRS(tablename):
with arcpy.da.SearchCursor(os.path.join(arcpy.env.workspace, "LRS_METADATA"), ['Metadata']) as cursor:
for row in cursor:
raw_metadata = row[0].tobytes()
xml = str(raw_metadata.decode("utf-8"))
root = ET.fromstring(xml)
event_tables = [elem.get('TableName') for elem in root.iter('EventTable')]
print(event_tables)
return tablename in event_tables
res = is_table_in_LRS("MyTable")
print(res)
Using ArcGIS Pro 2.9, I added an event table to my LRS, and tried the script above, but as result i just got the list of event tables without the new one.
after restarting arcgis pro, my Ide, checking the properties of the LRS and the properties of the Feature class, i was pulling my hair because the visual information from ArcGIS pro was correct, but the information from the script was not.
After making a double check in the documentation, i found here, that i can get the lrs metadata using the arcpy.Describe method.
import xml.etree.ElementTree as ET
import arcpy
import os
arcpy.env.workspace = r""
arcpy.env.workspace = r"U:\Documents\ArcGIS\Projects\UPDM2018\LIN0228\UPDM2018_DataOwner.sde"
def is_table_in_LRS(tablename):
desc = arcpy.Describe(os.path.join(arcpy.env.workspace, "UPDM2018.Dataowner.P_Integrity\\UPDM2018.Dataowner.ALRS"))
xml = desc.lrsMetadata
root = ET.fromstring(xml)
event_tables = [elem.get('TableName') for elem in root.iter('EventTable')]
print(event_tables)
return tablename in event_tables
res = is_table_in_LRS("P_DASurveyReadings")
print(res)
ok, that is good.
I want to know, where it is stored? can i get rid of the LRS_METADATA table? I would like to make this script but in SQL, where should i look for the REAL Lrs metadata?
Solved! Go to Solution.
The information that is required was moved to the GDB_ITEMS table, it can be fetched with a cursor:
identifier = None with arcpy.da.SearchCursor(os.path.join(arcpy.env.workspace,"sde.GDB_ITEMTYPES"), ['UUID'], where_clause="Name = 'Location Referencing Dataset'") as type_items_cursor: for type_object in type_items_cursor: identifier = type_object[0] del type_items_cursor lrs_path = None with arcpy.da.SearchCursor(os.path.join(arcpy.env.workspace,"sde.GDB_ITEMS"), ['Path'], where_clause=f"Type = '{identifier}'") as items_cursor: for item in items_cursor: lrs_path = item[0] del items_cursor print(lrs_path)
Moreover, I just change the name of the LRS......the name was not changed in the LRS_Metadata table......so.....programmatically speaking......how i am going to be able to retrieve the name of the LRS, in order to apply the script above??
[EDIT 1] I tried with ListDatasets..... no luck
The information that is required was moved to the GDB_ITEMS table, it can be fetched with a cursor:
identifier = None with arcpy.da.SearchCursor(os.path.join(arcpy.env.workspace,"sde.GDB_ITEMTYPES"), ['UUID'], where_clause="Name = 'Location Referencing Dataset'") as type_items_cursor: for type_object in type_items_cursor: identifier = type_object[0] del type_items_cursor lrs_path = None with arcpy.da.SearchCursor(os.path.join(arcpy.env.workspace,"sde.GDB_ITEMS"), ['Path'], where_clause=f"Type = '{identifier}'") as items_cursor: for item in items_cursor: lrs_path = item[0] del items_cursor print(lrs_path)