1 | from Utilities import wrapGetText |
---|
2 | |
---|
3 | def 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 | |
---|
11 | class 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> %s</td></tr> |
---|
50 | <tr><td colspan="2" align="center">%s</td></tr> |
---|
51 | </tbody></table>'''%tuple(self.boxes[0]) |
---|
52 | |
---|
53 | def __str__(self): |
---|
54 | return '%s,%s'%(self.nboxes,self.boxes) |
---|
55 | |
---|
56 | class TimeCoverage: |
---|
57 | def __init__(self,tc): |
---|
58 | ''' Takes a tuple of (start date, end date, status) ''' |
---|
59 | copy=[] |
---|
60 | for i in tc: |
---|
61 | if i=='': |
---|
62 | copy.append('Unknown') |
---|
63 | else: copy.append(i) |
---|
64 | self.data=tuple(copy) |
---|
65 | def __str__(self): |
---|
66 | if self.data==('Unknown','Unknown','Unknown'): |
---|
67 | return 'Unknown' |
---|
68 | else: |
---|
69 | print self.data |
---|
70 | return 'Start Date:%s, End Date:%s<br/>Status:%s'%self.data |
---|
71 | def __getitem__(self,i): |
---|
72 | return self.data[i] |
---|
73 | |
---|