Hi everyone,
I have never posted on a site like this before but am unfortunately a bit stuck on this problem... Hopefully someone much smarter than myself can help me out!
I have a table in MS Access 2013 full of latitude and longitude values. I am wanting to use a distance formula (something like one shown below) to loop through all the records in this same table and count entries that are within a user defined distance of one-another. Ideally I could run an update query at the same time to dump the values back into the table for use in visualization software. The table has approximately 200,000 entries. Can't imagine that is enough to cause a problem.
Saying that I am even an amateur in VBA would be a stretch but I can usually figure most basic problems out. This one is a bit outside of my ability level though so any help would be greatly appreciated! Thanks in advance for any help!
I have never posted on a site like this before but am unfortunately a bit stuck on this problem... Hopefully someone much smarter than myself can help me out!
I have a table in MS Access 2013 full of latitude and longitude values. I am wanting to use a distance formula (something like one shown below) to loop through all the records in this same table and count entries that are within a user defined distance of one-another. Ideally I could run an update query at the same time to dump the values back into the table for use in visualization software. The table has approximately 200,000 entries. Can't imagine that is enough to cause a problem.
Saying that I am even an amateur in VBA would be a stretch but I can usually figure most basic problems out. This one is a bit outside of my ability level though so any help would be greatly appreciated! Thanks in advance for any help!
Code:
Option Compare Database Function DistanceFeet(lat1 As Double, lon1 As Double, lat2 As Double, lon2 As Double) Dim EarthRadius As Double Dim KmtoMiFactor As Double Dim lat1Rad As Double Dim lon1Rad As Double Dim lat2Rad As Double Dim lon2Rad As Double Dim AsinBase As Double Dim DerivedAsin As Double EarthRadius = 6371 KmtoMiFactor = 0.621371 lat1Rad = (lat1 / 180) * 3.14159265359 lon1Rad = (lon1 / 180) * 3.14159265359 lat2Rad = (lat2 / 180) * 3.14159265359 lon2Rad = (lon2 / 180) * 3.14159265359 AsinBase = Sin(Sqr(Sin((lat1Rad - lat2Rad) / 2) ^ 2 + Cos(lat1Rad) * Cos(lat2Rad) * Sin((lon1Rad - lon2Rad) / 2) ^ 2)) DerivedAsin = (AsinBase / Sqr(-AsinBase * AsinBase + 1)) DistanceFeet = Round(2 * DerivedAsin * (EarthRadius * KmtoMiFactor) * 5280, 0) End Function
Comment