- Timestamp:
- 11/09/06 15:25:05 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TI02-CSML/trunk/Examples/parsing/csml2moles.py
r1505 r1506 5 5 import cElementTree 6 6 import elementtree.ElementTree as etree 7 import datetime 7 8 #this is a fix to the ElementTree namespace problem that namespaces are usually represented as ns0, ns1, ns2 etc. 8 9 etree._namespace_map.update({ 9 10 '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'}) 10 11 11 12 13 def _strToDate(ymd): 14 '''given a string in form '2006-01-01' returns a datetime object''' 15 return datetime.date(*map(int, ymd.split('-'))) 16 12 17 def _getEnvelopefromFile(f): 13 #parses a file and gets the bounding box from the feature collection18 '''parses a file and gets the bounding box from the feature collection''' 14 19 tree = cElementTree.ElementTree(file=f) 15 20 dataset = csml.parser.Dataset() … … 20 25 class EnvelopeAggregator(object): 21 26 def __init__(self,envelope): 22 #start with aggregated envelope equal to the initialising envelope23 #envelope must be of type csml.parser.EnvelopeWithTimePeriod27 '''start with aggregated envelope equal to the initialising envelope 28 envelope must be of type csml.parser.EnvelopeWithTimePeriod''' 24 29 self.envelope=envelope 25 30 self.minX=self.envelope.lowerCorner.vals.split()[0] … … 27 32 self.maxX=self.envelope.upperCorner.vals.split()[0] 28 33 self.maxY=self.envelope.upperCorner.vals.split()[1] 34 self.t1= _strToDate(self.envelope.timePosition) 35 self.t2= _strToDate(self.envelope.timePosition) 29 36 30 37 def _compareLowerCorners(self,lowerCorner): … … 36 43 self.envelope.lowerCorner.vals=str(self.minX +' '+ minY) 37 44 self.minY=minY 45 38 46 def _compareUpperCorners(self,upperCorner): 39 47 maxX,maxY=upperCorner.vals.split()[0],upperCorner.vals.split()[1] … … 44 52 self.envelope.upperCorner.vals=str(self.maxX +' '+ maxY) 45 53 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 51 64 52 65 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.''' 54 67 if envtocheck.srsName!=self.envelope.srsName: 55 68 print 'can currently only perform aggregation within the same spatio-temporal reference system.' … … 62 75 63 76 def getAggregatedEnvelope(self): 77 self.envelope.timePosition=str(self.t1) #convert from datetime types 78 self.envelope.timePosition2=str(self.t2) 64 79 return self.envelope 65 80 … … 67 82 68 83 def main(args=None): 69 #Get command line arguments, should be csml files: 'file1' 'file2'84 '''Get command line arguments, should be csml files ''' 70 85 if args: 71 86 sys.argv =args
Note: See TracChangeset
for help on using the changeset viewer.