/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/Model/table.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/Model/table.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1042 by frank, Mon May 26 11:46:17 2003 UTC revision 1043 by bh, Mon May 26 19:27:15 2003 UTC
# Line 230  class DBFTable(TitledObject, OldTableInt Line 230  class DBFTable(TitledObject, OldTableInt
230    
231      # DBF specific interface parts.      # DBF specific interface parts.
232    
     def Precision(self, col):  
         """Return column precision"""  
         return self.column_map[col].prec  
   
233      def Width(self, col):      def Width(self, col):
234          """Return column width"""          """Return column width"""
235          return self.column_map[col].width          return self.column_map[col].width
# Line 372  class MemoryTable(TitledObject, OldTable Line 368  class MemoryTable(TitledObject, OldTable
368      def Width(self, col):      def Width(self, col):
369          """Return the maximum width of values in the column          """Return the maximum width of values in the column
370    
371          The return value is the the maximum length of string representation          The return value is the the maximum length of string
372          of the values in the column (represented by index or name)."""          representation of the values in the column (represented by index
373            or name).
374            """
375          max = 0          max = 0
376            
377          type  = self.column_map[col].type          type  = self.column_map[col].type
378          index = self.column_map[col].index          index = self.column_map[col].index
379          values = [row[index] for row in self.data]          values = [row[index] for row in self.data]
# Line 383  class MemoryTable(TitledObject, OldTable Line 381  class MemoryTable(TitledObject, OldTable
381              return None              return None
382    
383          if type == FIELDTYPE_DOUBLE:          if type == FIELDTYPE_DOUBLE:
384              prec = self.Precision(col)              format = "%.12f"
             format = "%%.%df" % prec  
385          elif type == FIELDTYPE_INT:          elif type == FIELDTYPE_INT:
386              format = "%d"              format = "%d"
387          else:          else:
# Line 396  class MemoryTable(TitledObject, OldTable Line 393  class MemoryTable(TitledObject, OldTable
393    
394          return max          return max
395    
     def Precision(self, col):  
         """Return the precision of the column  
   
         The return value is the maximum number of numeric characters after the  
         decimal if column type is double. Else precision zero is returned.  
         The column can be represented by index or name.  
         """  
       
         type  = self.column_map[col].type  
         if type == FIELDTYPE_DOUBLE:  
             index = self.column_map[col].index  
             values = [row[index] for row in self.data]  
             if not values:  
                 return 0  
               
             max = 0  
             for value in values:  
                 l = len(str(value % 1))  
                 if l > max:  
                     max = l  
             if max > 2:  
                 return max - 2  
             else:  
                 return 0  
         else:  
             return 0  
             
396      def Dependencies(self):      def Dependencies(self):
397          """Return an empty sequence. The MemoryTable doesn't depend on anything          """Return an empty sequence. The MemoryTable doesn't depend on anything
398          """          """
# Line 446  def table_to_dbf(table, filename): Line 416  def table_to_dbf(table, filename):
416    
417      # Initialise the header. Distinguish between DBFTable and others.      # Initialise the header. Distinguish between DBFTable and others.
418      for col in table.Columns():      for col in table.Columns():
         prec  = table.Precision(col.name)  
419          width = table.Width(col.name)          width = table.Width(col.name)
420            if col.type == FIELDTYPE_DOUBLE:
421                prec = getattr(col, "prec", 12)
422            else:
423                prec = 0
424          dbf.add_field(col.name, dbflib_fieldtypes[col.type], width, prec)          dbf.add_field(col.name, dbflib_fieldtypes[col.type], width, prec)
425    
426      for i in range(table.NumRows()):      for i in range(table.NumRows()):

Legend:
Removed from v.1042  
changed lines
  Added in v.1043

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26