Skip to content

Commit 43e732f

Browse files
authored
Merge pull request #4 from animesh2049/animesh2049/upstream-contribution
Add api to create transform object
2 parents f61d56b + 3bddd76 commit 43e732f

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

Diff for: v5/proj.go

+33
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,39 @@ func (ctx *Context) Create(definition string) (*PJ, error) {
126126
return &p, nil
127127
}
128128

129+
func (ctx *Context) CreateCRS2CRS(srcDefn, dstDefn string) (*PJ, error) {
130+
if !ctx.opened {
131+
return &PJ{}, errContextClosed
132+
}
133+
134+
srcDefnC := C.CString(srcDefn)
135+
dstDefnC := C.CString(dstDefn)
136+
defer func() {
137+
C.free(unsafe.Pointer(srcDefnC))
138+
C.free(unsafe.Pointer(dstDefnC))
139+
}()
140+
141+
pj := C.proj_create_crs_to_crs(ctx.pj_context, srcDefnC, dstDefnC, nil)
142+
if pj == nil {
143+
errno := C.proj_context_errno(ctx.pj_context)
144+
err := C.GoString(C.proj_errno_string(errno))
145+
return &PJ{}, errors.New(err)
146+
}
147+
148+
p := PJ{
149+
opened: true,
150+
context: ctx,
151+
index: ctx.counter,
152+
pj: pj,
153+
}
154+
155+
ctx.projections[ctx.counter] = &p
156+
ctx.counter++
157+
158+
runtime.SetFinalizer(&p, (*PJ).Close)
159+
return &p, nil
160+
}
161+
129162
// Close a transformation object
130163
func (p *PJ) Close() {
131164
if p.opened {

0 commit comments

Comments
 (0)