From f919b510bcb0f41476d81860d7614be3b2dedc9e Mon Sep 17 00:00:00 2001 From: Valyrian-Code Date: Wed, 3 Jun 2026 11:54:36 +0530 Subject: [PATCH] grass.jupyter: use the Tools API in reproject_latlon 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. --- python/grass/jupyter/utils.py | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/python/grass/jupyter/utils.py b/python/grass/jupyter/utils.py index 95d4a0ce4d5..902ee3d6fcc 100644 --- a/python/grass/jupyter/utils.py +++ b/python/grass/jupyter/utils.py @@ -13,6 +13,7 @@ """Utility functions wrapping existing processes in a suitable way""" from collections.abc import Mapping +from io import StringIO import tempfile import json import os @@ -92,28 +93,9 @@ def reproject_latlon(coord): :param coord: coordinates given as tuple (latitude, longitude) :return: reprojected coordinates (returned as tuple) """ - # Prepare the input coordinate string coord_str = f"{coord[1]} {coord[0]}\n" - - # Start the m.proj command - proc = gs.start_command( - "m.proj", - input="-", - flags="i", - separator=",", - stdin=gs.PIPE, - stdout=gs.PIPE, - stderr=gs.PIPE, - ) - - proc.stdin.write(gs.encode(coord_str)) - proc.stdin.close() - proc.stdin = None - proj_output, _ = proc.communicate() - - output = gs.decode(proj_output).splitlines() - east, north, elev = map(float, output[0].split(",")) - + output = Tools().m_proj(input=StringIO(coord_str), flags="i", separator=",").text + east, north, elev = map(float, output.splitlines()[0].split(",")) return east, north, elev