Skip to content

Commit

Permalink
Add api to create transform object
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
animesh2049 committed May 10, 2022
1 parent f61d56b commit 3bddd76
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions v5/proj.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3bddd76

Please sign in to comment.