From 3bddd76038dbd77d2a91b3ffe108a0176aac41bb Mon Sep 17 00:00:00 2001 From: Animesh Pathak Date: Tue, 10 May 2022 16:33:15 +0300 Subject: [PATCH] Add api to create transform object To transform a coordinate from one crs to another we need a PJ object. This API will create PJ for such transformation, which can later be used for converting coordinate. --- v5/proj.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/v5/proj.go b/v5/proj.go index f2f9dc3..1a23422 100644 --- a/v5/proj.go +++ b/v5/proj.go @@ -126,6 +126,39 @@ func (ctx *Context) Create(definition string) (*PJ, error) { return &p, nil } +func (ctx *Context) CreateCRS2CRS(srcDefn, dstDefn string) (*PJ, error) { + if !ctx.opened { + return &PJ{}, errContextClosed + } + + srcDefnC := C.CString(srcDefn) + dstDefnC := C.CString(dstDefn) + defer func() { + C.free(unsafe.Pointer(srcDefnC)) + C.free(unsafe.Pointer(dstDefnC)) + }() + + pj := C.proj_create_crs_to_crs(ctx.pj_context, srcDefnC, dstDefnC, nil) + if pj == nil { + errno := C.proj_context_errno(ctx.pj_context) + err := C.GoString(C.proj_errno_string(errno)) + return &PJ{}, errors.New(err) + } + + p := PJ{ + opened: true, + context: ctx, + index: ctx.counter, + pj: pj, + } + + ctx.projections[ctx.counter] = &p + ctx.counter++ + + runtime.SetFinalizer(&p, (*PJ).Close) + return &p, nil +} + // Close a transformation object func (p *PJ) Close() { if p.opened {