Skip to content

Commit

Permalink
grass.temporal.stds_import: Use pathlib Path.read_text and Path.write…
Browse files Browse the repository at this point in the history
…_text for proj string (OSGeo#4236)
  • Loading branch information
echoix authored and Mahesh1998 committed Sep 19, 2024
1 parent fecff55 commit 71ea941
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions python/grass/temporal/stds_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import os
import os.path
import tarfile
from pathlib import Path

import grass.script as gs
from grass.exceptions import CalledModuleError
Expand Down Expand Up @@ -302,16 +303,12 @@ def import_stds(
# from other programs than g.proj into
# new line format so that the grass file comparison function
# can be used to compare the projections
proj_name_tmp = temp_name + "_in_projection"
proj_file = open(proj_name, "r")
proj_content = proj_file.read()
proj_content = Path(proj_name).read_text()
proj_content = proj_content.replace(" +", "\n+")
proj_content = proj_content.replace("\t+", "\n+")
proj_file.close()

proj_file = open(proj_name_tmp, "w")
proj_file.write(proj_content)
proj_file.close()
proj_name_tmp = f"{temp_name}_in_projection"
Path(proj_name_tmp).write_text(proj_content)

p = gs.start_command("g.proj", flags="j", stdout=temp_file)
p.communicate()
Expand All @@ -336,7 +333,7 @@ def import_stds(
old_env = gs.gisenv()
if location:
try:
proj4_string = open(proj_file_name, "r").read()
proj4_string = Path(proj_file_name).read_text()
gs.create_location(
dbase=old_env["GISDBASE"], location=location, proj4=proj4_string
)
Expand Down

0 comments on commit 71ea941

Please sign in to comment.