How to create a custom grid on a Folium Map?

202 views Asked by At

I am quite new to Python and I need to create a custom grid with a specific cell size on a Folium map for a particular district. I have added the Polygon of district boundary on the folium map as shown in the image.

Each grid cell size should be set to 7 km in the x-direction and 5.5 km in the y-direction.

I have written the following code but I am stuck at that. Is there any library for creating the grids?

How can I do it?

Image is shown here

import folium
from shapely.geometry import Polygon
import geopandas as gpd

# District boundary polygon
district_polygon

# Create a GeoDataFrame with the polygon as the geometry column
district_gdf = gpd.GeoDataFrame(geometry=[district_polygon])

# Set the CRS for the entire GeoDataFrame
district_gdf.crs = {'init': 'epsg:4326'} 

# Defining the size of the grid cells in decimal degrees
grid_size_lat = 0.063 # roughly 7km at the equator
grid_size_lon = 0.0505 # roughly 5.5km at the equator

# Get the bounds of the district boundary polygon
minx, miny, maxx, maxy = district_gdf.total_bounds

# Create empty lists to store grid cell geometries
grid_cells = []
0

There are 0 answers