Forum Discussion
Calculate nearest points by geographical coordinates
- 9 years ago
It seems, I figured how to do it
I made the user function
(reg,x_cast,y_cast)=>
let
Source = Table.SelectRows(shop,each [region]=reg),
formula = Table.AddColumn(Sorce, "Distance", each
6371 * 2 *Number.Asin(Number.Sqrt(Number.Power(Number.Sin((y_cast-[y_shop])*Number.PI/180/2),2)+Number.Cos(y_cast*Number.PI/180)*Number.Cos([y_shop]*Number.PI/180)*Number.Power(Number.Sin((x_cast-[x_shop])*Number.PI/180/2),2)))),
minimum = List.Min(formula[Distance]),
fnl_tbl= Table.SelectRows(formula,each [Custom]=minimum)
in
fnl_tbl
Unfortunatly, I do not understand how ArcGIS map could solve my task
How many distinct cities are in your customers table? If significantly less than your number of customers, you could perform the distance calculation based on a list of just the distinct cities of your customers table. Then buffer that result and join back to the customers.
- Dmitry_D9 years agoFrequent Visitor
It seems, I figured how to do it
I made the user function
(reg,x_cast,y_cast)=>
let
Source = Table.SelectRows(shop,each [region]=reg),
formula = Table.AddColumn(Sorce, "Distance", each
6371 * 2 *Number.Asin(Number.Sqrt(Number.Power(Number.Sin((y_cast-[y_shop])*Number.PI/180/2),2)+Number.Cos(y_cast*Number.PI/180)*Number.Cos([y_shop]*Number.PI/180)*Number.Power(Number.Sin((x_cast-[x_shop])*Number.PI/180/2),2)))),
minimum = List.Min(formula[Distance]),
fnl_tbl= Table.SelectRows(formula,each [Custom]=minimum)
in
fnl_tbl- ImkeF9 years ago
Community Champion
Yes , of course thats the best way as you don't have to group (and the tables to operate on are shorter).
How many times faster does it make your query?
- Dmitry_D9 years agoFrequent Visitor
Input data
Customer_table = 13 mln rows
Shop_table = 540 rows
The 1st method (with Group) was endless. After 20 minutes of waiting I stopped id
The 2nd method (with user function) takes about 7 seconds
- DAQEY8 years agoNew Member
Thanks for sharing your solution! I have the exact same issue with two tables of Latitude and Longitudes and a need to find the nearest location like finding the nearest shop to each customer. Can you please explain a little more of the syntax in your solution and how you implemented it?
Did you use that code to create a new column in your table containing the customer locations or did you create a 3rd table? Is thise done with just 1 column? Would you be able to share an example file so I can follow how your solution was implemented?
Thank you