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

The grid spacing 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?

District Boundary

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

# District boundary 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 = []

2 Answers 2


One option would be to use Geopandas to create the grid, save a GeoJSON and then add to your map.

Have a look at this answer: Creating polygon grid using GeoPandas

You should be able to use your District Boundary to get the bounding box and then tweak the answer to create your grid. In the code of the answer:

points = gpd.read_file('points.shp')
xmin,ymin,xmax,ymax =  points.total_bounds

You already have a Geopandas DataFrame, so you should be able to use:

xmin,ymin,xmax,ymax = district_gdf.total_bounds

Which you can then move through the rest of the code.


For my solution, just create layer on QGIS or ArcGIS, It's really help, when you need add some property on grid to define or search some data where that's grid needed, and also if you have another data to intersecting or something like configuring each data to another data you have.

Here is site of my case, https://gis-app-digi.vercel.app/

  • Don't want to use any online platform. I want to do it in Python.
    – Jawi289p
    Apr 20 at 14:29
  • Not online, I mean you create manually using GIS Desktop App as your data layers in Folium Apr 25 at 8:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.