source: cows/trunk/cows/helpers.py @ 4912

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cows/trunk/cows/helpers.py@4917
Revision 4912, 2.3 KB checked in by spascoe, 11 years ago (diff)

Added LICENSE file and a short banner at the top of each python file.
Use add_license.py to add a license to new files.

NOTE: also contains a couple of files missed at last commit.

Line 
1# BSD Licence
2# Copyright (c) 2009, Science & Technology Facilities Council (STFC)
3# All rights reserved.
4#
5# See the LICENSE file in the source distribution of this software for
6# the full license text.
7
8# Copyright (C) 2007 STFC & NERC (Science and Technology Facilities Council).
9# This software may be distributed under the terms of the
10# Q Public License, version 1.0 or later.
11# http://ndg.nerc.ac.uk/public_docs/QPublic_license.txt
12"""
13Helper functions for constructing cows objects
14
15@author: Stephen Pascoe
16"""
17
18from cows.model import *
19
20def domain(value=None, possibleValues=None, **kwargs):
21    """
22    Construct a domain object.
23
24    @param value: The defaultValue of the domain
25    @param possibleValues: Either a list of possible values,
26        a PossibleValues object or None to represent any value
27    @param kwargs: all other arguments passed to the Domain constructor.
28    """
29    if possibleValues is None:
30        pv = PossibleValues.fromAnyValue()
31    elif isinstance(possibleValues, PossibleValues):
32        pv = possibleValues
33    else:
34        pv = PossibleValues.fromAllowedValues(possibleValues)
35
36    return Domain(defaultValue=value, possibleValues=pv, **kwargs)
37
38def operation(uri, formats=[]):
39    """
40    Helper function for making Operation objects.
41
42    """
43    params = {'Format': domain(possibleValues=formats)}
44    return Operation(get=RequestMethod(href=uri), parameters=params)
45
46def wms_layer(name, title, srs, bbox, abstract=None):
47    """
48    Helper function for making wms layer descriptions.
49
50    Parameters are mainly self explanitory.
51
52    @param bbox: A tuple (llx, lly, urx, ury)
53   
54    """
55    llx, lly, urx, ury = bbox
56
57    if abstract is None:
58        abstracts = []
59    else:
60        abstracts = [abstract]
61   
62    bboxObj = BoundingBox((llx, lly), (urx, ury), crs=srs)
63    ds = WmsDatasetSummary(identifier=name,
64                           titles=[title],
65                           boundingBoxes=[bboxObj],
66                           abstracts=abstracts)
67
68    return ds
69
70def wms_dimension(extent, units, unitSymbol):
71    """
72    Helper function for making wms dimension descriptions.
73
74    @todo: More parameters like current and multipleValues need implementing.
75
76    """
77    d = Dimension(valuesUnit=units,
78                  unitSymbol=unitSymbol,
79                  possibleValues=PossibleValues.fromAllowedValues(extent))
80   
81    return d
Note: See TracBrowser for help on using the repository browser.