zhikrullah / pyshp

Automatically exported from code.google.com/p/pyshp
MIT License
0 stars 0 forks source link

DBF write fails to truncate #21

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Python's rjust and ljust don't seem to truncate, so, around line 735 (and 739) 
in shapefile.py, instead of:
    value = str(value).rjust(size)
I believe you need:
    value = str(value).rjust(size)[:size]

What steps will reproduce the problem?
1. attempt to write floats with higher precision than that alloted in the dbf 
field. 
2.
3.

What is the expected output? A DBF. What do you see instead? An assertion error.

What version of the product are you using? On what operating system?
1.1.4 on Windows XP.

Please provide any additional information below.

Thanks!

Original issue reported on code.google.com by lordv...@gmail.com on 16 Nov 2011 at 11:08

GoogleCodeExporter commented 8 years ago

Original comment by geospati...@gmail.com on 17 Nov 2011 at 3:19

GoogleCodeExporter commented 8 years ago
V1.2.0 fails to format according to size and decimal precision indicated by 
field attributes:

At line 886 in shapefile.py:
  value = str(value).rjust(size)

I've changed line 886 to (Python2.7+): 
  value = "{0:{1}.{2}f}".format(value, size, dec)

Original comment by wcart...@gmail.com on 25 Oct 2013 at 3:12