Changeset 896


Ignore:
Timestamp:
08/05/06 11:44:45 (13 years ago)
Author:
domlowe
Message:

Added some checking for mandatory csml elements

Location:
TI02-CSML/trunk/newparser
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • TI02-CSML/trunk/newparser/Parser.py

    r888 r896  
    7676def checkMandatory(obj,*args): 
    7777    #check mandatory attributes/elements are present. 
    78     #should be called at the *end* of each fromXML method 
     78    #should be called at the *end* of each fromXML method if that object has mandatory attributes 
    7979    for arg in args: 
    8080        if not hasattr(obj, arg): 
     
    286286    def fromXML(self,csmlFrag): 
    287287        AbstractGML.fromXML(self,csmlFrag) 
    288         #TO DO: how  best to handle errors? 
     288        #checkMandatory(self, 'id') 
    289289        if not hasattr(self,'id'): 
    290290            #print 'gml:id mandatory value missing in ' + csmlFrag.tag 
     291            #how best to handle the case where there is an xlink to the definition, 
     292            #so the reference to the definition object doesn't actually have an id 
    291293            pass 
    292294    def toXML(self,csmlFrag): 
     
    338340        if csmlFrag.attrib.has_key('factor'): 
    339341            self.factor=csmlFrag.attrib['factor'] 
     342        checkMandatory(self,'unit') 
    340343    def toXML(self,csmlFrag): 
    341344        csmlFrag.text=self.data 
     
    905908            if frag.tag==GML('axisDirection'): 
    906909                self.axisDirection=frag.text 
     910            checkMandatory(self,'uom') 
    907911    def toXML(self,csmlFrag): 
    908912        CoordinateSystemAxisBase.toXML(self,csmlFrag) 
     
    982986                self.usesAxes.append(CoordinateSystemAxis()) 
    983987                self.usesAxes[-1].fromXML(frag.getchildren()[0]) 
    984  
     988        checkMandatory(self,'usesAxes') 
    985989    def toXML(self,csmlFrag): 
    986990        AbstractCoordinateSystemBase.toXML(self, csmlFrag) 
     
    13191323                    definitionMember.fromXML(subFrag) 
    13201324                    self.definitionMembers.append(definitionMember) 
     1325        checkMandatory(self,'definitionMembers') 
    13211326    def toXML(self,csmlFrag): 
    13221327        Definition.toXML(self,csmlFrag) 
     
    14211426            elif frag.tag == CSML('numericTransform'): 
    14221427                self.numericTransform = frag.text 
     1428        checkMandatory(self,'arraySize') 
    14231429    def toXML(self,csmlFrag): 
    14241430        csmlFrag = AbstractGML.toXML(self,csmlFrag) 
     
    19691975        if csmlFrag.attrib.has_key('uom'): 
    19701976            self.uom = csmlFrag.attrib['uom'] 
     1977        checkMandatory(self,'uom') 
    19711978    def toXML(self, csmlFrag): 
    19721979        if hasattr(self,'vals'): 
  • TI02-CSML/trunk/newparser/ioDemo.py

    r888 r896  
    2929    featureType = csml.getFeatureType(featureList[i]) 
    3030    print featureType 
    31      
    32      
     31 
     32 
    3333#get type of single feature  
    3434#eg featureType=csml.getFeatureType('feat04') 
    3535 
    3636domainref=csml.getDomainReference('solar_3') 
    37 #print 'domainref: ' + str(domainref) 
     37print 'domainref: ' + str(domainref) 
    3838domaincomp=csml.getDomainComplement('solar_3') 
    39 #print 'domaincomp: ' + str(domaincomp) 
     39print 'domaincomp: ' + str(domaincomp) 
    4040domain=csml.getDomain('solar_3') 
    41 #print 'domain: ' + str(domain) 
     41print 'domain: ' + str(domain) 
    4242#featureValues=csml.getDataForFeature('solar_3', None) 
    4343 
    4444 
    4545timelist = domainref['t'] 
    46 #make some selection from the available times: 
     46#make some selection from the available times/spatialdomain: 
    4747timeSelection = timelist.split()[:2] 
    48 #featureValues=csml.getDataForFeature('solar_3',timeSelection, latitude=(0.,10.0), longitude=(90, 100.0)) 
    4948spatialSubsetDictionary= {} 
    5049spatialSubsetDictionary['latitude']=(0.,10.0) 
     
    5352featureValues=csml.getDataForFeature('solar_3', timeSelection, **spatialSubsetDictionary) 
    5453 
    55 #same as: 
    56 #featureValues=csml.getDataForFeature('solar_3',timeSelection, latitude=(0.,10.0), longitude=(90, 100.0)) 
    5754print featureValues 
    58 sys.exit() 
    59  
    60 print type(featureValues) 
     55#print type(featureValues) 
    6156#print dir(featureValues) 
    62 #print featureValues 
    63  
    64 #print 'Feature rangeSet:' +str(featureValues) 
    65  
    6657 
    6758#get gml description (long name) of feature 
     
    7970#dataArray = csml.getData(fileExtractID) 
    8071#dataArray = csml.getData('feat04times') 
    81 for extract in fileExtractList: 
    82     print extract 
    83     dataArray=csml.getDataForExtract(extract) 
     72#for extract in fileExtractList: 
     73  #  print extract 
     74    #dataArray=csml.getDataForExtract(extract) 
    8475    #print extract 
    8576    #print dataArray 
  • TI02-CSML/trunk/newparser/test.py

    r888 r896  
    1818tree = ElementTree(file='example.xml') 
    1919#tree = ElementTree(file='nagridseries.xml') 
     20#tree = ElementTree(file='bodc.xml') 
    2021dataset = Dataset() 
    2122 
Note: See TracChangeset for help on using the changeset viewer.