Changes between Version 5 and Version 6 of UsingTheParserToCreateCSML


Ignore:
Timestamp:
13/09/06 14:47:57 (13 years ago)
Author:
domlowe
Comment:

Edited page on using the parser to create csml

Legend:

Unmodified
Added
Removed
Modified
  • UsingTheParserToCreateCSML

    v5 v6  
    2424{{{ 
    2525#!python 
    26 from Parser import * 
    27 import parser_extra 
     26import csml.parser 
     27import csml.parser_extra 
    2828 
    2929 
     
    3636#empty list to hold definitionMembers 
    3737dm=[] 
    38 tc=TimeCoordinateSystem() 
     38tc=csml.parser.TimeCoordinateSystem() 
    3939dm.append(tc) 
    40 rsd=ReferenceSystemDefinitions(definitionMembers=dm) 
     40rsd=csml.parser.ReferenceSystemDefinitions(definitionMembers=dm) 
    4141 
    4242 
     
    4949 
    5050# #### add a PointSeriesFeature: ##### 
    51 ptsf=PointSeriesFeature() 
     51ptsf=csml.parser.PointSeriesFeature() 
    5252ptsf.id='testbed270401' 
    53 ptsf.description=Description('Station BLUEBIRD') 
    54 ptsd=PointSeriesDomain() 
    55 t=Trajectory() 
     53ptsf.description=csml.parser.Description('Station BLUEBIRD') 
     54ptsd=csml.parser.PointSeriesDomain() 
     55t=csml.parser.Trajectory() 
    5656t.srsName='urn:EPSG:geographicCRS:4326' 
    57 t.locations=DirectPositionList(vals='0.1 1.5 25') 
    58 t.times=TimePositionList('#pred20060427001','-18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60') 
     57t.locations=csml.parser.DirectPositionList(vals='0.1 1.5 25') 
     58t.times=csml.parser.TimePositionList('#pred20060427001','-18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60') 
    5959ptsd.domainReference=t 
    6060ptsf.domain=ptsd 
    61 rs=RangeSet() 
    62 rs.quantityList=MeasureOrNullList('MLUnits.xml#m', '0.27 0.25 0.25 0.23 0.22 0.22 0.21 0.17 0.17 0.14 0.14 0.12 0.10 0.08 0.08 0.08 0.11 0.13 0.11 0.11 0.13 0.10 0.06 0.06 0.06 0.01 -0.03 -0.06 -0.09 -0.11 -0.11 -0.13 -0.16 -0.18 -0.17 -0.16 -0.18 -0.16 -0.12 -0.09 -0.08 -0.07 -0.06 -0.05 -0.04 -0.03 -0.03 -0.04 -0.02 -0.01 -0.02 -0.02 -0.02 -0.03 -0.03 -0.02 -0.01 -0.01 -0.02 -0.02 -0.03 -0.04 -0.04 -0.05 -0.04 -0.05 -0.08 -0.09 -0.11 -0.12 -0.12 -0.12 -0.12 -0.12 -0.13 -0.14 -0.15') 
     61rs=csml.parser.RangeSet() 
     62rs.quantityList=csml.parser.MeasureOrNullList('MLUnits.xml#m', '0.27 0.25 0.25 0.23 0.22 0.22 0.21 0.17 0.17 0.14 0.14 0.12 0.10 0.08 0.08 0.08 0.11 0.13 0.11 0.11 0.13 0.10 0.06 0.06 0.06 0.01 -0.03 -0.06 -0.09 -0.11 -0.11 -0.13 -0.16 -0.18 -0.17 -0.16 -0.18 -0.16 -0.12 -0.09 -0.08 -0.07 -0.06 -0.05 -0.04 -0.03 -0.03 -0.04 -0.02 -0.01 -0.02 -0.02 -0.02 -0.03 -0.03 -0.02 -0.01 -0.01 -0.02 -0.02 -0.03 -0.04 -0.04 -0.05 -0.04 -0.05 -0.08 -0.09 -0.11 -0.12 -0.12 -0.12 -0.12 -0.12 -0.13 -0.14 -0.15') 
    6363ptsf.rangeSet=rs 
    6464fms.append(ptsf) 
     
    6767 
    6868# #instantiate FeatureCollection object: 
    69 fc=FeatureCollection(members=fms) 
    70 etp = EnvelopeWithTimePeriod() 
    71 etp.lowerCorner=DirectPosition('42 12',uomLabels='deg deg',axisLabels='lat lon') 
    72 etp.upperCorner=DirectPosition('42 26',uomLabels='deg deg',axisLabels='lat lon') 
     69fc=csml.parser.FeatureCollection(members=fms) 
     70etp = csml.parser.EnvelopeWithTimePeriod() 
     71etp.lowerCorner=csml.parser.DirectPosition('42 12',uomLabels='deg deg',axisLabels='lat lon') 
     72etp.upperCorner=csml.parser.DirectPosition('42 26',uomLabels='deg deg',axisLabels='lat lon') 
    7373etp.timePosition='2006-04-26T06:00:00+01' 
    7474etp.timePosition2='2006-04-29T012:00:00+01' 
     
    8181mds = [] 
    8282 
    83 md = MetaDataProperty() 
     83md = csml.parser.MetaDataProperty() 
    8484md.text=['Data (c) 2006 CCLRC // www.cclrc.ac.uk'] 
    8585mds.append(md) 
    8686 
    87 md = MetaDataProperty() 
     87md = csml.parser.MetaDataProperty() 
    8888md.text=['Test for CCLRC'] 
    8989mds.append(md) 
     
    9393########### The Dataset  ############## 
    9494#Create an Empty Dataset 
    95 ds = Dataset() 
     95ds = csml.parser.Dataset() 
    9696#Set objects as attributes of dataset 
    9797#NOTE: you can equally write this in the form: ds.id = 'Test001'  as used above. 
    9898setattr(ds,'id','Test001') 
    9999setattr(ds, 'metaDataProperty', mds) 
    100 setattr(ds,'description',Description('This is a test Water level.Period 26/04/06 06h -> 29/04/06 12h')) 
     100setattr(ds,'description',csml.parser.Description('This is a test Water level.Period 26/04/06 06h -> 29/04/06 12h')) 
    101101setattr(ds, 'referenceSystemDefinitions', rsd) 
    102102setattr(ds, 'featureCollection',fc) 
     
    104104 
    105105#call the toXML method of the Dataset object: 
    106 csml = ds.toXML() 
     106csmldoc = ds.toXML() 
    107107#parse and pretty print the result 
    108 strCSML=parser_extra.PrettyPrint(csml) 
    109 strCSML=parser_extra.removeInlineNS(strCSML) 
     108strCSML=csml.parser_extra.PrettyPrint(csmldoc) 
     109strCSML=csml.parser_extra.removeInlineNS(strCSML) 
    110110print strCSML 
    111111 
     
    120120{{{ 
    121121#!python 
    122 from Parser import * 
    123 import parser_extra 
     122import csml.parser 
     123import csml.parser_extra 
    124124}}}  
    125125 
     
    132132########### The Dataset  ############## 
    133133#Create an Empty Dataset 
    134 ds = Dataset() 
     134ds = csml.parser.Dataset() 
    135135#Set objects as attributes of dataset 
    136136#NOTE: you can equally write this in the form: ds.id = 'Test001'  as used above. 
    137137setattr(ds,'id','Test001') 
    138138setattr(ds, 'metaDataProperty', mds) 
    139 setattr(ds,'description',Description('This is a test Water level.Period 26/04/06 06h -> 29/04/06 12h')) 
     139setattr(ds,'description',csml.parser.Description('This is a test Water level.Period 26/04/06 06h -> 29/04/06 12h')) 
    140140setattr(ds, 'referenceSystemDefinitions', rsd) 
    141141setattr(ds, 'featureCollection',fc) 
     
    156156##### now create a PointSeriesFeature: ##### 
    157157##### see how you build up the domain and rangeSet #### 
    158 ptsf=PointSeriesFeature() 
     158ptsf=csml.parser.PointSeriesFeature() 
    159159ptsf.id='testbed270401' 
    160 ptsf.description=Description('Station BLUEBIRD') 
    161 ptsd=PointSeriesDomain() 
    162 t=Trajectory() 
     160ptsf.description=csml.parser.Description('Station BLUEBIRD') 
     161ptsd=csml.parser.PointSeriesDomain() 
     162t=csml.parser.Trajectory() 
    163163t.srsName='urn:EPSG:geographicCRS:4326' 
    164 t.locations=DirectPositionList(vals='0.1 1.5 25') 
    165 t.times=TimePositionList('#pred20060427001','-18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60') 
     164t.locations=csml.parser.DirectPositionList(vals='0.1 1.5 25') 
     165t.times=csml.parser.TimePositionList('#pred20060427001','-18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60') 
    166166ptsd.domainReference=t 
    167167ptsf.domain=ptsd 
    168 rs=RangeSet() 
    169 rs.quantityList=MeasureOrNullList('MLUnits.xml#m', '0.27 0.25 0.25 0.23 0.22 0.22 0.21 0.17 0.17 0.14 0.14 0.12 0.10 0.08 0.08 0.08 0.11 0.13 0.11 0.11 0.13 0.10 0.06 0.06 0.06 0.01 -0.03 -0.06 -0.09 -0.11 -0.11 -0.13 -0.16 -0.18 -0.17 -0.16 -0.18 -0.16 -0.12 -0.09 -0.08 -0.07 -0.06 -0.05 -0.04 -0.03 -0.03 -0.04 -0.02 -0.01 -0.02 -0.02 -0.02 -0.03 -0.03 -0.02 -0.01 -0.01 -0.02 -0.02 -0.03 -0.04 -0.04 -0.05 -0.04 -0.05 -0.08 -0.09 -0.11 -0.12 -0.12 -0.12 -0.12 -0.12 -0.13 -0.14 -0.15') 
     168rs=csml.parser.RangeSet() 
     169rs.quantityList=csml.parser.MeasureOrNullList('MLUnits.xml#m', '0.27 0.25 0.25 0.23 0.22 0.22 0.21 0.17 0.17 0.14 0.14 0.12 0.10 0.08 0.08 0.08 0.11 0.13 0.11 0.11 0.13 0.10 0.06 0.06 0.06 0.01 -0.03 -0.06 -0.09 -0.11 -0.11 -0.13 -0.16 -0.18 -0.17 -0.16 -0.18 -0.16 -0.12 -0.09 -0.08 -0.07 -0.06 -0.05 -0.04 -0.03 -0.03 -0.04 -0.02 -0.01 -0.02 -0.02 -0.02 -0.03 -0.03 -0.02 -0.01 -0.01 -0.02 -0.02 -0.03 -0.04 -0.04 -0.05 -0.04 -0.05 -0.08 -0.09 -0.11 -0.12 -0.12 -0.12 -0.12 -0.12 -0.13 -0.14 -0.15') 
    170170ptsf.rangeSet=rs 
    171171fms.append(ptsf) 
     
    182182#!python 
    183183# #instantiate FeatureCollection object: 
    184 fc=FeatureCollection(members=fms) 
    185 etp = EnvelopeWithTimePeriod() 
    186 etp.lowerCorner=DirectPosition('42 12',uomLabels='deg deg',axisLabels='lat lon') 
    187 etp.upperCorner=DirectPosition('42 26',uomLabels='deg deg',axisLabels='lat lon') 
     184fc=csml.parser.FeatureCollection(members=fms) 
     185etp = csml.parser.EnvelopeWithTimePeriod() 
     186etp.lowerCorner=csml.parser.DirectPosition('42 12',uomLabels='deg deg',axisLabels='lat lon') 
     187etp.upperCorner=csml.parser.DirectPosition('42 26',uomLabels='deg deg',axisLabels='lat lon') 
    188188etp.timePosition='2006-04-26T06:00:00+01' 
    189189etp.timePosition2='2006-04-29T012:00:00+01' 
     
    200200#empty list to hold definitionMembers 
    201201dm=[] 
    202 tc=TimeCoordinateSystem() 
     202tc=csml.parser.TimeCoordinateSystem() 
    203203dm.append(tc) 
    204 rsd=ReferenceSystemDefinitions(definitionMembers=dm) 
     204rsd=csml.parser.ReferenceSystemDefinitions(definitionMembers=dm) 
    205205}}} 
    206206 
     
    215215mds = [] 
    216216 
    217 md = MetaDataProperty() 
     217md = csml.parser.MetaDataProperty() 
    218218md.text=['Data (c) 2006 CCLRC // www.cclrc.ac.uk'] 
    219219mds.append(md) 
    220220 
    221 md = MetaDataProperty() 
     221md = csml.parser.MetaDataProperty() 
    222222md.text=['Test for CCLRC'] 
    223223mds.append(md) 
     
    231231########### The Dataset  ############## 
    232232#Create an Empty Dataset 
    233 ds = Dataset() 
     233ds = csml.parser.Dataset() 
    234234#Set objects as attributes of dataset 
    235235#NOTE: you can equally write this in the form: ds.id = 'Test001'  as used above. 
    236236setattr(ds,'id','Test001') 
    237237setattr(ds, 'metaDataProperty', mds) 
    238 setattr(ds,'description',Description('This is a test Water level. Period 26/04/06 06h -> 29/04/06 12h')) 
     238setattr(ds,'description',csml.parser.Description('This is a test Water level. Period 26/04/06 06h -> 29/04/06 12h')) 
    239239setattr(ds, 'referenceSystemDefinitions', rsd) 
    240240setattr(ds, 'featureCollection',fc) 
     
    248248#!python 
    249249#call the toXML method of the Dataset object: 
    250 csml = ds.toXML() 
     250csmldoc = ds.toXML() 
    251251#parse and pretty print the result 
    252 strCSML=parser_extra.PrettyPrint(csml) 
    253 strCSML=parser_extra.removeInlineNS(strCSML) 
     252strCSML=csml.parser_extra.PrettyPrint(csmldoc) 
     253strCSML=csml.parser_extra.removeInlineNS(strCSML) 
    254254print strCSML 
    255255#(you could save this to file instead)