source: ndgCommon/trunk/ndg/common/src/models/molesbounding.py @ 4793

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/ndgCommon/trunk/ndg/common/src/models/molesbounding.py@5136
Revision 4793, 2.5 KB checked in by cbyrom, 11 years ago (diff)

Checking in initial codebase for ndgUtils restructure.

Line 
1'''
2Data model for old moles bounding boxes - used by DIF model
3@author: C Byrom, Tessella Nov 08 (ported from geoUtilities)
4'''
5
6class Bounding:
7    ''' Separated out because this is NDG specific really
8    NB needs to support multiple bounding boxes properly and doesn't ...
9    '''
10    def __init__(self,elem,helper,entity='moles'):
11        '''
12        Parse a data entity and load a boundimatch={'moles':
13                 {'North':'*//dgSpatialCoverage/BoundingBox/LimitNorth',
14                  'South':'*//dgSpatialCoverage/BoundingBox/LimitSouth',
15                  'West':'*//dgSpatialCoverage/BoundingBox/LimitWest',
16                  'East':'*//dgSpatialCoverage/BoundingBox/LimitEast'},
17                'DIF':
18                 {'North':'Spatial_Coverage/Northernmost_Latitude',
19                  'South':'Spatial_Coverage/Southernmost_Latitude',
20                  'West':'Spatial_Coverage/Westernmost_Longitude',
21                  'East':'Spatial_Coverage/Easternmost_Longitude'}
22                }ng box
23        '''
24        #don't think this will work for multiple bounding boxes in a DIF ... yet
25        parent={'moles':'*//dgSpatialCoverage/BoundingBox',
26                'DIF':'Spatial_Coverage'}
27        #N,W,E,S
28        ebox={'moles':['LimitNorth','LimitWest','LimitEast','LimitSouth'],
29              'DIF':['Northernmost_Latitude','Westernmost_Longitude',
30                     'Easternmost_Longitude','Southernmost_Latitude']}
31        coverages=helper.findall(elem,parent[entity])
32        self.boxes=[]
33        self.nboxes=0
34        for coverage in coverages:
35            self.set([helper.getText(coverage,i) for i in ebox[entity]])
36
37    def geoString2float(self, x):
38        if x[-1:] in 'NE':
39            return float(x[:-1])
40        elif x[-1:] in 'SW':
41            return -float(x[:-1])
42        else:
43            return float(x)
44       
45    def set(self,box):
46        try: 
47            self.boxes.append([self.geoString2float(i) for i in box])
48            self.nboxes+=1
49        except:
50            pass
51       
52    def toHTMLbox(self):
53        if self.nboxes!=1:
54            return '<p> Record includes %s bounding boxes </p>'%self.nboxes
55        else:
56            return '''<table><tbody><tr><td colspan="2" align="center">%s</td></tr>
57                      <tr><td>%s,</td><td>&nbsp;%s</td></tr>
58                      <tr><td colspan="2" align="center">%s</td></tr>
59                    </tbody></table>'''%tuple(self.boxes[0])
60                   
61    def __str__(self):
62        return '%s,%s'%(self.nboxes,self.boxes)
63       
Note: See TracBrowser for help on using the repository browser.