0
0
Drone Programmingprogramming~20 mins

GPS data processing in Drone Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
GPS Data Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Calculate distance between two GPS points

What is the output of this code that calculates the distance between two GPS coordinates using the Haversine formula?

Drone Programming
import math

def haversine(lat1, lon1, lat2, lon2):
    R = 6371  # Earth radius in km
    phi1 = math.radians(lat1)
    phi2 = math.radians(lat2)
    dphi = math.radians(lat2 - lat1)
    dlambda = math.radians(lon2 - lon1)

    a = math.sin(dphi/2)**2 + math.cos(phi1)*math.cos(phi2)*math.sin(dlambda/2)**2
    c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))

    return R * c

print(round(haversine(52.2296756, 21.0122287, 41.8919300, 12.5113300), 2))
A1150.25
B1317.53
C2890.12
D980.45
Attempts:
2 left
💡 Hint

Remember the Haversine formula calculates great-circle distance between two points on a sphere.

🧠 Conceptual
intermediate
1:30remaining
Understanding GPS coordinate formats

Which option correctly converts GPS coordinates from degrees, minutes, seconds (DMS) to decimal degrees?

Adecimal = degrees + minutes/60 + seconds/3600
Bdecimal = degrees + minutes*60 + seconds*3600
Cdecimal = degrees * 60 + minutes + seconds/60
Ddecimal = degrees + minutes/3600 + seconds/60
Attempts:
2 left
💡 Hint

Think about how many minutes are in a degree and how many seconds are in a minute.

🔧 Debug
advanced
2:30remaining
Fix the GPS coordinate parsing error

What error does this code raise when parsing GPS coordinates from a string?

gps_str = "48°51'29.6\"N, 2°17'40.2\"E"
lat, lon = gps_str.split(",")
lat_deg, lat_min, lat_sec = map(float, lat[:-1].split("°"))
lon_deg, lon_min, lon_sec = map(float, lon[:-1].split("°"))
AValueError: too many values to unpack
BAttributeError: 'float' object has no attribute 'split'
CValueError: could not convert string to float
DIndexError: string index out of range
Attempts:
2 left
💡 Hint

Check how the string is split and converted to float.

📝 Syntax
advanced
1:30remaining
Identify the syntax error in GPS data filtering

Which option contains the correct syntax to filter GPS points with latitude greater than 40 using a dictionary comprehension?

Drone Programming
gps_points = {"p1": (39.9, -75.2), "p2": (41.1, -74.9), "p3": (40.5, -73.9)}
A{k: v for k, v in gps_points.items() if v[0] => 40}
B{k: v if v[0] > 40 for k, v in gps_points.items()}
C{k: v for k, v in gps_points.items() v[0] > 40}
D{k: v for k, v in gps_points.items() if v[0] > 40}
Attempts:
2 left
💡 Hint

Remember the correct order of clauses in a dictionary comprehension.

🚀 Application
expert
3:00remaining
Calculate average GPS speed from timestamped points

Given a list of GPS points with timestamps, which option correctly calculates the average speed in km/h between the first and last points?

points = [
    {"lat": 52.0, "lon": 21.0, "time": 0},
    {"lat": 52.1, "lon": 21.1, "time": 1800},  # 30 minutes later
    {"lat": 52.2, "lon": 21.2, "time": 3600}   # 60 minutes later
]
A
from math import radians, sin, cos, sqrt, atan2
R = 6371
p1, p2 = points[0], points[-1]
dlat = radians(p2['lat'] - p1['lat'])
dlon = radians(p2['lon'] - p1['lon'])
phi1 = radians(p1['lat'])
phi2 = radians(p2['lat'])
a = sin(dlat/2)**2 + cos(phi1)*cos(phi2)*sin(dlon/2)**2
c = 2*atan2(sqrt(a), sqrt(1-a))
distance = R * c
elapsed_hours = (p2['time'] - p1['time']) / 3600
speed = distance / elapsed_hours
print(round(speed, 2))
B
p1, p2 = points[0], points[-1]
distance = ((p2['lat'] - p1['lat'])**2 + (p2['lon'] - p1['lon'])**2)**0.5
elapsed_hours = (p2['time'] - p1['time']) / 3600
speed = distance / elapsed_hours
print(round(speed, 2))
C
from math import radians, sin, cos, sqrt, atan2
R = 6371
p1, p2 = points[0], points[-1]
dlat = radians(p2['lat'] - p1['lat'])
dlon = radians(p2['lon'] - p1['lon'])
phi1 = radians(p1['lat'])
phi2 = radians(p2['lat'])
a = sin(dlat/2)**2 + cos(phi1)*cos(phi2)*sin(dlon/2)**2
c = 2*atan2(sqrt(a), sqrt(1-a))
distance = R * c
elapsed_hours = (p2['time'] - p1['time'])
speed = distance / elapsed_hours
print(round(speed, 2))
D
from math import radians, sin, cos, sqrt, atan2
R = 6371
p1, p2 = points[0], points[-1]
dlat = radians(p2['lat'] - p1['lat'])
dlon = radians(p2['lon'] - p1['lon'])
phi1 = radians(p1['lat'])
phi2 = radians(p2['lat'])
a = sin(dlat/2)**2 + cos(phi1)*cos(phi2)*sin(dlon/2)**2
c = 2*atan2(sqrt(a), sqrt(1-a))
distance = R * c
elapsed_hours = (p2['time'] - p1['time']) / 60
speed = distance / elapsed_hours
print(round(speed, 2))
Attempts:
2 left
💡 Hint

Use the Haversine formula for distance and convert time difference to hours correctly.