[bug #2453] (thuban) gns2shp.py crashes on GNS input files containing names > 40 car.

Request Tracker thuban-bugs at intevation.de
Wed Jun 2 14:35:23 CEST 2004


this bug's URL: http://intevation.de/rt/webrt?serial_num=2453
-------------------------------------------------------------------------

Subject: gns2shp.py crashes on GNS input files containing names > 40 car.

Operating System: MS Windows, XP Pro
Thuban version: CVS, tarball available on the Web
Python version: 2.2.2

gns2shp extension crashes on GNS files containing names (FULL_NAME and FULL_NAME_ND fields) longer than 40 characters.
Just call the script on eg.txt (Egypt file) for example. You will get the following error stack:
C:\dev\src\gns\data\gns>python gns2shp.py eg.txt eg.shp
gns2shp.py $Revision: 1.3 $
Traceback (most recent call last):
  File "gns2shp.py", line 166, in ?
    no = gns2shp(sys.argv[1], sys.argv[2][:-4])
  File "gns2shp.py", line 104, in gns2shp
    dbf.write_record(i, { 'RC': RC, 'UFI': UFI, 'UNI': UNI, 'UTM': UTM,
  File "c:\dev\Thuban\Lib\dbflib.py", line 33, in write_record
    val = apply(dbflibc.DBFFile_write_record,args)
IOError: can't write field 18 of record 10

The solution I found is to add two tests on the length of FULL_NAME and FULL_NAME_ND fields. Just truncate them to max 40car. and it will works. Patch follows:
86a87
>     trunc = 0
103a105,108
>         if len(FULL_NAME) > 40:
>             FULL_NAME = FULL_NAME[:39]
>             trunc += 1
>         if len(FULL_NAME_ND) > 40: FULL_NAME_ND = FULL_NAME_ND[:39]
117c122
<     return i
---
>     return (i,trunc)
166c171
<         no = gns2shp(sys.argv[1], sys.argv[2][:-4])
---
>         (no,trunc) = gns2shp(sys.argv[1], sys.argv[2][:-4])
167a173
>         if trunc!=0: print '%d names truncated' % trunc

Have a nice day!
Pierre

-------------------------------------------- Managed by Request Tracker




More information about the Thuban-devel mailing list

This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)