grass.jupyter: use the Tools API in reproject_latlon#7489
grass.jupyter: use the Tools API in reproject_latlon#7489Valyrian-Code wants to merge 2 commits into
Conversation
reproject_latlon ran m.proj via gs.start_command with manual PIPE handling, communicate(), and encode/decode. Use grass.tools.Tools with an io.StringIO input instead, matching get_region and get_location_proj_string in the same module. The output is unchanged for valid input; Tools additionally raises on a non-zero m.proj exit instead of failing later while parsing empty output.
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Refactors reproject_latlon() to run m.proj via the Tools().m_proj() wrapper using an in-memory stream instead of manually managing a subprocess.
Changes:
- Adds
StringIOimport to support passing coordinates via an in-memory text stream. - Replaces
gs.start_command(...).communicate()subprocess handling with aTools().m_proj(...).textcall.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I took a look at this and don't think it makes sense to change right now.
If batch reprojection ever becomes a real use case, the more effective optimization would be to send multiple points through a single
|
Description
reproject_latlonranm.projviags.start_commandwith manualPIPEhandling,
communicate(), andencode/decode. This rewrites it to usegrass.tools.Toolswith anio.StringIOinput, matchingget_regionandget_location_proj_stringin the same module.Motivation and context
grass.jupyter.utilsalready uses the Tools API inget_regionandget_location_proj_string. This bringsreproject_latlonin line with thatand removes the manual subprocess boilerplate, in the spirit of the
"rewrite functions using the new Tools API" direction for
grass.jupyter.The output is unchanged for valid input; Tools additionally raises on a
non-zero
m.projexit instead of failing later while parsing empty output.How has this been tested?
Verified locally that the rewritten function returns the same result as the
previous implementation, e.g. reprojecting
(lat 35.7, lon -78.6)intoEPSG:3358 yields
(645799.19, 216389.17, 0.0).ruff formatandruff checkare clean.
Types of changes