|
| 1 | +import os |
| 2 | +import sys |
| 3 | +import csv |
| 4 | +import getopt |
| 5 | + |
| 6 | +# import swig-wrapped RasterToolkit as rt |
| 7 | +from openudm import (RasterToolkit as rt) |
| 8 | + |
| 9 | + |
| 10 | +#def urban_fabric_generator_entrypoint(): |
| 11 | +def ufg_coverage_from_density_entrypoint(): |
| 12 | + """ |
| 13 | + Commandline entrypoint |
| 14 | + """ |
| 15 | + # default values for required input variables |
| 16 | + data_path_tiles = '' |
| 17 | + |
| 18 | + # get args list |
| 19 | + args = sys.argv[1:] |
| 20 | + |
| 21 | + # parse passed command line arguments |
| 22 | + try: |
| 23 | + # e.g. i = input file (colon indicates input expected) |
| 24 | + opts, args = getopt.getopt(args, "i:t:", ["input_data_path=", 'tile_data_path=']) |
| 25 | + except getopt.GetoptError as err: |
| 26 | + print(err) |
| 27 | + sys.exit(2) |
| 28 | + |
| 29 | + input_data_path = None |
| 30 | + tile_data_path = None |
| 31 | + |
| 32 | + # check each passed argument and assign values to variables |
| 33 | + for opt, arg in opts: |
| 34 | + print(opt) |
| 35 | + if opt in ("-i", "input_data_path="): |
| 36 | + input_data_path = arg |
| 37 | + elif opt in ("-t", 'tile_data_path='): |
| 38 | + tile_data_path = arg |
| 39 | + else: |
| 40 | + print('Un-recognised argument %s' %opt) |
| 41 | + sys.exit(2) |
| 42 | + |
| 43 | + if input_data_path is None: |
| 44 | + print('Input data path is required') |
| 45 | + sys.exit(2) |
| 46 | + |
| 47 | + ufg_coverage_from_density(dph_path=input_data_path, tiles_path=tile_data_path) |
| 48 | + |
| 49 | + |
| 50 | +#def urban_fabric_generator(dph_path, out_path=None, tiles_path=None): |
| 51 | +def ufg_coverage_from_density(dph_path, tiles_path=None): |
| 52 | + """ |
| 53 | + Runs a function to generate raster files containing urban coverage. |
| 54 | + Input data to be in the UDM data dir and output written to same directory. |
| 55 | +
|
| 56 | + Inputs: |
| 57 | + - dph_path: the path to the folder containing the dph raster |
| 58 | + - tiles_path : accepts a file path to a folder which contains the tiles to generate urban coverage. |
| 59 | + """ |
| 60 | + |
| 61 | + if tiles_path is None: |
| 62 | + tiles_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'Tiles')) |
| 63 | + |
| 64 | + print(tiles_path) |
| 65 | + |
| 66 | + # call wrapped C++ UFG function |
| 67 | + rt.UFGCoverageFromDensity(dph_path, tiles_path) |
| 68 | + |
| 69 | + return |
0 commit comments