# Function to generate random coordinates within latitude and longitude bounds
def random_coordinates(n, lat_min=-90, lat_max=90, lon_min=-180, lon_max=180):
"""Generates n random latitude/longitude coordinates.
Args:
n (int): The number of coordinates to generate.
lat_min (float): Minimum latitude. Defaults to -90.
lat_max (float): Maximum latitude. Defaults to 90.
lon_min (float): Minimum longitude. Defaults to -180.
lon_max (float): Maximum longitude. Defaults to 180.
Returns:
pandas.DataFrame: A DataFrame containing 'Longitude' and 'Latitude' columns.
"""
latitudes = [random.uniform(lat_min, lat_max) for _ in range(n)]
longitudes = [random.uniform(lon_min, lon_max) for _ in range(n)]
return pd.DataFrame({"Longitude": longitudes, "Latitude": latitudes})
numpoints = 1000
# Generate random coordinates across the globe
df = random_coordinates(numpoints)
# Add a 'Conc' column (optional, for demonstration)
df["Conc"] = np.random.randn(numpoints) + 17 # Example data
# Create GeoDataFrame
gdf = geopandas.GeoDataFrame(
df, geometry=geopandas.points_from_xy(df.Longitude, df.Latitude), crs="EPSG:4326"
)
m = leafmap.Map() # Start with a low zoom to show the global distribution
# Add the GeoDataFrame to the map
m.add_gdf(
gdf,
hover_style={"fillColor": "yellow", "fillOpacity": 1.0},
point_style={
"radius": 5,
"color": "red",
"fillColor": "red",
"fillOpacity": 0.5,
"opacity": 0.5,
},
)
m