source: TI05-delivery/ows_framework/branches/ows_framework-refactor/ows_common/ows_common/helpers.py @ 3487

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/ows_framework/branches/ows_framework-refactor/ows_common/ows_common/helpers.py@3487
Revision 3487, 1.9 KB checked in by spascoe, 11 years ago (diff)
Line 
1# Copyright (C) 2007 STFC & NERC (Science and Technology Facilities Council).
2# This software may be distributed under the terms of the
3# Q Public License, version 1.0 or later.
4# http://ndg.nerc.ac.uk/public_docs/QPublic_license.txt
5"""
6Helper functions for constructing ows_common objects
7
8@author: Stephen Pascoe
9"""
10
11from ows_common.domain import Domain, PossibleValues
12from ows_common.operations_metadata import *
13from ows_common.wms import WmsDatasetSummary
14from ows_common.common import BoundingBox
15
16def domain(value=None, possibleValues=None, **kwargs):
17    """
18    Construct a domain object.
19
20    @param value: The defaultValue of the domain
21    @param possibleValues: Either a list of possible values,
22        a PossibleValues object or None to represent any value
23    @param kwargs: all other arguments passed to the Domain constructor.
24    """
25    if possibleValues is None:
26        pv = PossibleValues.fromAnyValue()
27    elif isinstance(possibleValues, PossibleValues):
28        pv = possibleValues
29    else:
30        pv = PossibleValues.fromAllowedValues(possibleValues)
31
32    return Domain(defaultValue=value, possibleValues=pv, **kwargs)
33
34def operation(uri, formats=[]):
35    """
36    Helper function for making Operation objects.
37
38    """
39    params = {'Format': domain(possibleValues=formats)}
40    return Operation(get=RequestMethod(href=uri), parameters=params)
41
42def wms_layer(uri, name, title, srs, bbox, abstract=None):
43    """
44    Helper function for making wms layer descriptions.
45
46    Parameters are mainly self explanitory.
47
48    @param bbox: A tuple (llx, lly, urx, ury)
49   
50    """
51    llx, lly, urx, ury = bbox
52
53    if abstract is None:
54        abstracts = []
55    else:
56        abstracts = [abstract]
57   
58    bboxObj = BoundingBox((llx, lly), (urx, ury), crs=srs)
59    ds = WmsDatasetSummary(identifier=name,
60                           titles=[title],
61                           boundingBoxes=[bboxObj],
62                           abstracts=abstracts)
63
64    return ds
Note: See TracBrowser for help on using the repository browser.