Skip to content

Commit ba61854

Browse files
authored
Fixed old boolean bug, and autoset size when adding date and boolean fields
1 parent 09afe27 commit ba61854

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

shapefile.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -498,10 +498,6 @@ def __record(self):
498498
for (name, typ, size, deci), value in zip(self.fields, recordContents):
499499
if name == 'DeletionFlag':
500500
continue
501-
elif not value.strip():
502-
# why this? better to delete this and leave it up to the field type?
503-
record.append(value)
504-
continue
505501
elif typ in ("N","F"):
506502
# numeric or float: number stored as a string, right justified, and padded with blanks to the width of the field.
507503
value = value.replace(b('\0'), b('')).strip()
@@ -535,8 +531,12 @@ def __record(self):
535531
if value == " ":
536532
value = None # space means missing or not yet set
537533
else:
538-
value = (value in b('YyTt') and b('T')) or \
539-
(value in b('NnFf') and b('F')) or b('?')
534+
if value in b('YyTt1'):
535+
value = True
536+
elif value in b('NnFf0'):
537+
value = False
538+
else:
539+
value = b('?')
540540
else:
541541
# anything else is forced to string/unicode
542542
value = u(value)
@@ -1009,6 +1009,12 @@ def poly(self, parts=[], shapeType=POLYGON, partTypes=[]):
10091009

10101010
def field(self, name, fieldType="C", size="50", decimal=0):
10111011
"""Adds a dbf field descriptor to the shapefile."""
1012+
if fieldType == "D":
1013+
size = "8"
1014+
decimal = 0
1015+
elif fieldType == "L":
1016+
size = "1"
1017+
decimal = 0
10121018
self.fields.append((name, fieldType, size, decimal))
10131019

10141020
def record(self, *recordList, **recordDict):

0 commit comments

Comments
 (0)