Skip to content

Commit

Permalink
r.in.pdal addon: fix raster alignment
Browse files Browse the repository at this point in the history
- either use resolution or raster map/file reference (mutually exclusive)
- use PID in tmp name
- cleanup of raster file reference upon command termination
  • Loading branch information
neteler committed Oct 14, 2019
1 parent 71c95f7 commit 46fe987
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions grass7/raster/r.in.pdal/r.in.pdal.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#
# PURPOSE: Creates a raster map from LAS LiDAR points using univariate statistics and r.in.xyz.
#
# COPYRIGHT: (C) 2018 by mundialis and the GRASS Development Team
# COPYRIGHT: (C) 2018-2019 by mundialis and the GRASS Development Team
#
# This program is free software under the GNU General Public
# License (>=v2). Read the file COPYING that comes with GRASS
Expand Down Expand Up @@ -147,6 +147,11 @@
#% description: In scan mode, print using shell script style
#%end

#%rules
#% exclusive: raster_file, raster_reference
#% exclusive: resolution, raster_file, raster_reference
#%end

import os
import sys

Expand Down Expand Up @@ -385,7 +390,7 @@ def main():
footprint_to_vectormap(infile, 'tiles')

if raster_file:
raster_reference = 'img'
raster_reference = 'img' + str(os.getpid())
grass.run_command(
'r.external',
input=raster_file,
Expand All @@ -394,26 +399,26 @@ def main():
)
result = grass.find_file(name=raster_reference, element='raster')
if result[u'fullname'] == u'':
raster_reference = 'img.1'
# first pass: set region to extent of tiles while aligning pixel
# geometry to raster_reference
grass.run_command('g.region', vector='tiles', flags='p')
raster_reference = raster_reference + '.1'
# option 1: set region to extent of tiles while precisely aligning pixel
# geometry to raster_reference (including both raster_reference and raster_file)
if raster_reference:
grass.run_command(
'g.region',
vector='tiles',
flags='ap',
flags='g',
align=raster_reference
)
# second pass: change raster resolution to final resolution while best
# effort aligning to pixel geometry
grass.run_command(
else:
# option 2: change raster resolution to final resolution while best
# effort aligning to pixel geometry
grass.run_command(
'g.region',
vector='tiles',
flags='ap',
res=resolution
)

# generate PDAL pipeline
# . pdal pipline laz2json (STDOUT) | r.in.xyz
bn = os.path.basename(infile)
infile_format = bn.split('.')[-1]
Expand Down Expand Up @@ -523,6 +528,14 @@ def main():
name='tiles',
quiet=True
)
if raster_file:
grass.run_command(
'g.remove',
flags='f',
type='raster',
pattern=raster_reference[:-1] + '*' ,
quiet=True
)
os.remove(tmp_file_json)
os.remove(tmp_xyz)
grass.message(_("Generating output raster map <%s>...") % outfile)
Expand Down

0 comments on commit 46fe987

Please sign in to comment.