📖 Scenario: You are working with a drone to survey a small area for mapping purposes. The drone takes photos at specific GPS coordinates. You want to organize these photos and prepare data for photogrammetry processing.
🎯 Goal: Create a program that stores GPS coordinates with photo IDs, sets a minimum number of photos required for mapping, filters the photos that meet this requirement, and finally prints the list of valid photo IDs for photogrammetry.
📋 What You'll Learn
Create a dictionary with photo IDs as keys and GPS coordinates as values
Create a variable for the minimum number of photos required
Filter the dictionary to keep only photos with valid GPS coordinates
Print the list of valid photo IDs
💡 Why This Matters
🌍 Real World
Drones capture many photos during a survey. Organizing and filtering these photos by GPS data helps prepare accurate maps and 3D models.
💼 Career
Surveyors, GIS specialists, and drone operators use similar programming skills to automate data processing for mapping projects.
Progress0 / 4 steps
1
Create the photo data dictionary
Create a dictionary called photos with these exact entries: 'photo1': (34.05, -118.25), 'photo2': (34.06, -118.26), 'photo3': (34.07, -118.27), 'photo4': None, 'photo5': (34.08, -118.28)
Drone Programming
Hint
Use a dictionary with photo IDs as keys and tuples for GPS coordinates. Use None for missing coordinates.
2
Set the minimum photos required
Create a variable called min_photos and set it to 3 to represent the minimum number of photos required for mapping
Drone Programming
Hint
Just create a variable named min_photos and assign the number 3.
3
Filter photos with valid GPS coordinates
Create a new dictionary called valid_photos that includes only entries from photos where the GPS coordinates are not None
Drone Programming
Hint
Use a dictionary comprehension to keep only photos where coordinates are not None.
4
Print the list of valid photo IDs
Print the list of keys from valid_photos using print(list(valid_photos.keys()))
Drone Programming
Hint
Use print(list(valid_photos.keys())) to show the photo IDs.
Practice
(1/5)
1. What is the main purpose of using photogrammetry in drone surveying?
easy
A. To create maps and 3D models from overlapping photos
B. To control the drone's battery life
C. To improve the drone's flight speed
D. To reduce the number of photos taken
Solution
Step 1: Understand photogrammetry basics
Photogrammetry uses many overlapping photos to build maps and 3D models.
Step 2: Identify the main goal in drone surveying
The goal is to create accurate maps and 3D models from the photos taken by the drone.
Final Answer:
To create maps and 3D models from overlapping photos -> Option A
Quick Check:
Photogrammetry = maps and 3D models [OK]
Hint: Photogrammetry means building maps from photos [OK]
Common Mistakes:
Confusing photogrammetry with drone battery management
Thinking photogrammetry speeds up flight
Assuming photogrammetry reduces photo count
2. Which of the following is the correct syntax to define a flight path list in Python for drone photogrammetry?
easy
A. flight_path = {"point1", "point2", "point3"}
B. flight_path = ("point1", "point2", "point3")
C. flight_path = ["point1", "point2", "point3"]
D. flight_path = "point1", "point2", "point3"
Solution
Step 1: Identify list syntax in Python
Lists use square brackets [] with items separated by commas.
Step 2: Check each option
flight_path = ["point1", "point2", "point3"] uses square brackets and quotes correctly for strings.
Final Answer:
flight_path = ["point1", "point2", "point3"] -> Option C
Quick Check:
List syntax = square brackets [OK]
Hint: Lists use square brackets [] in Python [OK]
Common Mistakes:
Using parentheses instead of square brackets for lists
Using curly braces which create sets, not lists
Leaving out brackets and just separating by commas
3. What will be the output of this Python code snippet used in photogrammetry data processing?
photos = ["img1.jpg", "img2.jpg", "img3.jpg"]
processed = [photo.replace('.jpg', '.tif') for photo in photos]
print(processed)
medium
A. ["img1.tif", "img2.tif", "img3.tif"]
B. ["img1.jpg", "img2.jpg", "img3.jpg"]
C. ["img1.tif.jpg", "img2.tif.jpg", "img3.tif.jpg"]
D. SyntaxError
Solution
Step 1: Understand list comprehension with string replace
Each photo filename has '.jpg' replaced by '.tif'.
Step 2: Apply replace to each item
"img1.jpg" becomes "img1.tif", similarly for others.
Final Answer:
["img1.tif", "img2.tif", "img3.tif"] -> Option A
Quick Check:
Replace '.jpg' with '.tif' = changed list [OK]
Hint: String replace in list comprehension changes extensions [OK]
Common Mistakes:
Expecting original list without changes
Thinking replace adds text instead of replacing
Confusing syntax causing errors
4. Identify the error in this Python code snippet for planning drone photo overlap:
overlap = 0.7
if overlap > 1:
print("Overlap too high")
else
print("Overlap acceptable")
medium
A. Incorrect comparison operator in if statement
B. Missing colon after else statement
C. Variable overlap should be an integer
D. Print statements must be outside if-else
Solution
Step 1: Check syntax of if-else statements
Python requires a colon ':' after else keyword.
Step 2: Identify missing colon
Code has 'else' without a colon, causing syntax error.
Final Answer:
Missing colon after else statement -> Option B
Quick Check:
else: needs colon [OK]
Hint: Always put colon after else in Python [OK]
Common Mistakes:
Forgetting colon after else
Thinking overlap must be integer
Misreading comparison operator
5. You want to generate a dictionary mapping photo filenames to their GPS coordinates after a drone flight. Which Python code correctly creates this dictionary from two lists: photos = ["img1.jpg", "img2.jpg", "img3.jpg"] and coords = [(34.5, -117.2), (34.6, -117.3), (34.7, -117.4)]?
hard
A. photo_coords = [photos, coords]
B. photo_coords = dict(zip(coords, photos))
C. photo_coords = {coords[i]: photos[i] for i in range(len(coords))}
D. photo_coords = {photos[i]: coords[i] for i in range(len(photos))}
Solution
Step 1: Understand dictionary creation from two lists
We want keys as photo names and values as coordinates.
Step 2: Check each option
photo_coords = {photos[i]: coords[i] for i in range(len(photos))} uses dictionary comprehension with matching indexes correctly.
Final Answer:
photo_coords = {photos[i]: coords[i] for i in range(len(photos))} -> Option D
Quick Check:
Dict keys=photos, values=coords [OK]
Hint: Use dict comprehension with index to pair lists [OK]
Common Mistakes:
Swapping keys and values in dict
Using zip with wrong order
Creating list instead of dict
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.