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 | """ |
---|
6 | Helper functions for constructing cows objects |
---|
7 | |
---|
8 | @author: Stephen Pascoe |
---|
9 | """ |
---|
10 | |
---|
11 | from cows.model import * |
---|
12 | |
---|
13 | def domain(value=None, possibleValues=None, **kwargs): |
---|
14 | """ |
---|
15 | Construct a domain object. |
---|
16 | |
---|
17 | @param value: The defaultValue of the domain |
---|
18 | @param possibleValues: Either a list of possible values, |
---|
19 | a PossibleValues object or None to represent any value |
---|
20 | @param kwargs: all other arguments passed to the Domain constructor. |
---|
21 | """ |
---|
22 | if possibleValues is None: |
---|
23 | pv = PossibleValues.fromAnyValue() |
---|
24 | elif isinstance(possibleValues, PossibleValues): |
---|
25 | pv = possibleValues |
---|
26 | else: |
---|
27 | pv = PossibleValues.fromAllowedValues(possibleValues) |
---|
28 | |
---|
29 | return Domain(defaultValue=value, possibleValues=pv, **kwargs) |
---|
30 | |
---|
31 | def operation(uri, formats=[]): |
---|
32 | """ |
---|
33 | Helper function for making Operation objects. |
---|
34 | |
---|
35 | """ |
---|
36 | params = {'Format': domain(possibleValues=formats)} |
---|
37 | return Operation(get=RequestMethod(href=uri), parameters=params) |
---|
38 | |
---|
39 | def wms_layer(name, title, srs, bbox, abstract=None): |
---|
40 | """ |
---|
41 | Helper function for making wms layer descriptions. |
---|
42 | |
---|
43 | Parameters are mainly self explanitory. |
---|
44 | |
---|
45 | @param bbox: A tuple (llx, lly, urx, ury) |
---|
46 | |
---|
47 | """ |
---|
48 | llx, lly, urx, ury = bbox |
---|
49 | |
---|
50 | if abstract is None: |
---|
51 | abstracts = [] |
---|
52 | else: |
---|
53 | abstracts = [abstract] |
---|
54 | |
---|
55 | bboxObj = BoundingBox((llx, lly), (urx, ury), crs=srs) |
---|
56 | ds = WmsDatasetSummary(identifier=name, |
---|
57 | titles=[title], |
---|
58 | boundingBoxes=[bboxObj], |
---|
59 | abstracts=abstracts) |
---|
60 | |
---|
61 | return ds |
---|
62 | |
---|
63 | def wms_dimension(extent, units, unitSymbol): |
---|
64 | """ |
---|
65 | Helper function for making wms dimension descriptions. |
---|
66 | |
---|
67 | @todo: More parameters like current and multipleValues need implementing. |
---|
68 | |
---|
69 | """ |
---|
70 | d = Dimension(valuesUnit=units, |
---|
71 | unitSymbol=unitSymbol, |
---|
72 | possibleValues=PossibleValues.fromAllowedValues(extent)) |
---|
73 | |
---|
74 | return d |
---|