wqjzzgci / pyshp

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

Invalid number when reading shape records #30

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Load the attached file
2. Ask for shapeRecords()

Get this:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "shapefile.py", line 430, in shapeRecords
    for rec in zip(self.shapes(), self.records())]
  File "shapefile.py", line 413, in records
    r = self.__record()
  File "shapefile.py", line 378, in __record
    value = int(value)
ValueError: invalid literal for int() with base 10: 
'********************************'

Original issue reported on code.google.com by 127.0.0.69 on 21 Mar 2012 at 4:03

Attachments:

GoogleCodeExporter commented 8 years ago

Original comment by jlawh...@geospatialpython.com on 13 Apr 2012 at 3:54

GoogleCodeExporter commented 8 years ago
Hi, I am also seeing that bug, 
attached as zip is my shape file. 

Original comment by nahu...@gmail.com on 29 Jul 2012 at 11:23

Attachments:

GoogleCodeExporter commented 8 years ago
One more comment, my shapefile was created Python GDAL. 
The dbf is normally read with programs like QGIS. 

Original comment by nahu...@gmail.com on 29 Jul 2012 at 11:26

GoogleCodeExporter commented 8 years ago
The error response I got was a bit more helpful:
    ValueError: invalid literal for int() with base 10: '1.487983'
The int() function is being sent the string '1.487983', and it throws an 
exception (at least it does in Python 2.7).
I patched the problem by changing line 378 from:
value = int(value)
to:
value = int(float(value))

Original comment by da...@davel.org on 31 Mar 2013 at 8:51

GoogleCodeExporter commented 8 years ago
Can confirm, receiving same error but for a different reason. NULL records show 
up as asterisks "****" as wide as the field. I patched it as
try:
     value = int(float(value))
except:
     value = None

Original comment by rexdougl...@gmail.com on 31 Oct 2013 at 11:47

GoogleCodeExporter commented 8 years ago
I encountered this issue too, with NULL values in the DBF being shown as 
asterisks '*********'.

Shapefile was created in QGIS.

I used rexdouglas's fix, so I can recommend it.

Original comment by timothy....@gmail.com on 23 Dec 2013 at 2:16