Geolocation World
In [4]:
#!pip install geopandas
#!pip install matplotlib
#!pip install geodatasets
In [2]:
# https://www.naturalearthdata.com/downloads/10m-cultural-vectors/
# Plotting on a World Map
import pandas as pd
from shapely.geometry import Point
import geopandas as gpd
import matplotlib.pyplot as plt
#################################################
## WORLD MAP
world = gpd.read_file("H:\\My Drive\\0001_projects\\2024\\Maps\\ne_10m_admin_0_countries.zip")
#################################################
## Points
data = {
'City': ['New York', 'Los Angeles', 'Chicago', 'London', 'Paris', 'Lisbon'],
'Latitude': [40.7128, 34.0522, 41.8781, 51.509865, 48.864716, 38.736946 ],
'Longitude': [-74.0060, -118.2437, -87.6298, -0.118092, 2.349014, -9.142685]
}
df = pd.DataFrame(data)
geometry = [Point(xy) for xy in zip(df['Longitude'], df['Latitude'])]
gdf = gpd.GeoDataFrame(df, geometry=geometry)
##################################################
# Plotting the world map
fig, ax = plt.subplots(1, 1, figsize=(15, 10))
world.plot(ax=ax, cmap='Pastel1', edgecolor='k')
gdf.plot(ax=ax, color='red', markersize=50)
plt.title('World Map')
plt.show()
