Skip to content

Commit 4150cda

Browse files
build out MUVD thematic schema (#5791)
1 parent e2a5af8 commit 4150cda

File tree

4 files changed

+1988
-378
lines changed

4 files changed

+1988
-378
lines changed

Makefile.hoot

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ SHELL=/bin/bash
1212
.PHONY: clean-ccache HOOT_VERSION_FILE
1313

1414
# This list is for manually rebuilding the schema files. The files have been commited to the main GitHub repo
15-
SCHEMA_FILES= translations/tds71_schema.js translations/tds70_schema.js translations/tds61_schema.js translations/tds40_schema.js translations/mgcp_schema.js translations/mgcp_thematic_schema.js translations/muvd_schema.js translations/ggdm30_schema.js translations/tds71_thematic_schema.js translations/tds71_thematic_enum_schema.js translations/tds71_full_schema.js translations/tds61_full_schema.js translations/tds70_full_schema.js translations/tds40_full_schema.js translations/ggdm30_full_schema.js translations/etds71_rules.js translations/etds70_rules.js translations/etds61_rules.js translations/etds40_rules.js translations/emgcp_rules.js translations/eggdm30_rules.js translations/etds71_osm_rules.js translations/etds61_osm_rules.js translations/etds40_osm_rules.js translations/emgcp_osm_rules.js translations/eggdm30_osm_rules.js translations/etds70_osm_rules.js
15+
SCHEMA_FILES= translations/tds71_schema.js translations/tds70_schema.js translations/tds61_schema.js translations/tds40_schema.js translations/mgcp_schema.js translations/mgcp_thematic_schema.js translations/muvd_schema.js translations/muvd_thematic_schema.js translations/ggdm30_schema.js translations/tds71_thematic_schema.js translations/tds71_thematic_enum_schema.js translations/tds71_full_schema.js translations/tds61_full_schema.js translations/tds70_full_schema.js translations/tds40_full_schema.js translations/ggdm30_full_schema.js translations/etds71_rules.js translations/etds70_rules.js translations/etds61_rules.js translations/etds40_rules.js translations/emgcp_rules.js translations/eggdm30_rules.js translations/etds71_osm_rules.js translations/etds61_osm_rules.js translations/etds40_osm_rules.js translations/emgcp_osm_rules.js translations/eggdm30_osm_rules.js translations/etds70_osm_rules.js
1616

1717

1818
-include Makefile.inc
@@ -196,6 +196,11 @@ translations/muvd_schema.js: scripts/schema/ConvertMUVDSchema_XML.py conf/transl
196196
mkdir -p $(@D)
197197
$^ > $@ || (rm -f $@ ; exit -1)
198198

199+
# Build the MUVD thematic schema from the TRD feature catalog
200+
translations/muvd_thematic_schema.js: scripts/schema/ConvertMUVDSchema_XML.py conf/translations/MUVD_Feature_Catalogue_UTRD1_v1.2_20230801.xml.gz
201+
mkdir -p $(@D)
202+
$< --thematic $(word 2,$^) > $@ || (rm -f $@ ; exit -1)
203+
199204
#### TDSv71
200205

201206
# Build the TDS71 "From English" rules

scripts/schema/ConvertMUVDSchema_XML.py

Lines changed: 121 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,64 @@ def printJavascript(schema):
7979
print '];' # End of schema
8080
# End printJavascript
8181

82+
# Modified printing function to print the Thematic Schema
83+
def printThematic(schema,spec):
84+
print
85+
print "var _global = (0, eval)('this');"
86+
print 'if (!_global.%s)' % (spec)
87+
print '{'
88+
print ' _global.%s = {};' % (spec)
89+
print '}'
90+
print
91+
print '%s.thematicSchema = [' % (spec)
92+
num_feat = len(schema.keys()) # How many features in the schema?
93+
for f in sorted(schema.keys()):
94+
95+
pString = ' {name:"%s",fcode:"%s",desc:"%s",geom:"%s",' % (f,schema[f]['fcode'],schema[f]['desc'],schema[f]['geom']); # name = geom + FCODE
96+
if 'fdname' in schema[f]:
97+
pString += 'fdname:"%s",' % (schema[f]['fdname'])
98+
if 'thematic' in schema[f]:
99+
pString += 'thematic:"%s",' % (schema[f]['thematic'])
100+
if 'definition' in schema[f]:
101+
pString += 'definition:"%s",' % (schema[f]['definition'])
102+
103+
print pString
104+
print ' columns:['
105+
106+
num_attrib = len(schema[f]['columns'].keys()) # How many attributes does the feature have?
107+
for k in sorted(schema[f]['columns'].keys()):
108+
if schema[f]['columns'][k]['type'] == 'enumeration':
109+
aType = 'Integer'
110+
else:
111+
aType = schema[f]['columns'][k]['type']
112+
113+
aString = ' {name:"%s",desc:"%s",optional:"%s",type:"%s",defValue:"%s"' % (k,schema[f]['columns'][k]['desc'],schema[f]['columns'][k]['optional'],aType,schema[f]['columns'][k]['defValue'])
114+
115+
if 'length' in schema[f]['columns'][k]:
116+
aString += ',length:"%s"' % (schema[f]['columns'][k]['length'])
117+
118+
if 'definition' in schema[f]['columns'][k]:
119+
aString += ',definition:"%s",' % (schema[f]['columns'][k]['definition'])
120+
121+
if num_attrib == 1: # Are we at the last attribute? yes = no trailing comma
122+
aString += '}'
123+
else:
124+
aString += '},'
125+
num_attrib -= 1
126+
print aString
127+
print ' ]'
128+
129+
if num_feat == 1: # Are we at the last feature? yes = no trailing comma
130+
print ' }'
131+
else:
132+
print ' },'
133+
num_feat -= 1
134+
print '] // End of %s.thematicSchema' % (spec)
135+
print
136+
# print 'exports.getthematicSchema = %s.schema.getThematicSchema;' % (spec)
137+
print
138+
# End printThematic
139+
82140
# XML Functions
83141
def processFeatureGeom(node):
84142
return node.firstChild.nodeValue[-2] == '_'
@@ -110,10 +168,35 @@ def readFeatures(xmlDoc,funcList):
110168

111169
# Setup handy lists
112170
geoList = {'C':'Curve', 'P':'Point', 'S':'Surface', '_':'None' }
171+
themAppndList = {'Curve':'Crv','Point':'Pnt','Surface':'Srf'}
113172
typeList = {'enumeration':'enumeration','CharacterString':'String','Integer':'Integer','Real':'Real'}
114173

115174
tSchema = {}
116175

176+
# Parse and index the thematic feature classes
177+
thematicLookup = {}
178+
for val in xmlDoc.getElementsByTagName('Package'):
179+
pName = ''
180+
parentId = ''
181+
182+
package_id = u' ' + val.getAttribute('id').encode('utf8').strip()
183+
184+
for node in val.childNodes:
185+
186+
if node.localName == 'name':
187+
pName = processSingleNode(val,'name')
188+
thematicLookup[package_id] = {'name':pName}
189+
190+
continue
191+
192+
if node.localName == 'parent':
193+
parentId = u' ' + node.getAttribute('idref').encode('utf8').strip()
194+
if parentId in thematicLookup:
195+
thematicLookup[package_id]['parent'] = thematicLookup[parentId]['name']
196+
197+
continue
198+
199+
117200
# Parse and index the enumerated values
118201
enumValue_lookup = {}
119202
for val in xmlDoc.getElementsByTagName('Value'):
@@ -219,7 +302,7 @@ def readFeatures(xmlDoc,funcList):
219302
tSchema[fCode]['fcode'] = fCode
220303
tSchema[fCode]['columns'] = {}
221304
tSchema[fCode]['columns']['FCODE'] = { 'name':'FCODE','desc':'Feature Code','type':'String','optional':'R','defValue':'','length':'5'}
222-
305+
tSchema[fCode]['thematic'] = ''
223306
# Process each node of the feature
224307
for node in feature.childNodes:
225308

@@ -250,6 +333,11 @@ def readFeatures(xmlDoc,funcList):
250333
geomChar = rawName[-1]
251334
tSchema[fCode]['geom'] = fGeom
252335
continue
336+
337+
if node.localName == 'package':
338+
package_id = u' ' + node.getAttribute('idref').encode('utf8').strip()
339+
tSchema[fCode]['thematic'] = thematicLookup[package_id]['parent'] + themAppndList[tSchema[fCode]['geom']]
340+
continue
253341

254342
if node.localName == 'title':
255343
continue
@@ -260,14 +348,36 @@ def readFeatures(xmlDoc,funcList):
260348
tSchema[fCode]['name'] = fName.replace('_S','').replace('_P','').replace('_C','')
261349
continue
262350

263-
if node.localName == 'package' or node.localName == 'type':
351+
if node.localName == 'type':
264352
continue
265353

266354
# Debug: If we didn't process a value for a node, print what we missed
267355
print('#### Node Missed ', node.localName)
268356

269357
return tSchema
270358

359+
# Convert a schema to Thematic schema
360+
def makeThematic(schema):
361+
tSchema = {}
362+
for feature in schema:
363+
thematicName = schema[feature]['thematic']
364+
365+
# Build a feature
366+
if thematicName not in tSchema:
367+
tSchema[thematicName] = {}
368+
tSchema[thematicName]['name'] = thematicName
369+
tSchema[thematicName]['fcode'] = ''
370+
tSchema[thematicName]['geom'] = schema[feature]['geom']
371+
tSchema[thematicName]['desc'] = thematicName
372+
tSchema[thematicName]['columns'] = {}
373+
374+
for attr in schema[feature]['columns']:
375+
if attr not in tSchema[thematicName]['columns']:
376+
tSchema[thematicName]['columns'][attr] = {}
377+
tSchema[thematicName]['columns'][attr] = schema[feature]['columns'][attr]
378+
379+
return tSchema
380+
# End of makeThematic
271381

272382
###########
273383
# Main Starts Here
@@ -313,13 +423,19 @@ def readFeatures(xmlDoc,funcList):
313423

314424
schema = readFeatures(xmlDoc,funcList)
315425

426+
# Now build a thematic schema
427+
thematicSchema = makeThematic(schema)
428+
316429
# Now dump the schema out
317430
if args.rules:
318431
printRules(schema)
319432
else:
320433
printCopyright()
321-
printJSHeader('muvd')
322-
printJavascript(schema)
323-
printJSFooter('muvd')
434+
if args.thematic:
435+
printThematic(thematicSchema,'muvd')
436+
else:
437+
printJSHeader('muvd')
438+
printJavascript(schema)
439+
printJSFooter('muvd')
324440

325441
# End

0 commit comments

Comments
 (0)