Conversation
giswqs
commented
Nov 14, 2025

for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Pull Request Overview
This PR adds a new utility function generate_latlon_grid to generate rectangular lat/lon grids over a specified extent. The function creates a GeoDataFrame with polygon geometries representing grid cells.
Key changes:
- New
generate_latlon_gridfunction inleafmap/common.pythat creates a grid of polygons based on extent and cell size parameters - Function exported from
leafmap/maplibregl.pyfor convenient access - Example notebook demonstrating grid generation and visualization on a map
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| leafmap/common.py | Implements the core generate_latlon_grid function with extent, cell size, and CRS parameters |
| leafmap/maplibregl.py | Imports and exports the new function for use in the MapLibre module |
| docs/maplibre/latlon_grid.ipynb | Provides a working example showing grid generation over the continental US |
| docs/maplibre/overview.md | Adds a section documenting the new grid generation feature |
| mkdocs.yml | Registers the new notebook in the documentation navigation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def generate_latlon_grid(extent, dx=0.1, dy=0.1, crs="EPSG:4326", output=None): | ||
| """ | ||
| Generate a rectangular lat/lon grid as polygons over a given extent. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| extent : tuple | ||
| (xmin, ymin, xmax, ymax) in degrees, e.g. (-180, -60, 180, 85) | ||
| dx : float | ||
| Longitude interval in degrees (cell width) | ||
| dy : float | ||
| Latitude interval in degrees (cell height) | ||
| crs : str or dict | ||
| Coordinate reference system for the output GeoDataFrame | ||
|
|
||
| Returns | ||
| ------- | ||
| GeoDataFrame | ||
| Columns: id, lon_min, lat_min, lon_max, lat_max, geometry | ||
| """ |
There was a problem hiding this comment.
The docstring is missing documentation for the output parameter. Add a parameter entry for output : str, optional describing it as the path to save the output file (defaults to None).
| if output is not None: | ||
| gdf.to_file(output) | ||
|
|
||
| return gdf |
There was a problem hiding this comment.
The function always returns the GeoDataFrame regardless of whether output is set. This is inconsistent with similar functions in the codebase like vector_set_crs (line 10874-10877) and coords_to_vector (line 10937-10940) which return the GeoDataFrame only when output is None. Consider either maintaining consistency with other functions by conditionally returning, or documenting that the function always returns the GeoDataFrame in addition to saving.
| return gdf | |
| if output is None: | |
| return gdf |
|
🚀 Deployed on https://691749e2edf05d6ea91391da--opengeos.netlify.app |
* Add generate_latlon_grid function * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>