104 point style

Plotting point data with custom styles
Uncomment the following line to install leafmap if needed.
| # %pip install -U leafmap
|
| from leafmap import leafmap
|
Load GeoJSON data
| url = (
"https://github.com/opengeos/datasets/releases/download/world/world_cities.geojson"
)
|
1
2
3
4
5
6
7
8
9
10
11
12
13 | 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
1
2
3
4
5
6
7
8
9
10
11
12
13 | 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
| import geopandas, pandas as pd, numpy as np
import random
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 | # 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
|