-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetadata_mre.py
54 lines (47 loc) · 1.61 KB
/
metadata_mre.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from arcgis import features
from arcgis import mapping
import arcpy
import sys
from pathlib import Path
from arcpy import metadata as md
import os, shutil
import xml.dom.minidom as DOM
import xml.etree.ElementTree as ET
from arcgis import GIS
elmer_geo_conn_path = r'T:\2024May\cpeak\AWS-PROD-SQL.sde'
arcpy.env.workspace = f"{elmer_geo_conn_path}"
# create dict of datasets per feature classes
fc_dict = {}
for dataset in arcpy.ListDatasets():
dataset_name = dataset.split(".")[2]
for fc in arcpy.ListFeatureClasses("*", "", dataset_name):
fc_name = fc.split(".")[2]
fc_dict[fc_name] = dataset_name
metadata_path = Path('./workspace/metadata')
meta_files = os.listdir(metadata_path)
src_file_path = r'.'
def get_dataset(layer):
try:
return(fc_dict[l])
except Exception as e:
return('nothing')
for f in meta_files:
l = f.replace('_metadata.xml','').lower()
dataset = get_dataset(l)
# print(f"layer {l} is in dataset {dataset}")
layer_path = Path(elmer_geo_conn_path)/dataset/l
target_item_md = md.Metadata(layer_path)
mdata_path = f"{metadata_path}\{f}"
new_md = md.Metadata(mdata_path)
# target_item_md.copy(new_md)
# target_item_md.save()
if l != 'block2000_nowater':
if not target_item_md.isReadOnly:
#target_item_md.importMetadata(src_file_path)
target_item_md.importMetadata(mdata_path)
target_item_md.save()
target_item_md.synchronize('ALWAYS')
target_item_md.save()
print(f"exported metadata for {l}")
else:
print(f"layer {l} is read-only")