Skip to content

Added read/write support for more datatypes, and writing nullvalues #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions shapefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def __repr__(self):

def signed_area(coords):
"""Return the signed area enclosed by a ring using the linear time
algorithm. A value >= 0 indicates a counter-clockwise oriented ring.
algorithm at http://www.cgafaq.info/wiki/Polygon_Area. A value >= 0
indicates a counter-clockwise oriented ring.
"""
xs, ys = map(list, zip(*coords))
xs.append(xs[1])
Expand Down Expand Up @@ -523,6 +524,20 @@ def __record(self):
elif typ == b('L'):
value = (value in b('YyTt') and b('T')) or \
(value in b('NnFf') and b('F')) or b('?')
elif typ in ("F","O"):
value = value.replace(b('\0'), b('')).strip()
value = value.replace(b('*'), b('')) # QGIS NULL is all '*' chars
if value == b(''):
value = None
else:
value = float(value)
elif typ == "I":
value = value.replace(b('\0'), b('')).strip()
value = value.replace(b('*'), b('')) # QGIS NULL is all '*' chars
if value == b(''):
value = None
else:
value = int(value)
else:
value = u(value)
value = value.strip()
Expand Down Expand Up @@ -915,8 +930,12 @@ def __dbfRecords(self):
for (fieldName, fieldType, size, dec), value in zip(self.fields, record):
fieldType = fieldType.upper()
size = int(size)
if fieldType.upper() == "N":
value = str(value).rjust(size)
if fieldType.upper() in ("N","F","O","I"):
if value is None or value is "":
value = str("*"*size) # QGIS NULL
else:
value = str(value).rjust(size)
# TODO: Do date field values need special packing or just normal str()?
elif fieldType == 'L':
value = str(value)[0].upper()
else:
Expand Down