Excercise: Geopandas
Aufgabe
Table with Geolocations
Generate a table with all landing coordinates on earth, with the location of all apollo missionsPython Code
Output
Last updated
Generate a table with all landing coordinates on earth, with the location of all apollo missionsLast updated
Create python code for those coordinates using geopandas in a colab book# Install necessary libraries in Colab
!pip install geopandas matplotlib descartes
# Import libraries
import geopandas as gpd
import pandas as pd
import matplotlib.pyplot as plt
from shapely.geometry import Point
import os # Import the os module
# Define the Apollo mission landing coordinates and locations
data = {
"Mission": [
"Apollo 7", "Apollo 8", "Apollo 9", "Apollo 10",
"Apollo 11", "Apollo 12", "Apollo 13", "Apollo 14",
"Apollo 15", "Apollo 16", "Apollo 17"
],
"Latitude": [27.23, 8.10, 23.25, -15.25, 13.30, -15.78, -21.63, -27.02, 26.13, 0.70, -16.47],
"Longitude": [-64.04, -165.00, -67.56, -164.55, -169.15, -165.15, -165.39, -172.65, -158.13, -156.23, -166.12]
}
# Create a Pandas DataFrame
df = pd.DataFrame(data)
# Create a GeoDataFrame with the coordinates
geometry = [Point(xy) for xy in zip(df["Longitude"], df["Latitude"])]
gdf = gpd.GeoDataFrame(df, geometry=geometry)
# Download the world map data from Natural Earth
!wget https://naturalearth.s3.amazonaws.com/110m_cultural/ne_110m_admin_0_countries.zip
!unzip ne_110m_admin_0_countries.zip
# Load the world map using GeoPandas
world = gpd.read_file("ne_110m_admin_0_countries.shp") # Load the world map data
# Plot the world map
fig, ax = plt.subplots(figsize=(12, 8))
world.plot(ax=ax, color="lightgrey")
# Plot the landing sites
gdf.plot(ax=ax, color="red", markersize=50, label="Apollo Landing Sites")
# Annotate the map with mission names
for x, y, label in zip(gdf.geometry.x, gdf.geometry.y, gdf["Mission"]):
ax.text(x + 2, y, label, fontsize=8, color="blue")
# Add title and legend
plt.title("Apollo Mission Landing Sites on Earth", fontsize=14)
plt.legend(loc="lower left")
plt.show()