-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiso19139template.py
executable file
·31 lines (27 loc) · 1.33 KB
/
iso19139template.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
import xml.etree.ElementTree as ET
import os
namespaces = {'gmd': 'http://www.isotc211.org/2005/gmd','gco': 'http://www.isotc211.org/2005/gco', 'gml': 'http://www.opengis.net/gml', 'gfc': 'http://www.isotc211.org/2005/gfc'}
ET.register_namespace('xsi', 'http://www.w3.org/2001/XMLSchema-instance')
ET.register_namespace('gmd', 'http://www.isotc211.org/2005/gmd')
ET.register_namespace('gco', 'http://www.isotc211.org/2005/gco')
ET.register_namespace('gts', 'http://www.isotc211.org/2005/gts')
ET.register_namespace('gss', 'http://www.isotc211.org/2005/gss')
ET.register_namespace('gsr', 'http://www.isotc211.org/2005/gsr')
ET.register_namespace('gfc', 'http://www.isotc211.org/2005/gfc')
ET.register_namespace('gmx', 'http://www.isotc211.org/2005/gmx')
ET.register_namespace('gmi', 'http://www.isotc211.org/2005/gmi')
ET.register_namespace('gml', 'http://www.opengis.net/gml')
template = 'templates/template_iso.xml'
#copy template to new file named for each layer
def applyTemplate():
tree = ET.parse(template)
root = tree.getroot()
new_file = filePath[:-4] + '.xml'
tree.write(new_file)
print (f)
#walk through the directory and locate shapefiles
for dirName, subDirs, fileNames in os.walk('.'):
for f in fileNames:
if f.endswith('.shp'):
filePath = os.path.join(dirName, f)
applyTemplate()