Changeset 945

Show
Ignore:
Timestamp:
10/13/08 15:04:23 (3 months ago)
Author:
hobu
Message:

Support fractional seconds in the python bindings #83

Location:
trunk/python
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/python/liblas/point.py

    r943 r945  
    4444import datetime 
    4545import time 
     46import math 
    4647 
    4748class Point(object): 
     
    178179    def get_time(self): 
    179180        t = core.las.LASPoint_GetTime(self.handle) 
    180         return datetime.datetime(*time.localtime(t)[0:7]) 
     181        floor = math.floor(t) 
     182        ms = float(t) - floor 
     183        ms = int(round(ms* 1000000 )) 
     184        lt = time.localtime(t) 
     185        return datetime.datetime(lt[0],lt[1],lt[2],lt[3],lt[4],lt[5],ms) 
     186         
    181187    def set_time(self, value): 
    182188        """ 
     
    195201        """ 
    196202        t = time.mktime(value.timetuple()) 
     203         
     204        ms = value.microsecond 
     205        t = float(t) + ms * 0.000001 
    197206        core.las.LASPoint_SetTime(self.handle,t) 
    198207    time = property(get_time, set_time) 
  • trunk/python/tests/Point.txt

    r552 r945  
    6161   
    6262  >>> import datetime 
    63   >>> t = datetime.datetime(2008,3,19) 
     63  >>> t = datetime.datetime(2008,3,19,23,45,45,134) 
    6464  >>> p.time = t 
    6565  >>> p.time 
    66   datetime.datetime(2008, 3, 19, 0, 0, 0, 2) 
     66  datetime.datetime(2008, 3, 19, 23, 45, 45, 134) 
     67  >>> p.time.microsecond 
     68  134 
     69   
     70  >>> p.intensity 
     71  0 
     72  >>> p.intensity = 120 
     73  >>> p.intensity 
     74  120 
    6775