Skip to content

More stable datatypes, writing nullvals, and type testing #71

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

Merged
merged 4 commits into from
Sep 24, 2016
Merged

More stable datatypes, writing nullvals, and type testing #71

merged 4 commits into from
Sep 24, 2016

Conversation

karimbahgat
Copy link
Collaborator

Added float datatype.
More fully implemented date type by returning and writing datetime.date objects, as well as a list for backwards compat, somewhat similar to #18.
Fixed old boolean reading bug.
Added writing of null values for all types.
Date and boolean fields have predecided size, so user shouldn't be able to change those internals, so autosets size and decimal.

No new doctest failures, only the ones that will be fixed with #68.

Also created some basic tests for all the datatypes (which also works and loads correctly in QGIS, though QGIS seems to treat boolean as string) but wanted to avoid cluttering the lib with additional files. So thought it would be better if someone could use the test code and implement it correctly according to existing pyshp test conventions. Here is the test code:

import shapefile
from datetime import date

# write

d = shapefile.Writer()
d.field("string", "C")
d.field("date", "D")
d.field("datelist", "D")
d.field("datemiss", "D")
d.field("num", "N")
d.field("nummiss", "N")
d.field("float", "F")
d.field("floatmiss", "F")
d.field("booltrue", "L")
d.field("boolfalse", "L")
d.field("boolunkn", "L")
d.field("boolmiss", "L")

writerow = ["hello",
             date(1998,1,30), [1998,1,30], None,
             45, None,
             89, None,
             True, False, "wrongbool", None
            ]

print writerow

d.record(*writerow)
d.null() 

d.save("testtypes.shp")

# read

d = shapefile.Reader("testtypes.shp")
readrow = d.record(0)

print readrow

Sync with geospatialpython master
Added read and write support for dbf float fieldtype. Date type now also returns and writes datetime.date objects, and can also write a list of yr,month,day for backward compat. 
Previously "N" numeric was the only supported number type, sometimes
resulting in strange string nrs and subsequent saving errors.

Also enabled writing QGIS nullvalues, previously only when reading.
@karimbahgat karimbahgat merged commit 86fbadb into GeospatialPython:master Sep 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant