Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gdal.config #5

Open
jdesboeufs opened this issue May 28, 2020 · 4 comments
Open

gdal.config #5

jdesboeufs opened this issue May 28, 2020 · 4 comments

Comments

@jdesboeufs
Copy link
Collaborator

Hi,

To open a shapefile with a specific encoding, we have to set SHAPE_ENCODING through gdal.config.set().

But after that, we are not able to reset this configuration to its original state, allowing other shapefile encodings to be auto-detected.
It could be useful to have an option to unset a config variable, or maybe a config contexte bound to the dataset, and not GDAL itself.

WDYT?

@yocontra
Copy link
Owner

Yeah that makes sense to me - I think adding an unset function, and being able to set it per function call would be the best move. It could be done easily in the JS portion of the project to avoid massive amounts of C++ changes, and unset would be added in C++ - want to send a PR?

@jdesboeufs
Copy link
Collaborator Author

I've found a work-around: gdal.config.set('VAR', undefined). It seems to work.

Yes I agree. It could be interesting to have some helpers like this.
OK to send a PR if this work-around is good or if we can have an unset function.

@yocontra
Copy link
Owner

I think unset or reset would be a fine API addition, and we can do a secondary PR to add a new helper.

Something like this could work? Pretty simple and flexible - would be much easier than adding a new config option to every single function

gdal.config(tempConfigObject, () => {
  // any gdal code here!
})

which would basically just be:

gdal.config = (obj, fn) => {
  const currentValues = gdal.config.get()
  const split = Object.entries(obj)
  split.forEach(([ k, v ]) => gdal.config.set(k, v))
  fn()
  split.forEach(([ k, v ]) => gdal.config.set(k, currentValues[k])
}

@mmomtchev
Copy link
Contributor

@contra, that could work, just don't do it with the gdal.config object which is C++ backed, choose any other name
@jdesboeufs when it comes to implementing this in C++, I am afraid it will require a very significant effort for a feature that can easily be reproduced in JS
In fact, gdal.config.set() and gdal.config.get() are simply wrappers around the GDAL-provided functions CPLSetConfigOption() and CPLGetConfigOption() - which do not have any other functionality. In C++, GDAL has another set of functions, CPLSetThreadLocalConfigOption() and CPLGetThreadLocalConfigOption(), which do exactly what you want, but these are unusable from Node.js where the event loop is handled by libuv which provides the thread management - in fact when calling GDAL you have absolutely no control over which thread is going to call it

oscarnc pushed a commit to AmristarSolutions/node-gdal-next that referenced this issue Dec 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants