Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Lab 3

image image

This notebook contains exercises based on the lectures on Functions and Classes and Files and Exception Handling. These exercises will help reinforce the concepts of functions, classes, file handling, and exception management in geospatial contexts.

Exercise 1: Calculating Distances with Functions

Exercise 2: Batch Distance Calculation

Exercise 3: Creating and Using a Point Class

Exercise 4: Reading and Writing Files

Exercise 5: Processing Coordinates from a File

# Create a sample coordinates.txt file
sample_data = """35.6895,139.6917
34.0522,-118.2437
51.5074,-0.1278
-33.8688,151.2093
48.8566,2.3522"""

output_file = "coordinates.txt"

try:
    with open(output_file, "w") as file:
        file.write(sample_data)
    print(f"Sample file '{output_file}' has been created successfully.")
except Exception as e:
    print(f"An error occurred while creating the file: {e}")

Exercise 6: Exception Handling in Data Processing