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

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

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