admin管理员组文章数量:1122846
When I run gdal2tiles
command in a subprocess, how can I follow the progress of the tiling process (from 0 to 1) ?
I tried using --verbose
parameter, but logs from gdal2tiles do not show progress line by line.
I tried using watchdog
and listen to the tiles generated by gdal2tiles
, but it does not seems to work.
Here's my code :
def run_command(command):
"""Run a shell command, handle errors and return its output."""
try:
result = subprocess.run(
command,
shell=True,
check=True,
text=True,
capture_output=True,
)
if result.stderr:
logger.warning(result.stderr)
return result.stdout
except subprocess.CalledProcessError as error:
error_message = (
f"Command '{error.cmd}' failed with return code {error.returncode}.\n"
f"Standard output:\n{error.stdout}\n"
f"Standard error:\n{error.stderr}\n"
)
raise RuntimeError(error_message) from error
def extract_tiles_for_geotiff(folder_images, path):
"""Use gdal2tiles to extract tile images."""
options = [
f"-p mercator",
"--resampling bilinear",
f"--processes={multiprocessing.cpu_count()}",
"--xyz"
]
def run_gdal2tiles(options):
options_str = " ".join(options)
command = f"gdal2tiles.py {options_str} {path} {folder_images}/"
run_command(command)
run_gdal2tiles(options)
本文标签: subprocessHow can we track progress of gdal2tiles command in pythonStack Overflow
版权声明:本文标题:subprocess - How can we track progress of `gdal2tiles` command in python? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736307363a1933283.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论