Skip to content

Commit

Permalink
r.import: pass extent to r.in.gdal (#291)
Browse files Browse the repository at this point in the history
* if extent=region in r.import, pass to r.in.gdal
* make use of TMP_REG_NAME
  • Loading branch information
mmacata authored and neteler committed Jan 22, 2020
1 parent 3a24c8c commit 1bbc756
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion scripts/r.import/r.import.py 100755 → 100644
Expand Up @@ -210,6 +210,7 @@ def main():
SRCGISRC = grass.tempfile()

TMPLOC = 'temp_import_location_' + str(os.getpid())
TMP_REG_NAME = 'vreg_tmp_' + str(os.getpid())

f = open(SRCGISRC, 'w')
f.write('MAPSET: PERMANENT\n')
Expand All @@ -232,6 +233,11 @@ def main():
except CalledModuleError:
grass.fatal(_("Unable to read GDAL dataset <%s>") % GDALdatasource)

# prepare to set region in temp location
if 'r' in region_flag:
tgtregion = TMP_REG_NAME
grass.run_command('v.in.region', **dict(output=tgtregion, flags='d'))

# switch to temp location
os.environ['GISRC'] = str(SRCGISRC)

Expand All @@ -248,6 +254,11 @@ def main():
memory=memory, flags='ak' + additional_flags)
if bands:
parameters['band'] = bands
if 'r' in region_flag:
grass.run_command('v.proj', **dict(location=tgtloc, mapset=tgtmapset,
input=tgtregion, output=tgtregion))
grass.run_command('g.region', **dict(vector=tgtregion))
parameters['flags'] = parameters['flags'] + region_flag
try:
grass.run_command('r.in.gdal', **parameters)
except CalledModuleError:
Expand All @@ -267,12 +278,18 @@ def main():
# switch to target location
os.environ['GISRC'] = str(TGTGISRC)

if 'r' in region_flag:
grass.run_command('g.remove', **dict(type="vector", flags="f",
name=tgtregion))

region = grass.region()

rflags = None
if flags['n']:
rflags = 'n'

vreg = TMP_REG_NAME

for outfile in outfiles:

n = region['n']
Expand Down Expand Up @@ -311,7 +328,6 @@ def main():
grass.run_command('g.region', n=n, s=s, e=e, w=w)

# v.in.region in tgt
vreg = TMP_REG_NAME = 'vreg_tmp_' + str(os.getpid())
grass.run_command('v.in.region', output=vreg, quiet=True)

grass.del_temp_region()
Expand Down

0 comments on commit 1bbc756

Please sign in to comment.