JuliaGeo / Proj.jl

Julia wrapper for the PROJ cartographic projections library
MIT License
48 stars 9 forks source link

Create Transformation with a single pipeline projection #69

Closed evetion closed 1 year ago

evetion commented 2 years ago

Now to setup a pipeline, we need to handle the C API:

julia> pipe = Proj.proj_create("+proj=pipeline +step +proj=unitconvert +xy_in=deg +z_in=m +xy_out=rad +z_out=m +step +inv +proj=longlat +a=6378136.3 +rf=298.257 +e=0.08181922146 +step +proj=cart +a=6378136.3 +rf=298.257 +step +inv +proj=cart +ellps=WGS84 +step +proj=unitconvert +xy_in=rad +z_in=m +xy_out=deg +z_out=m +step +proj=axisswap +order=2,1")
Ptr{Nothing} @0x00000001254061d0

julia> Proj.proj_trans(pipe, Proj.PJ_FWD, (0,0,0))
4-element Proj.Coord:
  0.0
  0.0
 -0.7000000001862645
 Inf
evetion commented 2 years ago

We can also create a new struct, such as Pipeline?

visr commented 2 years ago

I'd prefer to support this as part of the Proj.Transformation API. It secretly already works:

julia> using Proj

julia> pipe = Proj.proj_create("+proj=pipeline +step +proj=unitconvert +xy_in=deg +z_in=m +xy_out=rad +z_out=m +step +inv +proj=longlat +a=6378136.3 +rf=298.257 +e=0.08181922146 +step +proj=cart +a=6378136.3 +rf=298.257 +step +inv +proj=cart +ellps=WGS84 +step +proj=unitconvert +xy_in=rad +z_in=m +xy_out=deg +z_out=m +step +proj=axisswap +order=2,1")
Ptr{Nothing} @0x0000000066f7aee0

julia> trans = Proj.Transformation(pipe, PJ_FWD);

julia> trans(0, 0, 0)
(0.0, 0.0, -0.7000000001862645)

Though that hides the rough edges, since some of the code, like, show don't work:

julia> trans = Proj.Transformation(pipe, PJ_FWD)
Error showing value of type Proj.Transformation:
ERROR: ArgumentError: cannot convert NULL to string
Stacktrace:
  [1] unsafe_string
    @ .\strings\string.jl:70 [inlined]
  [2] unsafe_string
    @ .\c.jl:193 [inlined]
  [3] show(io::IOContext{Base.TTY}, trans::Proj.Transformation)
    @ Proj D:\visser_mn\.julia\dev\Proj\src\coord.jl:104

And we'd probably want a constructor that takes a single string, rather than passing the pointer to the pipeline created by proj_create.