Changeset 1506


Ignore:
Timestamp:
11/09/06 15:25:05 (13 years ago)
Author:
domlowe
Message:

Aggregation working in both time and space

File:
1 edited

Legend:

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

    r1505 r1506  
    55import cElementTree 
    66import elementtree.ElementTree as etree 
     7import datetime 
    78#this is a fix to the  ElementTree namespace problem that namespaces are usually represented as ns0, ns1, ns2 etc. 
    89etree._namespace_map.update({ 
    910        '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'}) 
    1011 
    11              
     12      
     13def _strToDate(ymd): 
     14    '''given a string in form '2006-01-01' returns a datetime object''' 
     15    return datetime.date(*map(int, ymd.split('-'))) 
     16 
    1217def _getEnvelopefromFile(f): 
    13     #parses a file and gets the bounding box from the feature collection 
     18    '''parses a file and gets the bounding box from the feature collection''' 
    1419    tree = cElementTree.ElementTree(file=f) 
    1520    dataset = csml.parser.Dataset() 
     
    2025class EnvelopeAggregator(object): 
    2126    def __init__(self,envelope): 
    22         #start with aggregated envelope equal to the initialising envelope 
    23         #envelope must be of type csml.parser.EnvelopeWithTimePeriod 
     27        '''start with aggregated envelope equal to the initialising envelope 
     28        envelope must be of type csml.parser.EnvelopeWithTimePeriod''' 
    2429        self.envelope=envelope 
    2530        self.minX=self.envelope.lowerCorner.vals.split()[0] 
     
    2732        self.maxX=self.envelope.upperCorner.vals.split()[0] 
    2833        self.maxY=self.envelope.upperCorner.vals.split()[1] 
     34        self.t1= _strToDate(self.envelope.timePosition) 
     35        self.t2= _strToDate(self.envelope.timePosition) 
    2936  
    3037    def _compareLowerCorners(self,lowerCorner): 
     
    3643            self.envelope.lowerCorner.vals=str(self.minX +' '+ minY) 
    3744            self.minY=minY 
     45             
    3846    def _compareUpperCorners(self,upperCorner): 
    3947        maxX,maxY=upperCorner.vals.split()[0],upperCorner.vals.split()[1] 
     
    4452            self.envelope.upperCorner.vals=str(self.maxX +' '+ maxY) 
    4553            self.maxY=maxY 
    46         return upperCorner 
    47     def _compareLowerTimes(self,timeposlist): 
    48         return timeposlist 
    49     def _compareUpperTimes(self,timeposlist): 
    50         return timeposlist 
     54             
     55    def _compareLowerTimes(self,timepos): 
     56        t=_strToDate(timepos) 
     57        if t<self.t1: 
     58            self.t1=t 
     59         
     60    def _compareUpperTimes(self,timepos): 
     61        t=_strToDate(timepos) 
     62        if t>self.t2: 
     63            self.t2=t  
    5164     
    5265    def compareEnvelope(self,envtocheck): 
    53         #compares new envelope, and if necessary changes the aggregated envelope. 
     66        '''compares new envelope, and if necessary changes the aggregated envelope.''' 
    5467        if envtocheck.srsName!=self.envelope.srsName: 
    5568            print 'can currently only perform aggregation within the same spatio-temporal reference system.' 
     
    6275     
    6376    def getAggregatedEnvelope(self): 
     77        self.envelope.timePosition=str(self.t1)  #convert from datetime types 
     78        self.envelope.timePosition2=str(self.t2) 
    6479        return self.envelope 
    6580    
     
    6782 
    6883def main(args=None): 
    69     #Get command line arguments, should be csml files: 'file1' 'file2' 
     84    '''Get command line arguments, should be csml files ''' 
    7085    if args: 
    7186        sys.argv =args 
Note: See TracChangeset for help on using the changeset viewer.