source: TI05-delivery/ows_framework/trunk/ows_server/ows_server/models/geoUtilities.py @ 2680

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/ows_framework/trunk/ows_server/ows_server/models/geoUtilities.py@2680
Revision 2680, 2.6 KB checked in by lawrence, 13 years ago (diff)

ows stack now has the equivalent support for DIF to
the older wsgi stack

Line 
1from Utilities import wrapGetText
2
3def geoString2float(x):
4    if x[-1:] in 'NE':
5        return float(x[:-1])
6    elif x[-1:] in 'SW':
7        return -float(x[:-1])
8    else:
9        return float(x)
10
11class Bounding:
12    ''' Separated out because this is NDG specific really
13    NB needs to support multiple bounding boxes properly and doesn't ... '''
14    def __init__(self,elem,entity='stubB',getter=wrapGetText):
15        '''Parse a data entity and load a bounding box '''
16        match={'stubB':
17                 {'North':'dgDataSummary/dgDataCoverage/dgSpatialCoverage/BoundingBox/LimitNorth',
18                  'South':'dgDataSummary/dgDataCoverage/dgSpatialCoverage/BoundingBox/LimitSouth',
19                  'West':'dgDataSummary/dgDataCoverage/dgSpatialCoverage/BoundingBox/LimitWest',
20                  'East':'dgDataSummary/dgDataCoverage/dgSpatialCoverage/BoundingBox/LimitEast'},
21                'DIF':
22                 {'North':'Spatial_Coverage/Northernmost_Latitude',
23                  'South':'Spatial_Coverage/Southernmost_Latitude',
24                  'West':'Spatial_Coverage/Westernmost_Longitude',
25                  'East':'Spatial_Coverage/Easternmost_Longitude'}
26                }
27        #try:
28        North=getter(elem,match[entity]['North'])
29        South=getter(elem,match[entity]['South'])
30        West=getter(elem,match[entity]['West'])
31        East=getter(elem,match[entity]['East'])
32        self.boxes=[]
33        self.nboxes=0
34       
35        self.set([North,West,East,South])
36       
37    def set(self,box):
38        try: 
39            self.boxes.append([geoString2float(i) for i in box])
40            self.nboxes+=1
41        except:
42            pass
43       
44    def toHTMLbox(self):
45        if self.nboxes!=1:
46            return '<p> Record includes %s bounding boxes </p>'%self.nboxes
47        else:
48            return '''<table><tbody><tr><td colspan="2" align="center">%s</td></tr>
49                      <tr><td>%s,</td><td>&nbsp;%s</td></tr>
50                      <tr><td colspan="2" align="center">%s</td></tr>
51                    </tbody></table>'''%tuple(self.boxes[0])
52
53class TimeCoverage:
54    def __init__(self,tc):
55        ''' Takes a tuple of (start date, end date, status) '''
56        copy=[]
57        for i in tc:
58            if i=='': 
59                copy.append('Unknown')
60            else: copy.append(i)
61        self.data=tuple(copy)
62    def __str__(self):
63        if self.data==('Unknown','Unknown','Unknown'): 
64            return 'Unknown'
65        else:
66            print self.data
67            return 'Start Date:%s, End Date:%s<br/>Status:%s'%self.data
68    def __getitem__(self,i):
69        return self.data[i]
70       
Note: See TracBrowser for help on using the repository browser.