2

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

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 = []

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Jawi289p
  • 33
  • 4

2 Answers2

0

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.

Keagan Allan
  • 3,706
  • 1
  • 15
  • 25
-1

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/

Kadir Şahbaz
  • 76,800
  • 56
  • 247
  • 389