source: TI02-CSML/trunk/Examples/BODC/demoCreateBODCPointSeries.py @ 1502

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI02-CSML/trunk/Examples/BODC/demoCreateBODCPointSeries.py@1502
Revision 1502, 4.0 KB checked in by domlowe, 13 years ago (diff)

added notes to BODC example

Line 
1''' demo - how to create typical BODC PointSeries Feature using attributes of parser objects.
2 Dominic Lowe 07 August 2006, (c) BADC, CCLRC
3 updated 07 September 2006 to reflect new module structure
4 the only changes are:
5     different imports
6     prefixed parser objects with csml.parser.
7     renamed variable 'csml' to 'csmldoc' to avoid conflict with package names
8  '''
9
10import csml.parser
11import csml.parser_extra
12
13
14####################################################
15#You will need to get your values using SQL and store them in variables. For now I have hardcoded some values below. I've put them in capitals so they stand out from the names of the CMSL parser objects.
16####################################################
17
18#the dataset:
19DSID='HGFS4082'
20METADATAPROP='http://ndg.nerc.ac.uk/Metadata/HGFS4082'
21DESC='Sea level time series from the Lea tide gauge at Wick between January 1972 and December 1975.'
22NAME = 'HGFS4082'
23CODESPACE='http://ndg.nerc.ac.uk/NDGData'
24
25
26#the feature + feature collection bounding box:
27ID='feat01'
28DESC2='Surface elevation (unspecified datum) of the water column'
29SRSNAME='urn:EPSG:geographicCRS:4326'
30TRAJECTORY_LOCATIONS = '58.4417 -3.085'
31TRAJECTORY_TIMES ='1972-01-01 1975-02-31'
32#for the netcdf extract:
33ARRAYSIZE='8784'
34FILENAME='/users/bodc3/pxf2qxf/b0240000/b0244122.qxf /users/bodc3/pxf2qxf/b0240000/b0244134.qxf /users/bodc3/pxf2qxf/b0240000/b0244146.qxf /users/bodc3/pxf2qxf/b0240000/b0244158.qxf'
35VARIABLENAME='ASLVZZ01'
36
37
38  #########################################
39##  Now start construction of CSML objects ##
40  #########################################
41
42
43
44####### FeatureCollection ###############
45
46# #empty list to hold featureMembers
47fms =[]
48
49
50# #### add a PointSeriesFeature: #####
51ptsf=csml.parser.PointSeriesFeature()
52ptsf.id=ID
53ptsf.description=csml.parser.Description(DESC2)
54#domain:
55ptsd=csml.parser.PointSeriesDomain()
56t=csml.parser.Trajectory()
57t.srsName=SRSNAME
58t.locations=csml.parser.DirectPositionList(vals=TRAJECTORY_LOCATIONS)
59t.times=csml.parser.TimePositionList(TRAJECTORY_TIMES)
60ptsd.domainReference=t
61
62#rangeSet
63rs=csml.parser.RangeSet()
64ncExtract=csml.parser.NetCDFExtract()
65ncExtract.arraySize = ARRAYSIZE
66ncExtract.fileName=FILENAME
67ncExtract.variableName=VARIABLENAME
68rs.arrayDescriptor=ncExtract
69
70#add domain and rangeset to feature
71ptsf.rangeSet=rs
72ptsf.domain=ptsd
73#add feature to collection
74fms.append(ptsf)
75
76
77
78# #instantiate FeatureCollection object:
79fc=csml.parser.FeatureCollection(members=fms)
80#etp is the bounding box for the feature. Again I've hard coded some values into variables.
81
82LOWER='58.4417 -3.085'
83UPPER='58.4417 -3.085'
84T1='1972-01-01T06:00:00'
85T2='1975-12-31T00:00:00'
86
87
88etp = csml.parser.EnvelopeWithTimePeriod()
89etp.srsName=SRSNAME
90etp.lowerCorner=csml.parser.DirectPosition(LOWER ,uomLabels='deg deg',axisLabels='lat lon')
91etp.upperCorner=csml.parser.DirectPosition(UPPER ,uomLabels='deg deg',axisLabels='lat lon')
92etp.timePosition=T1
93etp.timePosition2=T2
94fc.boundedBy=etp
95
96
97#Now, put it all together at the dataset level
98
99#MetaDataProperty Object of <Dataset>
100#list to hold multiple metaDataProperty elements
101mds = []
102md =csml.parser.MetaDataProperty()
103md.href = DESC
104mds.append(md)
105
106########### The Dataset  ##############
107#Create an Empty Dataset
108ds = csml.parser.Dataset()
109#Set objects as attributes of dataset
110#NOTE: you can equally write this in the form: ds.id = 'Test001'  as used above.
111ds.id=DSID
112ds.metaDataProperty=mds
113ds.name = csml.parser.Name(val=[NAME],codeSpace=CODESPACE)
114ds.description=csml.parser.Description(DESC)  #this is a description object!
115ds.featureCollection = fc
116
117
118########################################
119
120
121#call the toXML method of the Dataset object:
122csmldoc = ds.toXML()
123#parse and pretty print the result
124strCSML=csml.parser_extra.PrettyPrint(csmldoc)
125strCSML=csml.parser_extra.removeInlineNS(strCSML)
126print strCSML
127
128#(you could save this (strCSML)  to file instead of just printing..)
Note: See TracBrowser for help on using the repository browser.