login

<     >

2021-08-22 19:41:58 (UTC-03:00)

Marcel Rodrigues <marcelgmr@gmail.com>

shp: remove unused code

diff --git a/shp.lua b/shp.lua
index f786a2d..d102a5b 100644
--- a/shp.lua
+++ b/shp.lua
@@ -214,40 +214,6 @@ function SF:read_record_header(index)
     return num, len, shape
 end
 
--- this is the old version, using coroutines
-function SF:read_polygons_co(index)
-    assert(startswith(self.header.shape, "polygon"), "type mismatch")
-    local fp = self.fp
-    local num, len, shape = self:read_record_header(index)
-    if shape == "null" then
-        return nil
-    end
-    local bbox = read_bbox(fp)
-    local nparts = read_lei32(fp)
-    --~ print(nparts)
-    local npoints = read_lei32(fp)
-    local total = read_lei32(fp) -- first index is always zero?
-    local lengths = {}
-    for i = 2, nparts do
-        local index = read_lei32(fp)
-        table.insert(lengths, index - total)
-        total = index
-    end
-    table.insert(lengths, npoints - total)
-    return coroutine.wrap(function()
-        for i = 1, #lengths do
-            local length = lengths[i]
-            coroutine.yield(coroutine.wrap(function()
-                for i = 1, length do
-                    local x = read_led64(fp)
-                    local y = read_led64(fp)
-                    coroutine.yield({x, y})
-                end
-            end))
-        end
-    end)
-end
-
 function SF:read_polygons(index)
     assert(startswith(self.header.shape, "polygon"), "type mismatch")
     local fp = self.fp
@@ -297,78 +263,4 @@ local function open_shapefile(path)
     return self
 end
 
-local function read_dbf(fp)
-    local version = bit.band(read_byte(fp), 0x07)
-    if version ~= 3 then
-        error("only DBF version 5 is supported")
-    end
-    local year = 1900 + read_byte(fp)
-    local month = read_byte(fp)
-    local day = read_byte(fp)
-    -- print(("%04d-%02d-%02d"):format(year, month, day))
-    local nrecs = read_leu32(fp)
-    fp:seek("cur", 24)
-    local reclen = 0
-    local fields = {}
-    local byte = read_byte(fp)
-    while byte ~= 0x0D do
-        local field_name = rtrim(string.char(byte) .. fp:read(10), "\000")
-        local field_type = fp:read(1)
-        fp:seek("cur", 4)
-        local field_length = read_byte(fp)
-        reclen = reclen + field_length
-        local field_dec_count = read_byte(fp)
-        local field = {
-          name=field_name,
-          type=field_type,
-          length=field_length,
-          dec_count=field_dec_count
-        }
-        table.insert(fields, field)
-        fp:seek("cur", 14)
-        byte = read_byte(fp)
-    end
-    local tab = {}
-    for i = 1, nrecs do
-        if fp:read(1) == "*" then
-            fp:seek("cur", reclen)
-        else
-            local row = {}
-            for j = 1, #fields do
-                local field = fields[j]
-                local cell = rtrim(fp:read(field.length), " ")
-                if field.type == "F" or field.type == "N" then
-                    cell = tonumber(cell)
-                end
-                table.insert(row, cell)
-            end
-            table.insert(tab, row)
-        end
-    end
-    return fields, tab
-end
-
-local function tab2csv(fields, tab, sep, fp)
-    -- TODO: refactor to use table.concat(str_list, sep)
-    sep = sep or ":"
-    fp = fp or io.output()
-    for i = 1, #fields do
-        if i > 1 then
-            fp:write(sep)
-        end
-        fp:write(fields[i].name)
-    end
-    fp:write("\n")
-    for i = 1, #tab do
-        for j = 1, #fields do
-            if j > 1 then
-                fp:write(sep)
-            end
-            local cell = tab[i][j]
-            fp:write(cell)
-        end
-        fp:write("\n")
-    end
-end
-
-return {open_shapefile=open_shapefile, read_dbf=read_dbf, tab2csv=tab2csv}
+return {open_shapefile=open_shapefile}