source: MILK/trunk/milk_server/milk_server/lib/geoUtilities.py @ 4469

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/MILK/trunk/milk_server/milk_server/lib/geoUtilities.py@4469
Revision 4469, 2.6 KB checked in by cbyrom, 12 years ago (diff)

Strip out code not relevant to MILK - mainly WCS and WMS stuff - also including the CSML server code + trackback code
Also tidy up structure of 'public' dir - setting up new 'style' dir and
centralising icons in icons dir + remove all unused icons, javascript and stylesheets.
Also strip out testcase code and populate new test directory structure.

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