Skip to content

Commit

Permalink
downloaad_and_import_tindex
Browse files Browse the repository at this point in the history
  • Loading branch information
anikaweinmann committed Feb 14, 2024
1 parent c57c100 commit b4b6da6
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/grass_gis_helpers/data_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
############################################################################

import glob
import gzip
import os
import shutil
from subprocess import PIPE
import wget

import grass.script as grass

Expand All @@ -32,6 +35,41 @@
from .raster import adjust_raster_resolution, rename_raster


def downloaad_and_import_tindex(tindex_url, output, download_dir):
"""Download and import tile index from url
Args:
tindex_url (str): URL of tile index
output (str): The output name for the tile index
download_dir (str): The directory where the data should be downloaded
"""
cur_dir = os.getcwd()
zip_name = os.path.basename(tindex_url)
tindex_gpkg = zip_name.replace(".gz", "")
try:
os.chdir(download_dir)
# download data
wget.download(tindex_url, zip_name, bar=None)

# unzip tindex
os.system(f"gunzip {zip_name}")

# import data
grass.run_command(
"v.import",
input=tindex_gpkg,
output=output,
extent="region",
overwrite=True,
quiet=True,
)
finally:
for rm_file in [zip_name, tindex_gpkg]:
if os.path.isfile(rm_file):
os.remove(rm_file)
os.chdir(cur_dir)


def import_local_raster_data(
aoi,
basename,
Expand Down

0 comments on commit b4b6da6

Please sign in to comment.