-
Notifications
You must be signed in to change notification settings - Fork 942
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
Custom earth radius #1176
Comments
Hey @dhivehi, not sure if this is what you need but you can get the earth radius from /**
* Earth Radius used with the Harvesine formula and approximates using a spherical (non-ellipsoid) Earth.
*/
export var earthRadius = 6371008.8; which I believe is also used internally as global/constant value, isn't it @DenisCarriere ? |
Sorry, just realized you said set and not get... 😅 I guess now that we adopted the |
I want that feature mostly in distance calculation modules. But would be better if can be used in all modules. |
Perhaps reconsider using options to override the radius. That might work ok for using distance directly. However any other modules that in turn use distance would need to also accept earthRadius as an option so everything matches up. For example, the midpoint function. It may be better to pass the new radius from the inside out globally, rather than outside in on a case by case basis. Something like having @turf/helpers check for an environment variable override which applies the desired radius globally (at least within turf). |
I agree with your approach @smallsaucepan if it can work. I think you brought it up in a discussion. What does this mechanism look like? Needs to work in browser and node/other runtimes, and also if user isn't importing and using the big turf library, but rather individual turf packages e.g. It could be a global variable that helpers looks for on init? Falling back to a default value of mean radius.
How the global variable gets set in user space code would be up to the user. Simple browser app it can be set in the base script, or top of a module, before using Turf. If user bundles their app with Vite, they can pass in the value via an environment variable at build time and set the variable - https://vitejs.dev/guide/env-and-mode. [EDIT] I guess turf would be checking for the global variable right when it is imported, so the global variable would need to be set before import. |
I think it would be better to be able to set earth's radius as a global parameter in turf. Because many people like me would be using google earth's radius which is also accepted by many professional organaisations. As for now, for every update, i download turf js and edit radius and use.
The text was updated successfully, but these errors were encountered: