Code Monkey home page Code Monkey logo

dbftables.jl's Introduction

DBFTables

CI codecov deps version pkgeval

Read xBase / dBASE III+ .dbf files in Julia. Supports the Tables.jl interface.

Shapefile.jl uses this package to read the information associated to the geometries of the .shp file.

Usage

using DBFTables
dbf = DBFTables.Table("test.dbf")

# whole columns can be retrieved by their name
# note that this creates a copy, so instead of repeated `dbf.field` calls,
# it is faster to once do `field = dbf.field` and then use `field` instead
dbf.INTEGER  # => Union{Missing, Int64}[100, 101, 102, 0, 2222222222, 4444444444, missing]

# example function that iterates over the rows and uses two columns
function sumif(dbf)
    total = 0.0
    for row in dbf
        if row.BOOLEAN && !ismissing(row.NUMERIC)
            value += row.NUMERIC
        end
    end
    return total
end

# for other functionality, convert to other Tables such as DataFrame
using DataFrames
df = DataFrame(dbf)

Format description resources

Implementation details

The DBF header contains information on the amount of rows, which columns are present, what type they are, and how many bytes the entries are. Based on this we can create a Tables.Schema. Each row is a fixed amount of bytes. All data is represented as strings, with different conventions based on the specified type. There are no delimiters between the entries, but since we know the sizes from the header, it is not needed.

The DBFTables.Table struct holds both the header and data. All data is read into memory in one go as a Vector{UInt8}. To provide efficient access into the individual entries, we use WeakRefStrings. WeakRefStrings' StringArray only holds the offsets and lengths into the Vector{UInt8} with all the data. Then we still need to convert from the string to the julia type. This is done on demand with dbf_value.

Note that the format also contains a "record deleted" flag, which is represented by a '*' at the start of the row. When this is encountered the record should be treated as if it doesn't exist. Since normally writers strip these records when writing, they are rarely encountered. For that reason this package ignores these flags by default right now. To check for the flags yourself, there is the isdeleted function. A sample file with deleted record flags is available here.

dbftables.jl's People

Contributors

visr avatar quinnj avatar joshday avatar nalimilan avatar cchderrick avatar ararslan avatar dm13450 avatar juliatagbot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.