Skip to content

Fix "missing declaration for symbol ''pj_get_errno''" #12

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 1 commit into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
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
28 changes: 17 additions & 11 deletions gis/projection.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,27 @@ if proj_path == nil then
error("Failed to find internal library")
end
local lib = ffi.load(proj_path)
-- local ctx = lib.pj_ctx_alloc()
-- if ctx == nil then
-- error('Failed to create proj4 context')
-- end
-- ffi.gc(ctx, lib.pj_ctx_free)
local ctx = lib.pj_ctx_alloc()
if ctx == nil then
error('Failed to create proj4 context')
end
ffi.gc(ctx, lib.pj_ctx_free)

local projections = {}

local PROJ_VERSION = ffi.string(lib.libproj_version())
projections.PROJ_VERSION = PROJ_VERSION

local function ctx_raise_errno(errno)
assert(errno ~= 0)
local errstr = lib.pj_strerrno(errno)
local errstr = errstr ~= nil and ffi.string(errstr) or "Unknown error"
error('PROJ: '..errstr)
end

local function ctx_raise()
-- local errno = lib.pj_ctx_get_errno(ctx)
local errno = lib.pj_get_errno(ctx)
error('PROJ: '..ffi.string(lib.pj_strerrno(errno)))
local errno = lib.pj_ctx_get_errno(ctx)
return ctx_raise_errno(errno)
end

local proj_t = ffi.typeof('struct PJ')
Expand Down Expand Up @@ -105,9 +111,9 @@ local function proj_transformv(src, dst, count, xvec, yvec, zvec)
"xvec: double[], yvec: double[], zvec: double[])")
end
proj_arg(src)
local rc = lib.pj_transform(src, dst, count, 1, xvec, yvec, zvec)
if rc ~= 0 then
ctx_raise()
local errno = lib.pj_transform(src, dst, count, 1, xvec, yvec, zvec)
if errno ~= 0 then
ctx_raise_errno(errno)
end
return true
end
Expand Down
15 changes: 14 additions & 1 deletion tests/projection.test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ local gis = require('gis')
gis.install()
local projection = require('gis.projection')
local test = require('tap').test('gis.projection')
test:plan(23)
test:plan(25)

local status, reason
local latlong = projection[4326]
Expand Down Expand Up @@ -81,4 +81,17 @@ test:ok(dist(x - x1, y - y1, z - z1) < 1e-3, "transform(utm, geocent)")
local a1, b1 = geocent:transform(utm44n, x, y, z)
test:ok(dist(a - a1, b - b1) < 1e-3, "transform(geocent, utm)")

--
-- Bugs
--

-- missing declaration for symbol ''pj_get_errno''
-- https://github.com/tarantool/gis/issues/11
local second = gis.Point({43.035657, 131.891867}, 4326)
local first = gis.Point({43.165000, 131.906750}, 4326)
local linec = gis.LineString({first, second}, 4326)
local err, reason = pcall(linec.transform, linec, 32644)
test:is(err, false, "transform error 1")
test:like(reason, "exceeded limits", "transform error 2")

os.exit(test:check() == true and 0 or -1)