Skip to content

Commit

Permalink
define Coord in new file, rename PJ_COORD to it
Browse files Browse the repository at this point in the history
and leave out the unusable structs PJ_XY from proj_common.jl
  • Loading branch information
visr committed Jan 14, 2021
1 parent a1ae2db commit affd59e
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 36 deletions.
24 changes: 8 additions & 16 deletions gen/wrap_proj.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ If Doxygen gives errors, it helps to turn off Latex and HTML output:

using Clang
using MacroTools
using MacroTools: postwalk
using EzXML
using PROJ_jll

Expand Down Expand Up @@ -136,17 +137,14 @@ function rewriter(x::Expr)
x2 = :(function $f($(fargs2...))
$cc2
end) |> prettify
return x2, argpos

# rename PJ_COORD to Coord
x3 = postwalk(x -> x === :PJ_COORD ? :Coord : x, x2)
return x3, argpos
else
# do not modify expressions that are no ccall function wrappers
# argument positions do not apply, but something still needs to be returned

if x.head == :struct && x.args[2] == :PJ_COORD
# PJ_COORD becomes a subtype of StaticArrays' FieldVector
return prettify(pj_coord), nothing
else
return x, nothing
end
return x, nothing
end
end

Expand All @@ -156,15 +154,9 @@ const doc = readxml(xmlpath)
includedir = joinpath(PROJ_jll.artifact_dir, "include")
headerfiles = [joinpath(includedir, "proj.h")]

const pj_coord = :(struct PJ_COORD <: FieldVector{4, Float64}
x::Float64
y::Float64
z::Float64
t::Float64
end)

# PJ_COORD becomes `Coord <: FieldVector{4, Float64}` and the rest is left out altogether
# https://proj.org/development/reference/datatypes.html#c.PJ_COORD
const coord_union = [:PJ_XYZT, :PJ_UVWT, :PJ_LPZT, :PJ_GEOD, :PJ_OPK,
const coord_union = [:PJ_COORD, :PJ_XYZT, :PJ_UVWT, :PJ_LPZT, :PJ_GEOD, :PJ_OPK,
:PJ_ENU, :PJ_XYZ, :PJ_UVW, :PJ_LPZ, :PJ_XY, :PJ_UV, :PJ_LP]

wc = init(; headers = headerfiles,
Expand Down
4 changes: 4 additions & 0 deletions src/Proj4.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ export Projection, # proj_types.jl
# geodesic support
export geod_direct, geod_inverse, geod_destination, geod_distance

# these are part of the deprecated PROJ API, and will be removed soon
include("projection_codes.jl") # ESRI and EPSG projection strings
include("proj_capi.jl") # low-level C-facing functions (corresponding to src/proj_api.h)
include("proj_geodesic.jl") # low-level C-facing functions (corresponding to src/geodesic.h)

# these are part of the new PROJ API
include("coord.jl")
include("proj_common.jl")
include("proj_c.jl")
include("error.jl")
Expand Down
17 changes: 17 additions & 0 deletions src/coord.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
Coord <: FieldVector{4, Float64}
General purpose coordinate type, applicable in two, three and four dimensions. This is the
default coordinate datatype used in PROJ.
Elements can be retrieved either by index 1-4, or by field x, y, z, t. If a Coord does not
represent a cartesian coordinate, using the index may be more clear, as the other coordinate
types listed in the [PJ_COORD docs](https://proj.org/development/reference/datatypes.html#c.PJ_COORD)
are not addressable by name.
"""
struct Coord <: FieldVector{4, Float64}
x::Float64
y::Float64
z::Float64
t::Float64
end
22 changes: 11 additions & 11 deletions src/proj_c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -367,43 +367,43 @@ function proj_degree_output(P, dir)
end

function proj_trans(P, direction, coord)
ccall((:proj_trans, libproj), PJ_COORD, (Ptr{PJ}, PJ_DIRECTION, PJ_COORD), P, direction, coord)
ccall((:proj_trans, libproj), Coord, (Ptr{PJ}, PJ_DIRECTION, Coord), P, direction, coord)
end

function proj_trans_array(P, direction, n, coord)
ccall((:proj_trans_array, libproj), Cint, (Ptr{PJ}, PJ_DIRECTION, Csize_t, Ptr{PJ_COORD}), P, direction, n, coord)
ccall((:proj_trans_array, libproj), Cint, (Ptr{PJ}, PJ_DIRECTION, Csize_t, Ptr{Coord}), P, direction, n, coord)
end

function proj_trans_generic(P, direction, x, sx, nx, y, sy, ny, z, sz, nz, t, st, nt)
ccall((:proj_trans_generic, libproj), Csize_t, (Ptr{PJ}, PJ_DIRECTION, Ptr{Cdouble}, Csize_t, Csize_t, Ptr{Cdouble}, Csize_t, Csize_t, Ptr{Cdouble}, Csize_t, Csize_t, Ptr{Cdouble}, Csize_t, Csize_t), P, direction, x, sx, nx, y, sy, ny, z, sz, nz, t, st, nt)
end

function proj_coord(x = 0.0, y = 0.0, z = 0.0, t = 0.0)
ccall((:proj_coord, libproj), PJ_COORD, (Cdouble, Cdouble, Cdouble, Cdouble), x, y, z, t)
ccall((:proj_coord, libproj), Coord, (Cdouble, Cdouble, Cdouble, Cdouble), x, y, z, t)
end

function proj_roundtrip(P, direction, n, coord)
ccall((:proj_roundtrip, libproj), Cdouble, (Ptr{PJ}, PJ_DIRECTION, Cint, Ptr{PJ_COORD}), P, direction, n, coord)
ccall((:proj_roundtrip, libproj), Cdouble, (Ptr{PJ}, PJ_DIRECTION, Cint, Ptr{Coord}), P, direction, n, coord)
end

function proj_lp_dist(P, a, b)
ccall((:proj_lp_dist, libproj), Cdouble, (Ptr{PJ}, PJ_COORD, PJ_COORD), P, a, b)
ccall((:proj_lp_dist, libproj), Cdouble, (Ptr{PJ}, Coord, Coord), P, a, b)
end

function proj_lpz_dist(P, a, b)
ccall((:proj_lpz_dist, libproj), Cdouble, (Ptr{PJ}, PJ_COORD, PJ_COORD), P, a, b)
ccall((:proj_lpz_dist, libproj), Cdouble, (Ptr{PJ}, Coord, Coord), P, a, b)
end

function proj_xy_dist(a, b)
ccall((:proj_xy_dist, libproj), Cdouble, (PJ_COORD, PJ_COORD), a, b)
ccall((:proj_xy_dist, libproj), Cdouble, (Coord, Coord), a, b)
end

function proj_xyz_dist(a, b)
ccall((:proj_xyz_dist, libproj), Cdouble, (PJ_COORD, PJ_COORD), a, b)
ccall((:proj_xyz_dist, libproj), Cdouble, (Coord, Coord), a, b)
end

function proj_geod(P, a, b)
ccall((:proj_geod, libproj), PJ_COORD, (Ptr{PJ}, PJ_COORD, PJ_COORD), P, a, b)
ccall((:proj_geod, libproj), Coord, (Ptr{PJ}, Coord, Coord), P, a, b)
end

function proj_context_errno(ctx = C_NULL)
Expand Down Expand Up @@ -439,7 +439,7 @@ function proj_log_func(app_data, logf, ctx = C_NULL)
end

function proj_factors(P, lp)
ccall((:proj_factors, libproj), PJ_FACTORS, (Ptr{PJ}, PJ_COORD), P, lp)
ccall((:proj_factors, libproj), PJ_FACTORS, (Ptr{PJ}, Coord), P, lp)
end

function proj_info()
Expand Down Expand Up @@ -1489,7 +1489,7 @@ end
the index in operations that would be used to transform coord. Or -1 in case of error, or no match.
"""
function proj_get_suggested_operation(operations, direction, coord, ctx = C_NULL)
ccall((:proj_get_suggested_operation, libproj), Cint, (Ptr{PJ_CONTEXT}, Ptr{PJ_OBJ_LIST}, PJ_DIRECTION, PJ_COORD), ctx, operations, direction, coord)
ccall((:proj_get_suggested_operation, libproj), Cint, (Ptr{PJ_CONTEXT}, Ptr{PJ_OBJ_LIST}, PJ_DIRECTION, Coord), ctx, operations, direction, coord)
end

"""
Expand Down
8 changes: 0 additions & 8 deletions src/proj_common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ const PROJ_VERSION_MAJOR = 7
const PROJ_VERSION_MINOR = 2
const PROJ_VERSION_PATCH = 0
const PJ_DEFAULT_CTX = 0

struct PJ_COORD <: FieldVector{4, Float64}
x::Float64
y::Float64
z::Float64
t::Float64
end

const PJ_AREA = Cvoid

struct P5_FACTORS
Expand Down
2 changes: 1 addition & 1 deletion test/proj6api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ end
a = Proj4.proj_coord(12, 55)
@test a isa AbstractVector
@test a isa FieldVector{4, Float64}
@test a isa Proj4.PJ_COORD
@test a isa Proj4.Coord
@test eltype(a) == Float64
@test length(a) == 4
@test sum(a) == 12 + 55
Expand Down

0 comments on commit affd59e

Please sign in to comment.