Azimuth, Draw a line

Question:

I’m trying to draw a azimuth of a given coordinate on the map using folium. I’m new to Python and I’m lost.
The objective is to receive a coordinate and a degree and draw it to the map.
I’m trying using folium, but it doesn’t need to be folium.

import folium

# criar o objeto do mapa
m = folium.Map(location=[37.0431575, -7.8449655], zoom_start=14)

# Texto que vai aparecer no marcador
tootip = "Célula em Olhão"

folium.CircleMarker(
    location=[37.040893, -7.83197],
    radius=4,
    popup="célula",
).add_to(m)

# posicao = folium.RegularPolygonMarker(
#     location=[37.040893, -7.83197],
#     fill_color='blue',
#     number_of_sides=3,
#     radius=10,
#     rotation=45).add_to(m)
# I TRIED WITH A TRIANGULE BUT I COULDN'T UNDERSTAND WHICH PART WAS 
# POINTING AT THE DESIRED DIRECTION

m.save("mapa.html")

How can I draw a line starting at the circle degree 45º ? The size of the line isn’t important, it only has to be visible.

Asked By: Mário Mendonça

||

Answers:

Something like this?

With the help of math and some trig

import folium
import math

# criar o objeto do mapa
m = folium.Map(location=[37.0431575, -7.8449655], zoom_start=14)

# Texto que vai aparecer no marcador
tootip = "Célula em Olhão"

origin_point = [37.040893, -7.83197]

folium.CircleMarker(
    location=origin_point,
    radius=4,
    popup="célula",
).add_to(m)

length = .01
angle = 45

end_lat = origin_point[0] + length * math.sin(math.radians(angle))
end_lon = origin_point[1] + length * math.cos(math.radians(angle))

folium.PolyLine([origin_point, [end_lat, end_lon]]).add_to(m)

m

enter image description here

Answered By: Bob Haffner
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.