/[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 1389 by jonathan, Thu Jul 10 14:53:27 2003 UTC revision 1431 by jonathan, Wed Jul 16 13:23:41 2003 UTC
# Line 465  def _find_dbf_column_names(names): Line 465  def _find_dbf_column_names(names):
465    
466      return name_map      return name_map
467    
468  def table_to_dbf(table, filename, records = None):  def table_to_dbf(table, filename, rows = None):
469      """Create the dbf file filename from the table"""      """Create the dbf file filename from the table.
470        
471        If rows is not None (the default) then it must be a list of row
472        indices to be saved to the file, otherwise all rows are saved.
473        """
474    
475      dbf = dbflib.create(filename)      dbf = dbflib.create(filename)
476    
477      dbflib_fieldtypes = {FIELDTYPE_STRING: dbflib.FTString,      dbflib_fieldtypes = {FIELDTYPE_STRING: dbflib.FTString,
# Line 486  def table_to_dbf(table, filename, record Line 491  def table_to_dbf(table, filename, record
491          dbf.add_field(name_map[col.name], dbflib_fieldtypes[col.type],          dbf.add_field(name_map[col.name], dbflib_fieldtypes[col.type],
492                        width, prec)                        width, prec)
493    
494      if records is None:      if rows is None:
495          records = range(table.NumRows())          rows = range(table.NumRows())
496    
497      recNum = 0      recNum = 0
498      for i in records:      for i in rows:
499          record = {}          record = {}
500          for key, value in table.ReadRowAsDict(i).items():          for key, value in table.ReadRowAsDict(i).items():
501              record[name_map[key]] = value              record[name_map[key]] = value
# Line 498  def table_to_dbf(table, filename, record Line 503  def table_to_dbf(table, filename, record
503          recNum += 1          recNum += 1
504      dbf.close()      dbf.close()
505    
506  def table_to_csv(table, filename, records = None):  def table_to_csv(table, filename, rows = None):
507      """Export table to csv file."""      """Export table to csv file.
508        
509        If rows is not None (the default) then it must be a list of row
510        indices to be saved to the file, otherwise all rows are saved.
511        """
512    
513      file = open(filename,"w")      file = open(filename,"w")
514      columns = table.Columns()      columns = table.Columns()
# Line 510  def table_to_csv(table, filename, record Line 519  def table_to_csv(table, filename, record
519          header = header + "\n"          header = header + "\n"
520          file.write(header)          file.write(header)
521    
522          if records is None:          if rows is None:
523              records = range(table.NumRows())              rows = range(table.NumRows())
524    
525          for i in records:          for i in rows:
526              record = table.ReadRowAsDict(i)              record = table.ReadRowAsDict(i)
527              if len(record):              if len(record):
528                  line = "%s" % record[columns[0].name]                  line = "%s" % record[columns[0].name]

Legend:
Removed from v.1389  
changed lines
  Added in v.1431

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26