Hi,
I was hoping you can help me with the above. I have longitude and latitude for several different locations and would like to calculate the distance between them. I know we have functions like Cos, Sin and Tan to enable us to do this however I just can't seem to wrap my head around it. I have found similar scripts for VB but have been unsuccessful trying to incorporate it into IDEAScript.
Any help would be greatly appreciated and please let me know if you require any further information.
Thanks
Salman
salman.qasim
Offline
Last seen: 8 years 5 months ago
Joined: 07/03/2014 - 09:24
Hello Salman, I found a vb script to calculate the distance at http://www.geodatasource.com/developers/vb and I have adapted it as a custom function. The function will accept the latitude and longitude of two points and return the distance in miles, kilometers or nautical miles. I have not tested this function so I can't guarentee the accuracy, if you can do that it would be appreciated.
Brian
Hi Brian,
Thank you for your prompt reply! I did find that VB code but was unsure on what amendments to make to make it work with IDEAscript. I have very limited knowledge of scripting but I am trying to learn as much as I can before my training course later this year.Please see attached image of the code which I have had to amend slightly. I only need the output in miles. It wouldn't let me proceed without defining the variables shown and now it gives me a constant value for every record. Are you able to use the coordinates in the image to help test the file? Can you please advise if I have missed something or defined the variables incorrectly?Thanks
Salman
Hi Salem, when using the custom functions you have to define your parameters outside of the script, in your case you are defining your parameters within the script which is fine for IDEAScript code but not for a custom function. Here is a screen capture of the parameters dialog:
Here is the rest of the code. I will attach the updated custom function.
Ah, thank you for putting me right! It seems we are very close as there are no errors in the code however when I click test, I get the following error message:
Hi Salem, you are getting that error because you dont' have any parameters for the test equation. When you hit test it will take the parameters of the distlatlong() and use them in the function, as it is blank there are no parameters. Instead doing something like this: distlatlong(32.9697, -96.80322, 29.46786, -98.53) it will now have the 4 needed numeric paramters and it can calculate the distance.
Hi Brian, I knew it was something silly I missed! That's it up and running now and I have tested the quality of data against web based calculators. Might be handy to put this in the scripts section for others to use as well. Thanks again for your help and patience, it's been a steep learning curve.
Regards
Salman
Hi Salman, I am glad I could help out.