I have a dataframe with latitude and longitudes:
latitude longitude
0 -1.621622 8.918919
1 -1.216216 8.648649
2 -1.486486 8.783784
3 -2.027027 8.918919
4 -1.216216 8.648649
I want to round the coordinates to a define number of kilometers n (between 5 and 50), which means I will obtain a subset of coordinates, with n kilometers between each point.
Basically, I can round to 1 decimal, which approximately corresponds to 11.1 km (http://wiki.gis.com/wiki/index.php/Decimal_degrees):
latitude longitude
0 -1.6 8.9
1 -1.2 8.6
2 -1.5 8.8
3 -2.0 8.9
4 -1.2 8.6
But how can I achieve this if n is not 11.1 ? For instance if n = 10.
I tried the following formula:
degree_to_km_factor = 1.11
ratio = degree_to_km_factor / n = 0.111
rounded_latitude = (latitude * ratio).round(2) / ratio
Which gives me:
latitude longitude
0 -1.621622 8.918919
1 -1.171171 8.738739
2 -2.072072 8.918919
3 -2.072072 8.918919
4 -1.621622 8.918919
This allows me to get latitude and longitude points rounded to 1/11.1 = 0.09, which correspond to 10 kilometers.
I've tested this formula for several values of n and it seems to work, but I'm not sure it is correct and I didn't achieve to prove it. Do you know if it is correct, and if not, is there a better way to achieve this ?
NOTE: I assume I'm always at the equator, so the approximation 1 degree = 111 km is always true in my case, I don't need to be more precise than this.