tileManagerDemo1.py
1 ## @package python.demo.tileManagerDemo1
2 #
3 # @brief Demo script for a simple tiling with tileManager
4 #
5 # This script takes a number of ODM point clouds, tiles them into 2 rows and 2 columns, and creates a tile-wise DSM.
6 # Afterwards, the DSM is merged.
7 #
8 #
9 
10 import sys, os
11 import glob
12 
13 import pprint
14 
15 import opals
16 from opals import DSM, Algebra
17 
18 from opals.tools import tileManager
19 from opals.tools.doxygen import brief
20 from opals.tools.opalsargparse import PkgArgumentParser, Boolean, PathArgument
21 
22 @opals.main
23 def main(options, logger):
24  inp = [] #build list of input files (supporting wildcards)
25  for i in options.i:
26  inp.extend(glob.glob(str(i)))
27  if len(inp) == 0:
28  raise Exception("No input files found")
29 
30  inp_files = [{'files': inp, # List of Files (relative or full path, no */?)\n
31  'type': 'odm', # either odm or raster\n
32  'name': 'pointcloud', # any name that can be used as a dict key and a (windows) filename\n
33  'required': True}]
34  tiling_concept = '2r2c' # two rows, two columns
35  naming_concept = 'LL_6' # lower left coordinate, 6 digits, '_'-separated
36  tempdir = 'temp'
37 
38  # prepare tileManager
39  tm = tileManager.tileManager(logger, inp_files, tiling_concept, naming_concept, tempdir)
40  # get number of elements - this already cuts the files!
41  lix = len(tm)
42 
43  outfiles = []
44  # iterate over the tiles (no more cutting needed here)
45  for idx, tile in enumerate(tm):
46  print("Now processing tile %s/%s:" % (idx, lix))
47  pprint.pprint(tile)
48  outfile = os.path.join(tempdir, tile['tile_name'], 'dsm.tif')
49  # create a DSM
50  dsm = DSM.DSM(inFile=tile['pointcloud'],
51  outFile=outfile)
52  dsm.run()
53  outfiles.append(outfile)
54  # merge the output files into one mosaic
55  alg = Algebra.Algebra(inFile=outfiles,
56  outFile='mosaic.tif',
57  formula='first(r)',
58  limit='union')
59  alg.run()
60 
61 if __name__ == '__main__':
62  parser = PkgArgumentParser(usage="%(prog)s [options]\n" + brief(__doc__))
63  parser.add_argument("-i", type=PathArgument, help="input files", remarks='mandatory', nargs='*' )
64  options = parser.parse_args(sys.argv[1:])
65  main(options)