I have problems with shifting coordinates by 100 meters horizontaly/verticaly in Python. I found that If your displacements aren't too great (less than a few kilometers) and you're not right at the poles, use the quick and dirty estimate that 111,111 meters (111.111 km) in the y direction is 1 degree (of latitude) and 111,111 * cos(latitude) meters in the x direction is 1 degree (of longitude). here: https://gis.stackexchange.com/questions/2951/algorithm-for-offsetting-a-latitude-longitude-by-some-amount-of-meters
I wrote two functions in Python. This function works, that is it computes the shift in latitude:
def vertikalne(shift):
return shift/111_111
Check that distance between (49.550586, 18.859254) and (49.550586 + vertikalne(100), 18.859254) is really 100 meters.
But this function does not work and I don`t know what is the problem:
import math
def horizontalne(latitude, shift):
return (shift/111_111) * math.cos(latitude*math.pi/180) # UPDATE: I just converted to radians
Distance between (49.550586, 18.859254) and (49.550586 , 18.859254 + horizontalne(49.550586 , 100)) is 49 which is nonsense.
Can you help me please?
math.cosexpects radians, not degrees. convert your latitude to radians before applying the cosinus.math.cos(latitude)? Are you able to do the calculation by hand? If so, that makes it much easier to notice what goes wrong.shiftvalue is 100. I check it on an example: distance between (49.550586, 18.859254) and (49.550586, 18.859254 + horizontalne(49.550586 , 100))