diff --git a/context.go b/context.go index fd11638c..4bf2ab9b 100644 --- a/context.go +++ b/context.go @@ -39,6 +39,22 @@ func (c *Context) Destroy() { } } +// SetSearchPaths sets the paths PROJ should be exploring to find the PROJ Data files. +func (c *Context) SetSearchPaths(paths []string) { + c.Lock() + defer c.Unlock() + cPaths := make([]*C.char, len(paths)) + var pathPtr unsafe.Pointer + for i, path := range paths { + cPaths[i] = C.CString(path) + defer C.free(unsafe.Pointer(cPaths[i])) + } + if len(paths) > 0 { + pathPtr = unsafe.Pointer(&cPaths[0]) + } + C.proj_context_set_search_paths(c.pjContext, C.int(len(cPaths)), (**C.char)(pathPtr)) +} + func (c *Context) Lock() { c.mutex.Lock() } diff --git a/context_test.go b/context_test.go index e9595793..34467d25 100644 --- a/context_test.go +++ b/context_test.go @@ -139,3 +139,18 @@ func TestContext_NewFromArgs(t *testing.T) { }) } } + +func TestContext_SetSearchPaths(t *testing.T) { + defer runtime.GC() + + context := proj.NewContext() + assert.NotZero(t, context) + + // The C function does not return any error so we only validate + // that executing the SetSearchPaths function call + // does not panic considering various boundary conditions + context.SetSearchPaths(nil) + context.SetSearchPaths([]string{}) + context.SetSearchPaths([]string{"/tmp/data"}) + context.SetSearchPaths([]string{"/tmp/data", "/tmp/data2"}) +}