source: mauRepo/CedaMarkup/trunk/ceda_markup/gml/gml.py @ 8418

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/mauRepo/CedaMarkup/trunk/ceda_markup/gml/gml.py@8418
Revision 8418, 5.9 KB checked in by mnagni, 7 years ago (diff)

Incomplete - # 22513: missing ValidTime? in the GML tag library
 http://team.ceda.ac.uk/trac/ceda/ticket/22513

Even if this release adds the required tag, the most important difference with the version 0.0.2 is the library itself which has been deeply changed to add more flexibility for future development.
The main difference is that now the class is not composed by classes per markup type but from createXXX function per markup type which directly return an Element instance.

Another major add is a rich collection of unittests

  • Property svn:mime-type set to text/plain
RevLine 
[8369]1'''
2BSD Licence
3Copyright (c) 2012, Science & Technology Facilities Council (STFC)
4All rights reserved.
5
6Redistribution and use in source and binary forms, with or without modification,
7are permitted provided that the following conditions are met:
8
9    * Redistributions of source code must retain the above copyright notice,
10        this list of conditions and the following disclaimer.
11    * Redistributions in binary form must reproduce the above copyright notice,
12        this list of conditions and the following disclaimer in the documentation
13        and/or other materials provided with the distribution.
14    * Neither the name of the Science & Technology Facilities Council (STFC)
15        nor the names of its contributors may be used to endorse or promote
16        products derived from this software without specific prior written permission.
17
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29Created on 24 May 2012
30
31@author: Maurizio Nagni
32'''
[8418]33from ceda_markup.markup import createMarkup
[8369]34
[8418]35GML_NAMESPACE = 'http://www.opengis.net/gml'
36GML_PREFIX = 'gml'
37GML_ROOT_TAG = 'metadata'
38
39def createGML(root = None, tagName = GML_ROOT_TAG, ns = GML_NAMESPACE):     
[8369]40    '''
[8418]41        @param root: the root tag of the document containing this element
42        @param tagName: the tagName
43        @param ns: the tag namespace       
[8369]44    '''
[8418]45    return createMarkup(tagName, GML_PREFIX, ns, root)
[8369]46
[8418]47def createPosList(root = None, ns = GML_NAMESPACE, body = None, srsDimension = None):     
48    '''
49        @param root: the root tag of the document containing this element
50        @param ns: the tag namespace
51        @param body: a string like '45.256 -110.45 46.46 -109.48 43.84 -109.86 45.256 -110.45'
52        @param srsDimension: a number       
53    '''
54    markup = createMarkup('posList', GML_PREFIX, ns, root)
55    if srsDimension is not None: 
56        markup.set('srsDimension', srsDimension)
57    if body is not None:                               
58        markup.text = body
59    return markup
[8369]60
[8418]61def createLinearRing(root = None, ns = GML_NAMESPACE, body = None):     
[8369]62    '''
[8418]63        @param root: the root tag of the document containing this element
64        @param ns: the tag namespace
65        @param body: an instance of GML.PosList
[8369]66    '''
[8418]67    markup = createMarkup('LinearRing', GML_PREFIX, ns, root)
68    if body is not None:
69        markup.append(body)   
70    return markup       
[8369]71
[8418]72def createExterior(root = None, ns = GML_NAMESPACE, body = None):     
[8369]73    '''
[8418]74        @param root: the root tag of the document containing this element
75        @param ns: the tag namespace
76        @param body: an instance of GML.LinerRing
[8369]77    '''
[8418]78    markup = createMarkup('exterior', GML_PREFIX, ns, root)
79    if body is not None:
80        markup.append(body)   
81    return markup       
[8369]82
[8418]83def createPolygon(root = None, ns = GML_NAMESPACE, body = None):     
[8369]84    '''
[8418]85        @param root: the root tag of the document containing this element
86        @param ns: the tag namespace
87        @param body: an instance of GML.Exterior
[8369]88    '''
[8418]89    markup = createMarkup('Polygon', GML_PREFIX, ns, root)
90    if body is not None:
91        markup.append(body)
92    return markup       
93     
94def createValidTime(root = None, ns = GML_NAMESPACE, body = None):     
95    '''
96        @param root: the root tag of the document containing this element       
97        @param ns: the tag namespace
98        @param body: an instance of GML.TimePeriod       
99    '''
100    markup = createMarkup('validTime', GML_PREFIX, ns, root)
101    if body is not None:
102        markup.append(body)
103    return markup       
[8369]104
[8418]105def createTimePeriod(root = None, ns = GML_NAMESPACE, begin = None, end = None):     
[8369]106    '''
[8418]107        @param root: the root tag of the document containing this element
108        @param ns: the tag namespace
109        @param begin: an instance of GML.BeginPosition
110        @param end: an instance of GML.EndPosition
[8369]111    '''
[8418]112    markup = createMarkup('TimePeriod', GML_PREFIX, ns, root)
113    if begin is not None:
114        markup.append(begin)
115    if end is not None:
116        markup.append(end)
117    return markup       
118       
119def _createTimePositionType(itype, root = None, ns = GML_NAMESPACE, body = None):     
120    '''
121        @param itype: 'beginPosition' or endPosition   
122        @param root: the root tag of the document containing this element
123        @param ns: the tag namespace       
124        @param body: an instance of GML.TimePeriod       
125    '''
126    markup = createMarkup(itype, GML_PREFIX, ns, root)
127    if body is not None:
128        markup.append(body)
129    return markup       
[8369]130
[8418]131def createBeginPosition(root = None, ns = GML_NAMESPACE, body = None):     
132    '''   
133        @param root: the root tag of the document containing this element
134        @param ns: the tag namespace
135        @param body: a string
136    '''
137    markup = createMarkup('beginPosition', GML_PREFIX, ns, root)
138    if body is not None:
139        markup.text = body
140    return markup       
[8369]141   
[8418]142def createEndPosition(root = None, ns = GML_NAMESPACE, body = None):     
143    '''   
144        @param root: the root tag of the document containing this element
145        @param ns: the tag namespace
146        @param body: a string
147    '''
148    markup = createMarkup('endPosition', GML_PREFIX, ns, root)
149    if body is not None:
150        markup.text = body   
151    return markup         
Note: See TracBrowser for help on using the repository browser.