Created
September 21, 2012 17:16
-
-
Save zodman/3762723 to your computer and use it in GitHub Desktop.
Calc the near lat,lng in radius
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def get_near_point( lat,lng, radius): | |
""" http://gis.stackexchange.com/questions/25877/how-to-generate-random-locations-nearby-my-location""" | |
import math | |
u = random.random() | |
v = random.random() | |
r_d = radius/111300.0 | |
t = 2* math.pi*v | |
w = r_d * math.sqrt(u) | |
x = w* math.cos(t) | |
y = w*math.sin(t) | |
newx = x/math.cos(float(lat)) | |
return ( y+ float(lat), newx + float(lng)) | |
print get_near_point(21.030093, -89.558248, 100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment