|
35 | 35 | # Export metadata using FGDC |
36 | 36 | translator = directory + 'Metadata\Translator\ArcGIS2FGDC.xml' |
37 | 37 |
|
38 | | -# Convert shapefile layer to gdb feature class |
| 38 | +## (1) Convert shapefile layer to gdb feature class |
39 | 39 | for f in in_features: |
40 | 40 | # construct the filename, which is takes form of routes_assembled/routes_assembled.shp |
41 | 41 | shp_file_name = f + '/' + f + '.shp' |
42 | 42 |
|
43 | | - # Need this try/except because arcpy won't let you overwrite, and will error if it finds it |
| 43 | + # Need this try/except because arcpy won't let you overwrite, |
| 44 | + # and will error if it finds it |
44 | 45 | try: |
45 | 46 | arcpy.management.Delete(staging_location + '/' + f) |
46 | 47 | except: |
|
57 | 58 | print(field.name) |
58 | 59 |
|
59 | 60 |
|
60 | | -# Rename fields |
| 61 | +## (2) Rename fields where needed |
| 62 | +# Do this once it's a feature class, so we can preserve the new column names |
| 63 | +# before metadata is created |
61 | 64 | need_renaming = [ |
62 | 65 | 'ca_hq_transit_areas', |
63 | 66 | 'ca_hq_transit_stops', |
|
90 | 93 | field.name, RENAME_CA_HQTA[field.name]) |
91 | 94 |
|
92 | 95 |
|
| 96 | +## (3) Export metadata associated with file gdb feature class in FGDC format |
93 | 97 | for f in in_features: |
94 | 98 | # Construct XML filename |
95 | 99 | # Spit out one that's before it's manually changed |
|
101 | 105 |
|
102 | 106 |
|
103 | 107 |
|
104 | | -### UPDATE XML METADATA SEPARATELY IN PYTHON OUTSIDE OF ARCGIS |
| 108 | +### (4) UPDATE XML METADATA SEPARATELY IN PYTHON OUTSIDE OF ARCGIS |
105 | 109 |
|
106 | | -# Run this after putting the updated XML in the file gdb |
107 | | -# Clean up the open_data file gdb |
| 110 | +## (5) Copy the feature class from staging location to out location |
| 111 | +# In the out location, we can drop the new XML and use it to sync |
| 112 | +# Use staging location and out location because otherwise, arcpy errors when it detects |
| 113 | +# another XML when you try and update the layer in a subsequent update |
108 | 114 | for f in in_features: |
109 | 115 | # Delete the feature class in this gdb, because we don't want _1 appended to end |
110 | 116 | try: |
|
117 | 123 | out_location + '/', |
118 | 124 | f) |
119 | 125 |
|
120 | | - |
| 126 | +## (6) Sync the XML with the feature class |
121 | 127 | for f in in_features: |
122 | 128 | # This is the one after it's manually changed. Keep separate to see what works. |
123 | 129 | updated_xml_file = out_location + '/' + f + '.xml' |
|
129 | 135 | "ENABLED") |
130 | 136 |
|
131 | 137 |
|
132 | | -# Clean up XML file in staging.gdb |
133 | | -# If not, next time, it will error because it can't output an XML file when one is present (no overwriting) |
| 138 | +## (7) Clean up XML file in staging.gdb |
| 139 | +# If not, next time, it will error because it can't output an XML file |
| 140 | +# when one is present (no overwriting) |
134 | 141 | for f in in_features: |
135 | 142 | try: |
136 | 143 | os.remove(xml_file) |
|
0 commit comments