I am working on an application that makes use of the c# Mapscript bindings. When I manually set and/or append to the GDAL_DATA, GDAL_DRIVER_PATH, PROJ_LIB, and PATH environment variables - the application code works beautifully.
For a number of reasons, I am trying to avoid permanently setting/changing these environment variables. I am under the impression that by using the .NET frameworks Environment.SetEnvironmentVariable method, that I should be able to set these environment variables at runtime for the current process.
This approach seems to work in some capacity - as the mapscript objects initialize properly (i.e., I dont get PInvoke errors...etc). In my code snippet below, I get an error at map.draw() complaining about GDAL_DATA and gcs.csv.
// add some new environment vars // TODO check if they may already exist - in which case append to Environment.SetEnvironmentVariable("GDAL_DATA",MY_GDAL_DATA_PATH) Environment.SetEnvironmentVariable("GDAL_DRIVER_PATH",MY_GDAL_DRIVER_PATH) Environment.SetEnvironmentVariable("PROJ_LIB",MY_PROJ_LIB_PATH) // append to existing PATH variable string pathVariable = Environment.GetEnvironmentVariable("PATH") pathVariable += MY_PATH_VARS Environment.SetEnvironmentVariable("PATH",MY_PATH_VARS) mapObj map = new mapObj(transmitterMapFile); map.setSize(request.Width, request.Height); map.setExtent(extent, extent, extent, extent); imageObj img = map.draw();
Does anyone see something wrong with this approach? Or is there a better way to set these variables at runtime?