Skip to content

docs: Better use of computational region in NumPy examples#6315

Draft
wenzeslaus wants to merge 3 commits intoOSGeo:mainfrom
wenzeslaus:better-region-examples-with-numpy
Draft

docs: Better use of computational region in NumPy examples#6315
wenzeslaus wants to merge 3 commits intoOSGeo:mainfrom
wenzeslaus:better-region-examples-with-numpy

Conversation

@wenzeslaus
Copy link
Copy Markdown
Member

This improves how computational region is handled in all NumPy examples. Specifically, it creates variables for number of rows and columns and only then sets the computational region to be clear what is happening.

tools = Tools(session=session)
rows = elevation.shape[0]
cols = elevation.shape[1]
tools.g_region(s=0, n=rows, w=0, e=cols, res=1)

This still has limited applicability as it works without a geographical context. Notably, NumPy arrays are generally not georeferenced, so XY project is applicable and I added creation of the project to the example. Maybe this is enough for the basic example.

While this builds on #6313 (and currently contains also the changes from there), I'm opening a separate PR to allow for a separate discussion on how to handle this.

The main interface doc for Python now shows how GRASS tools are used with arrays through grass.tools before showing direct conversions between GRASS rasters and NumPy arrays with grass.script.array.
@github-actions github-actions bot added Python Related code is in Python libraries docs markdown Related to markdown, markdown files labels Sep 5, 2025
Comment thread doc/python_intro.md
tools = Tools()
tools.g_region(n=elevation_array.shape[0], s=0,
e=elevation_array.shape[1], w=0, res=1)
gs.create_project("xy_project")
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.

Missing comment here.

@wenzeslaus wenzeslaus added this to the 8.5.0 milestone Oct 6, 2025
@echoix echoix added the conflicts/needs rebase Rebase to or merge with the latest base branch is needed label Oct 7, 2025
@nilason nilason modified the milestones: 8.5.0, 8.6.0 Feb 12, 2026
@neteler neteler marked this pull request as ready for review February 12, 2026 09:59
@neteler
Copy link
Copy Markdown
Member

neteler commented Feb 12, 2026

ops, wrong button

@neteler neteler marked this pull request as draft February 12, 2026 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conflicts/needs rebase Rebase to or merge with the latest base branch is needed docs libraries markdown Related to markdown, markdown files Python Related code is in Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants