Skip to content

Add generate_latlon_grid function#1262

Merged
giswqs merged 2 commits into
masterfrom
grid
Nov 14, 2025
Merged

Add generate_latlon_grid function#1262
giswqs merged 2 commits into
masterfrom
grid

Conversation

@giswqs

@giswqs giswqs commented Nov 14, 2025

Copy link
Copy Markdown
Member

Copilot AI review requested due to automatic review settings November 14, 2025 15:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_grid function in leafmap/common.py that creates a grid of polygons based on extent and cell size parameters
  • Function exported from leafmap/maplibregl.py for 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.

Comment thread leafmap/common.py
Comment on lines +19855 to +19874
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
"""

Copilot AI Nov 14, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Comment thread leafmap/common.py
if output is not None:
gdf.to_file(output)

return gdf

Copilot AI Nov 14, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
return gdf
if output is None:
return gdf

Copilot uses AI. Check for mistakes.
@github-actions

github-actions Bot commented Nov 14, 2025

Copy link
Copy Markdown

@giswqs giswqs merged commit 65f3d86 into master Nov 14, 2025
15 checks passed
@giswqs giswqs deleted the grid branch November 14, 2025 15:23
@github-actions github-actions Bot temporarily deployed to pull request November 14, 2025 15:25 Inactive
giswqs added a commit that referenced this pull request Dec 6, 2025
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants