Ejemplo n.º 1
0
def prepare_data(data_path, elev_gen_path, hill_gen_path):
    processes = []
    files = rasterutils.find_all_raster_files(data_path, known_elev_filetypes)
    for folder, group in groupby(files, operator.itemgetter(0)):
        #       Handle files in subfolder
        if folder:
            dirutils.clear_folder(os.path.join(elev_gen_path, folder))
            filename = os.path.join(elev_gen_path, folder, folder + ".vrtlist")
            with open(filename, 'a') as vrttemp:
                for f in list(group):
                    vrttemp.write(os.path.join(data_path, f[0], f[1]) + '\n')
                processes.append(Process(target=generate_virtual_and_overview, args=(
                    elev_gen_path, hill_gen_path, folder, folder, filename)))
#       Handle files directly under the data dir
        else:
            for g in list(group):
                filename = os.path.join(elev_gen_path, g[1] + ".vrtlist")
                with open(filename, 'w') as vrttemp:
                    vrttemp.write(os.path.join(data_path, g[1]) + '\n')
                processes.append(Process(target=generate_virtual_and_overview, args=(
                    elev_gen_path, hill_gen_path, None, os.path.splitext(g[1])[0], filename)))

    for p in processes:
        p.start()
    for p in processes:
        p.join()
Ejemplo n.º 2
0
def generate_aml_config(data_path, map_path, rule_set_path, resource_path, force_overwrite, debug):

    # Generate new map files
    dirutils.clear_folder(map_path)
    if debug:
        debug_string = "yes"
    else:
        debug_string = "no"
    color_tables_dir = os.path.join(rule_set_path, "color_tables")

    aml_type = ""
    for f in dirutils.get_all_files_with_suffix(data_path, [".000"]):
        for theme in os.listdir(color_tables_dir):
            bashCmd = ' '.join(["./process_aml_layers.sh", "aml_file=" + f, "rp=" + rule_set_path,
                                "ct=" + os.path.join(color_tables_dir, theme), "mp=" + map_path, "d=" + debug_string])
            output = check_output(bashCmd, shell=True)
            print(output)
            aml_type = output[-4:-1]

    if (aml_type):
        create_capability_files(data_path, os.path.join(resource_path, "templates"), os.path.join(rule_set_path, "color_tables"), os.path.join(
            resource_path, "aml_csv_files"), map_path, os.path.join(resource_path, "fonts", "fontset.lst"), aml_type, debug)

        dirutils.copy_and_replace(os.path.join(
            resource_path, "epsg"), os.path.join(map_path, "epsg"))
        dirutils.copy_and_replace(os.path.join(
            resource_path, "symbols"), os.path.join(map_path, "symbols"))
    else:
        print("There were no AML-files to be processed")
Ejemplo n.º 3
0
def generate_tif_config(data_path, map_path, debug):
    main_template_path = os.path.join(resource_dir, "templates",
                                      "geotif_templates", "geotif_main.map")
    layer_template_path = os.path.join(resource_dir, "templates",
                                       "geotif_templates", "geotif_layer.map")

    if not os.path.isfile(main_template_path) or \
       not os.path.isfile(layer_template_path):
        print("No templates found for this data type")
        sys.exit(1)

    main_template = Template(open(main_template_path, 'r').read())
    layer_template = Template(open(layer_template_path, 'r').read())

    dirutils.clear_folder(map_path)

    rasterfiles = rasterutils.find_all_raster_files(data_path, tif_suffix)

    layers = create_layers(layer_template, data_path, rasterfiles)
    # Write output map file if layers is non-empty
    if layers:
        extent = rasterutils.calculate_total_extent(data_path, rasterfiles,
                                                    output_srs)
        dictionary2 = create_main_dic(data_path, map_path, extent, output_srs,
                                      layers, debug)
        output = open(os.path.join(map_path, 'Geotif.map'), 'w')
        output.write(main_template.substitute(dictionary2))

        print("Generated:\n\t" + '\n\t'.join(os.listdir(map_path)))
    else:
        print("Error: No data found in " + data_path)
Ejemplo n.º 4
0
def generate_basechart_config(data_path, map_path, rule_set_path, resource_dir,
                              force_overwrite, debug, point_table, area_table,
                              displaycategory, chartsymbols):

    # Generate new map files
    dirutils.clear_folder(map_path)

    if chartsymbols:
        shapepath = data_path
        process_all_layers(data_path, map_path, rule_set_path, point_table,
                           area_table, displaycategory, chartsymbols)
    else:
        shapepath = None
        subprocess.call("./process_all_layers.sh data=" + data_path +
                        " target=" + map_path + " config=" + rule_set_path,
                        shell=True)

    fonts_path = os.path.join("./fonts", "fontset.lst")
    create_capability_files(os.path.join(resource_dir, "templates"),
                            os.path.join(rule_set_path, "color_tables"),
                            map_path, fonts_path, debug, shapepath)
    create_legend_files(os.path.join(resource_dir, "templates"),
                        os.path.join(rule_set_path, "color_tables"), map_path,
                        fonts_path, debug)

    dirutils.copy_and_replace(os.path.join(resource_dir, "epsg"),
                              os.path.join(map_path, "epsg"))
    dirutils.copy_and_replace(os.path.join(resource_dir, "symbols"),
                              os.path.join(map_path, "symbols"))
    dirutils.copy_and_replace(os.path.join(resource_dir, "fonts"),
                              os.path.join(map_path, "fonts"))
Ejemplo n.º 5
0
def create_color_rules(resource_dir, path, default_color_table):
    print("Overwrite color tables in " + path)
    choices = os.listdir(os.path.join(resource_dir, "chartsymbols"))
    if default_color_table:
        selection = index_containing_substring(choices, default_color_table)
    else:
        selection = ask_user("Select color definition: ", choices)
    print("Using color table " + choices[selection])
    path_to_selection = os.path.join(resource_dir, "chartsymbols",
                                     choices[selection])
    clear_folder(force_sub_dir(path, "color_tables"))
    bashCmd = ' '.join([
        "./convert_colors_xml2csv.sh", "input=" + path_to_selection,
        " target=" + path
    ])
    subprocess.call(bashCmd, shell=True)
Ejemplo n.º 6
0
def main():
    args = parse_arguments()

    source_path = os.path.abspath(args.src_dir[0])
    output_path = dirutils.force_sub_dir(os.path.abspath(args.out_dir[0]),
                                         "shape")
    dirutils.clear_folder(output_path)

    if not os.path.exists(source_path):
        print("That source folder does not exist")
        sys.exit(1)

    levels = get_levels_from_source(source_path)

    debug_val = "no"
    if args.debug:
        debug_val = "yes"

    processes = []

    os.chdir(script_dir)
    for level in levels:
        logstuff = []
        if args.log == "tmp":
            logstuff = [">>", get_logfile_name(), "2>&1"]
        elif args.log == "no":
            logstuff = ["> /dev/null 2>&1"]

        processes.append(
            mp.Process(target=process_level.process,
                       args=(level, source_path, output_path,
                             args.progress_addr)))

    # start
    for p in processes:
        p.start()

    # join
    for p in processes:
        p.join()
Ejemplo n.º 7
0
def generate_elevation_config(data_path, map_path, debug):
    elev_gen_path = os.path.normpath(
        os.path.join(data_path, elevation_folder_name))
    hill_gen_path = os.path.normpath(
        os.path.join(data_path, hillshade_folder_name))

    print("Clearing folder with generated files")
    dirutils.clear_folder(map_path)
    dirutils.clear_folder(elev_gen_path)
    dirutils.clear_folder(hill_gen_path)

    templates_dir = os.path.join(
        resource_dir, "templates", "elevation_templates")
    main_template_path = os.path.join(templates_dir, "elevation_main.map")
    layer_template_path = os.path.join(templates_dir, "elevation_layer.map")
    hillshade_main_template_path = os.path.join(
        templates_dir, "hillshade_main.map")
    hillshade_layer_template_path = os.path.join(
        templates_dir, "hillshade_layer.map")

    if not os.path.isfile(main_template_path) or \
       not os.path.isfile(layer_template_path) or \
       not os.path.isfile(hillshade_main_template_path) or \
       not os.path.isfile(hillshade_layer_template_path):
        print("No templates found for this data type")
        sys.exit(1)

    main_template = Template(open(main_template_path, 'r').read())
    layer_template = Template(open(layer_template_path, 'r').read())
    hillshade_main_template = Template(
        open(hillshade_main_template_path, 'r').read())
    hillshade_layer_template = Template(
        open(hillshade_layer_template_path, 'r').read())

#   Do data preparation
    prepare_data(data_path, elev_gen_path, hill_gen_path)

#   Create elevation map file
    create_map_file(elev_gen_path, map_path, 'Elevation.map', [
                    '.tif'], main_template, layer_template, debug)

#   Create hillshade map file
    create_map_file(hill_gen_path, map_path, 'Hillshade.map', [
                    '.tif'], hillshade_main_template, hillshade_layer_template, debug)

    print("Generated:\n\t" + '\n\t'.join(os.listdir(map_path)))