104 point style
In [1]:
Copied!
# %pip install -U leafmap
# %pip install -U leafmap
In [2]:
Copied!
from leafmap import leafmap
from leafmap import leafmap
Load GeoJSON data¶
In [3]:
Copied!
url = (
"https://github.com/opengeos/datasets/releases/download/world/world_cities.geojson"
)
url = (
"https://github.com/opengeos/datasets/releases/download/world/world_cities.geojson"
)
In [4]:
Copied!
m = leafmap.Map()
point_style = {
"radius": 5,
"color": "red",
"fillOpacity": 0.8,
"fillColor": "blue",
"weight": 3,
}
hover_style = {"fillColor": "yellow", "fillOpacity": 1.0}
m.add_geojson(
url, point_style=point_style, hover_style=hover_style, layer_name="World Cities"
)
m
m = leafmap.Map()
point_style = {
"radius": 5,
"color": "red",
"fillOpacity": 0.8,
"fillColor": "blue",
"weight": 3,
}
hover_style = {"fillColor": "yellow", "fillOpacity": 1.0}
m.add_geojson(
url, point_style=point_style, hover_style=hover_style, layer_name="World Cities"
)
m
Load GoeDataFrame¶
In [5]:
Copied!
import geopandas as gpd
import geopandas as gpd
In [6]:
Copied!
gdf = gpd.read_file(url)
gdf = gpd.read_file(url)
In [7]:
Copied!
m = leafmap.Map()
point_style = {
"radius": 5,
"color": "red",
"fillOpacity": 0.8,
"fillColor": "blue",
"weight": 3,
}
hover_style = {"fillColor": "yellow", "fillOpacity": 1.0}
m.add_gdf(
gdf, point_style=point_style, hover_style=hover_style, layer_name="World Cities"
)
m
m = leafmap.Map()
point_style = {
"radius": 5,
"color": "red",
"fillOpacity": 0.8,
"fillColor": "blue",
"weight": 3,
}
hover_style = {"fillColor": "yellow", "fillOpacity": 1.0}
m.add_gdf(
gdf, point_style=point_style, hover_style=hover_style, layer_name="World Cities"
)
m
Load Random Data¶
In [8]:
Copied!
import geopandas, pandas as pd, numpy as np
import random
import geopandas, pandas as pd, numpy as np
import random
In [9]:
Copied!
# 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
# 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