Network and Interconnection in Python Maps

#Population file
file1 = “data/npl_ppp_2020.tif”
#Open file
raster_file1 = rasterio.open(file1)
#Read raster data
pop_data = raster_file1.read(1)
def plot_raster(raster_data, title = “”, figsize = (8, 6)):
“””
Plot population count in log scale (+1)
“””
plt.figure(figsize = figsize)
im1 = plt.imshow(np.log1p(raster_data), cmap = “viridis”,)
plt.title(f”{title}”, fontdict = {“fontsize”: 14})
plt.axis(“off”)
plt.colorbar(im1, fraction = 0.03)
Log-scaled spatial distribution of population in Nepal in 2020. Image by Author.
Log-scaled spatial distribution of population density in Nepal in 2020. Image by Author.
Exploring the political and administrative boundaries shapefile of Nepal using geopandas. Image by Author.

Geocoding

Geocoding and reverse geocoding using geopy library in Python. Image by Author.

Plotting operational airports in the map of Nepal

fig, ax = plt.subplots(figsize = (8, 6))
plt.rcParams[“font.size”] = 14
nepal.plot(color = “silver”, ax = ax)for lat, lon in zip(df[“Latitude”],df[“Longitude”]):
ax.plot(lon, lat, marker = “o”, color = “red”)

plt.title(“Operational airports in Nepal”, fontweight = “bold”)

Map of Nepal with 31 operational airports. Image by Author.

Convex Hull

from scipy.spatial import ConvexHull, convex_hull_plot_2d
points = np.array([[lon, lat] for lat, lon in zip(airport_latitudes, airport_longitudes)])
hull = ConvexHull(points)
hull_indices = np.unique(hull.simplices.flat)
hull_points = points[hull_indices, :]
fig, ax = plt.subplots()
nepal.plot(ax = ax, color = “silver”)
ax.plot(points[:,0], points[:,1], ‘o’)
ax.plot(hull_points[:,0], hull_points[:,1], “ro”, alpha = 0.25)
for simplex in hull.simplices:
ax.plot(points[simplex, 0], points[simplex, 1], ‘r — ‘)
plt.title("Convex Hull of the operational airports in Nepal")
Convex hull of the operational airports in Nepal. Image by Author.

Domestic flights from Kathmandu to other locations

Dataframe showing the list of 12 airports along with their latitude and longitude that has a connection with Tribhuvan International Airport in Kathmandu, Nepal.
Code to plot the domestic flights from Kathmandu to other airports in Nepal.
Domestic flight routes with connection to Kathmandu, Nepal. Image by Author.
#Function to draw a curved line between two points
def draw_curve(p1, p2):
“””Return curves lines between two points p1 and p2.”””
#np.cosh(x) is equivalent to 0.5*(np.exp(x) — np.exp(-x))
a = (p2[1] — p1[1])/ (np.cosh(p2[0]) — np.cosh(p1[0]))
b = p1[1] — a * np.cosh(p1[0])
x = np.linspace(p1[0], p2[0], 100)
y = a * np.cosh(x) + b
return x, y
Domestic flight routes with connection to Kathmandu, Nepal are shown as curved lines. Image by Author.

References