source: TI05-delivery/ows_framework/trunk/ows_server/ows_server/lib/wms_capabilities.py @ 2493

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/ows_framework/trunk/ows_server/ows_server/lib/wms_capabilities.py@2493
Revision 2493, 3.6 KB checked in by spascoe, 12 years ago (diff)

Implemented all metadata fields in WMS_Capabilities/Service.

Line 
1"""
2Utilities for extracting WMS 1.3.0 compatible metadata out of an
3OWS common 1.1.0 XML tree.
4
5@author: Stephen Pascoe
6
7"""
8
9from elementtree import ElementTree as ET
10
11# Namespaces
12ows_ns = 'http://www.opengis.net/ows/1.1'
13xlink_ns = 'http://www.w3.org/1999/xlink'
14
15# ElementTree utilities
16def qname(ns, tag):
17    return '{%s}%s' % (ns, tag)
18def path(items):
19    return '/'.join(items)
20
21def ows_path(items):
22    return path([qname(ows_ns, x) for x in items])
23
24def text_or_none(e):
25    if e is not None:
26        return e.text
27    else:
28        return e
29
30class WmsOwsAdapter(object):
31    """
32    This class is a facade over an OWS common XML tree which gives
33    easy access to key WMS metadata.
34
35    """
36    def __init__(self, ows_tree):
37        self.ows_tree = ows_tree
38
39    def _getTitle(self):
40        return text_or_none(self.ows_tree.find(
41            ows_path(['ServiceIdentification', 'Title'])))
42    title = property(_getTitle)
43
44    def _getAbstracts(self):
45        es = self.ows_tree.findall(ows_path(['ServiceIdentification', 'Abstract']))
46        return [x.text for x in es]
47    abstracts = property(_getAbstracts)
48
49    def _getKeywords(self):
50        es = self.ows_tree.findall(ows_path(['ServiceIdentification',
51                                             'Keywords',
52                                             'Keyword']))
53        return [x.text for x in es]
54    keywords = property(_getKeywords)
55
56    def _getOnlineResource(self):
57        return self.ows_tree.find(
58            ows_path(['ServiceProvider',
59                      'ProviderSite'])).attrib[qname(xlink_ns, 'href')]
60    onlineResource = property(_getOnlineResource)
61
62    def _getContactInformation(self):
63        """
64        This gets the first ServiceContact element.
65
66        """
67        d = {}
68        e = self.ows_tree.find(ows_path(['ServiceProvider', 'ServiceContact']))
69
70        d['person'] = text_or_none(e.find(qname(ows_ns, 'IndividualName')))
71
72        # This one doesn't map exactly.  Use ServiceProvider/ProviderName
73        d['organization'] = text_or_none(
74            self.ows_tree.find(ows_path(['ServiceProvider', 'ProviderName'])))
75
76        d['position'] = text_or_none(e.find(qname(ows_ns, 'PositionName')))
77
78        d['address'] = [x.text for x in
79                        e.findall(ows_path(['ContactInfo', 'Address',
80                                            'DeliveryPoint']))]
81        d['city'] = text_or_none(e.find(ows_path(['ContactInfo',
82                                                  'Address', 'City'])))
83        d['state_or_province'] = text_or_none(
84            e.find(ows_path(['ContactInfo', 'Address', 'AdministrativeArea'])))
85
86        d['postcode'] = text_or_none(
87            e.find(ows_path(['ContactInfo', 'Address', 'PostalCode'])))
88
89        d['country'] = text_or_none(
90            e.find(ows_path(['ContactInfo', 'Address', 'Country'])))
91
92        d['telephone'] = text_or_none(
93            e.find(ows_path(['ContactInfo', 'Phone', 'Voice'])))
94
95        d['fax'] = text_or_none(
96            e.find(ows_path(['ContactInfo', 'Phone', 'Facsimile'])))
97
98        d['email'] = text_or_none(
99            e.find(ows_path(['ContactInfo', 'Address',
100                             'ElectronicMailAddress'])))
101
102        return d
103    contactInformation = property(_getContactInformation)
104
105    def _getFees(self):
106        return text_or_none(
107            self.ows_tree.find(ows_path(['ServiceIdentification', 'Fees'])))
108    fees = property(_getFees)
109
110    def _getAccessConstraints(self):
111        return text_or_none(
112            self.ows_tree.find(ows_path(['ServiceIdentification',
113                                         'AccessConstraints'])))
114    accessConstraints = property(_getAccessConstraints)
Note: See TracBrowser for help on using the repository browser.