Skip to content

Instantly share code, notes, and snippets.

@stdavis
Last active August 5, 2020 20:15
Show Gist options
  • Save stdavis/1a7631e8a1e781047e421646640b9c21 to your computer and use it in GitHub Desktop.
Save stdavis/1a7631e8a1e781047e421646640b9c21 to your computer and use it in GitHub Desktop.
import re
import arcpy
SDE = r'C:\temp\parcels_metadata_fix_1.gdb'
BASIC_SUMMARY = 'GIS mapping data representing parcel boundaries.'
LIR_SUMMARY = 'GIS mapping data representing parcel boundaries and county tax roll attributes.'
BASIC_UPDATE_INFO = 'Update information can be found within the layer’s attributes and in a table on the <a href="https://gis.utah.gov/data/cadastre/parcels/#UtahParcels">Utah Parcel Data webpage</a> under Basic Parcels.'
LIR_UPDATE_INFO = 'Update information can be found within the layer’s attributes and in a table on the <a href="https://gis.utah.gov/data/cadastre/parcels/#UtahParcels">Utah Parcel Data webpage</a> under LIR Parcels.'
LAST_UPDATE_REGEX = re.compile(r'(<P><SPAN>)?Last Update: .*\d(<\/SPAN><\/P>)?', re.MULTILINE | re.IGNORECASE)
print('getting feature classes...')
arcpy.env.workspace = SDE
for feature_class in arcpy.ListFeatureClasses('*Parcels_*'):
print(f'processing: {feature_class}')
is_lir = feature_class.find('LIR') > -1
metadata = arcpy.metadata.Metadata(feature_class)
if is_lir:
summary = LIR_SUMMARY
update_info = LIR_UPDATE_INFO
else:
summary = BASIC_SUMMARY
update_info = BASIC_UPDATE_INFO
metadata.upgrade('ESRI_ISO')
#: remove "Last Update: ..."
metadata.summary = re.sub(LAST_UPDATE_REGEX, '', metadata.summary)
metadata.description = re.sub(LAST_UPDATE_REGEX, '', metadata.description)
#: add old summary to the top of the description
if is_lir:
metadata.description = f'{metadata.summary}\n\n{metadata.description}'
#: add new update info to beginning of description
metadata.description = f'<p>{update_info}</p>{metadata.description}'
#: update summary to new generic version
metadata.summary = summary
metadata.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment