-
-
Notifications
You must be signed in to change notification settings - Fork 323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
r.import: Fix the -e flag for estimating the resolution without importing #4947
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -127,6 +127,7 @@ | |||||||||
SRCGISRC = None | ||||||||||
GISDBASE = None | ||||||||||
TMP_REG_NAME = None | ||||||||||
TMP_EST_FILE = None | ||||||||||
|
||||||||||
|
||||||||||
def cleanup(): | ||||||||||
|
@@ -145,8 +146,17 @@ | |||||||||
"g.remove", type="vector", name=TMP_REG_NAME, flags="f", quiet=True | ||||||||||
) | ||||||||||
|
||||||||||
if ( | ||||||||||
TMP_EST_FILE | ||||||||||
and gs.find_file( | ||||||||||
name=TMP_EST_FILE, element="cell" | ||||||||||
)["fullname"] | ||||||||||
): | ||||||||||
gs.run_command( | ||||||||||
"g.remove", type="raster", name=TMP_EST_FILE, flags="f", quiet=True | ||||||||||
) | ||||||||||
|
||||||||||
def is_projection_matching(GDALdatasource): | ||||||||||
"""Returns True if current location projection | ||||||||||
matches dataset projection, otherwise False""" | ||||||||||
try: | ||||||||||
|
@@ -157,7 +167,7 @@ | |||||||||
|
||||||||||
|
||||||||||
def main(): | ||||||||||
global TMPLOC, SRCGISRC, GISDBASE, TMP_REG_NAME | ||||||||||
global TMPLOC, SRCGISRC, GISDBASE, TMP_REG_NAME, TMP_EST_FILE | ||||||||||
|
||||||||||
GDALdatasource = options["input"] | ||||||||||
output = options["output"] | ||||||||||
|
@@ -168,6 +178,7 @@ | |||||||||
title = options["title"] | ||||||||||
if flags["e"] and not output: | ||||||||||
output = "rimport_tmp" # will be removed with the entire tmp location | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As @petrasovaa suggested,
Suggested change
|
||||||||||
TMP_EST_FILE = output | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you need something unique, see |
||||||||||
if options["resolution_value"]: | ||||||||||
if tgtres != "value": | ||||||||||
gs.fatal( | ||||||||||
|
@@ -206,6 +217,25 @@ | |||||||||
_("Input <%s> successfully imported without reprojection") | ||||||||||
% GDALdatasource | ||||||||||
) | ||||||||||
if flags["e"]: | ||||||||||
try: | ||||||||||
gs.message(_("Calculating estimted resolution...")) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
raster_info = gs.raster_info(output) | ||||||||||
if raster_info: | ||||||||||
estres = (raster_info["ewres"] + raster_info["nsres"])/2.0 | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ruff] reported by reviewdog 🐶
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be consistent with the original code: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be consistent with the original code,
Suggested change
|
||||||||||
gs.message( | ||||||||||
_("Estimated target resolution for input band <{out}>: {res}").format( | ||||||||||
out=output, res=estres | ||||||||||
) | ||||||||||
) | ||||||||||
else: | ||||||||||
gs.warning( | ||||||||||
_("Unable to estimate the resolution for the input raster") | ||||||||||
) | ||||||||||
return 0 | ||||||||||
except CalledModuleError: | ||||||||||
gs.fatal(_("Unable to import GDAL dataset <%s>") % GDALdatasource) | ||||||||||
|
||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for another try:
gs.run_command("r.in.gdal", **parameters)
...
return 0 # <-- delete this line
except
...
if flags["e"]:
...
return 0 |
||||||||||
return 0 | ||||||||||
except CalledModuleError: | ||||||||||
gs.fatal(_("Unable to import GDAL dataset <%s>") % GDALdatasource) | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[ruff] reported by reviewdog 🐶