Ignore:
Timestamp:
19/10/06 12:40:50 (13 years ago)
Author:
domlowe
Message:

ongoing changes to csml2moles.py - convenient time to commit

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI02-CSML/trunk/csml2MolesStuff/csml2moles.py

    r1607 r1608  
    66import elementtree.ElementTree as etree 
    77import datetime 
     8import molesWriter 
    89#this is a fix to the  ElementTree namespace problem that namespaces are usually represented as ns0, ns1, ns2 etc. 
    910etree._namespace_map.update({ 
    1011        'http://www.opengis.net/om': 'om',  'http://www.opengis.net/gml': 'gml','http://ndg.nerc.ac.uk/csml' : 'csml', 'http://www.w3.org/1999/xlink':'xlink'}) 
    1112 
    12       
     13 
    1314def _strToDate(ymd): 
    1415    '''given a string in form '2006-01-01' returns a datetime object''' 
    1516    return datetime.date(*map(int, ymd.split('-'))) 
    1617 
    17 def _getEnvelopefromFile(f): 
    18     '''parses a file and gets the bounding box from the feature collection''' 
     18def _getEnvelopefromDataset(ds): 
     19    '''gets the bounding box from the feature collection''' 
     20    envelope= ds.featureCollection.boundedBy 
     21    return envelope 
     22 
     23def _parsefile(f): 
    1924    tree = cElementTree.ElementTree(file=f) 
    2025    dataset = csml.parser.Dataset() 
    2126    dataset.fromXML(tree.getroot()) 
    22     envelope= dataset.featureCollection.boundedBy 
    23     return envelope 
     27    return dataset 
     28     
    2429 
    2530class EnvelopeAggregator(object): 
     
    7883        self.envelope.timePosition2=str(self.t2) 
    7984        return self.envelope 
    80     
    8185 
    82  
     86    #new process: 
    8387def main(args=None): 
    8488    '''Get command line arguments, should be paths to csml files 
     
    8993        sys.argv =args 
    9094    csmlfilelist= sys.argv[1:] 
    91     #use the first file to set up the aggregator: 
    92     env=_getEnvelopefromFile(csmlfilelist[0]) 
     95 
     96    #set up coverage envelope aggragator with envelope from first file: 
     97    dataset=_parsefile(csmlfilelist[0]) 
     98    env=_getEnvelopefromDataset(dataset) 
    9399    aggregator=EnvelopeAggregator(env) 
    94     #then aggregate across the rest of the files in the list 
    95     csmlfilelist=csmlfilelist[1:] 
     100  
     101    #for each file: 
    96102    for f in csmlfilelist: 
    97         aggregator.compareEnvelope(_getEnvelopefromFile(f)) 
     103        #parse file: 
     104        dataset=_parsefile(f) 
     105        #compare envelope: 
     106        aggregator.compareEnvelope(_getEnvelopefromDataset(dataset)) 
     107        #get other things: 
     108         
     109    #get aggregated envelope: 
    98110    finalEnvelope=aggregator.getAggregatedEnvelope() 
    99     #test output - need to decide what we want to do with the aggregated envelope:  
    100     #options include; Create an empty moles record, write to a text file, add to an existing moles record..? 
     111    #get other aggregations: 
     112     
     113    #write MOLES skeleton document: 
    101114    print finalEnvelope.lowerCorner.vals 
    102115    print finalEnvelope.upperCorner.vals 
Note: See TracChangeset for help on using the changeset viewer.