Could someone suggest a way to adding 1KM wide grids/graticules to folium map? The folium example here uses lat/longitude intervals but doesn't render the grid.
import folium
# Bangkok coordinates
center_lat = 13.7563
center_lon = 100.4911
m = folium.Map(location=[center_lat, center_lon], zoom_start=11)
# Interval in degrees (1 kilometer ≈ 0.00694444 degrees)
interval = 0.00694444
# Create grid lines
grid_lines = []
# East-west lines (from -90 to 90 latitude)
for lat in range(-90, 91, int(1 / interval)):
west_point = (-180, lat)
east_point = (180, lat)
grid_lines.append(folium.PolyLine([west_point, east_point], color="black", weight=0.5, opacity=0.5))
# North-south lines (from -180 to 180 longitude)
for lon in range(-180, 181, int(1 / interval)):
south_point = (lon, -90)
north_point = (lon, 90)
grid_lines.append(folium.PolyLine([south_point, north_point], color="black", weight=0.5, opacity=0.5))
# Add lines to the map
for line in grid_lines:
line.add_to(m)
# Display the map
m
Your grid does actually render on the map but it's not as you expect because you're using
rangeinstead ofnumpy.arange. Also you're inverting the locations of eachPolyLinein your two for-loops. So, here is one possible fix :NB : It took ~40 seconds for the map to display on my JupyterLab and the navigation is relatively cumbersome/slow. So, if performance is a concern, you may need to reduce the interval :
Output (
m):