I am wanting to create a circle with an inputted radius around a point of predetermined latitude and longitude. I've been trying to use the formula found in this post which uses an algorithm documented by Ed Williams found here - but the outcome always creates a rectangle (seen below after plotted on google earth).
My code looks like:
bufferRange = input("enter radius of buffer zone")
bufferRange = float(bufferRange)
angle = 0
newCoords = []
for i in range(360):
lonDD = abs(lonDD)
d = bufferRange/6371
Radian = angle * 0.017453
lat = math.asin(math.sin(latDD)*math.cos(d)+math.cos(latDD)*math.sin(d)*math.cos(Radian))
lon=math.fmod(lonDD - math.asin(math.sin(Radian) * math.sin(d)/math.cos(lat))+math.pi,2*math.pi)-math.pi
if 0 < angle < 90:
lat = latDD + lat
lon = lonDD + lon
elif 90 < angle < 180:
lat = latDD - lat
lon = lonDD + lon
elif 180 < angle < 270:
lat = latDD - lat
lon = lonDD - lon
elif 270 < angle < 360:
lat = latDD + lat
lon = lonDD - lon
elif angle == 90:
lat = latDD
lon = lonDD + lon
elif angle == 180:
lat = latDD - lat
lon = lonDD
elif angle == 270:
lat = latDD
lon = lonDD - lon
else:
lat = latDD + lat
lon = lonDD
lon = -lon
if angle < 360:
newCoords.append((lon, lat), )
else:
newCoords.append((lon, lat))
angle = angle + 1
Where latDD and lonDD are the points at the center of the circle (Ottawa for this test).
Update:
After using xunilk's code (see below) the results improved, but the buffer is still not circular. I have a feeling its how I converted my longitude to meters, but I can't seem to find a better way to convert them online.
The following test was done with a buffer radius of 100km. The distance from the centre to the 'top' and 'bottom' of the buffer is exactly 100km. The distance from the centre to the sides of the buffer is 70.5km
polygonSides = 360
lat = (latDD*111.320)*1000
lonNum = 111320*math.cos(latDD)
lon = abs(lonDD)*111320
points_list = [ (-1*((lon + np.sin(angle)*bufferRange)/111320), (lat + np.cos(angle)*bufferRange)/111320)
for angle in np.linspace(0, 2*np.pi, polygonSides, endpoint = False) ]
i
?