Changeset b72d9c4 for src/common


Ignore:
Timestamp:
Apr 4, 2020, 12:38:21 PM (7 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
debian/bullseye, master
Children:
d0a651d
Parents:
5e16955
Message:

Patched gdal2tiles.py to support tile-size option. Change is merged upstream, but until it mades its way into distributions, we ship our own gdal2tiles.py

Location:
src/common/bin
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • src/common/bin/gdal2tiles-gnuboat.py

    r5e16955 rb72d9c4  
    22# -*- coding: utf-8 -*-
    33# ******************************************************************************
    4 #  $Id: gdal2tiles.py 17c3fa6fefeb3b305a27ff6ed1590145815d7ee3 2019-03-14 22:12:27 +0100 Even Rouault $
     4#  $Id: gdal2tiles.py fae3a65f16af509cf9e0dd16cd16858d8e49eb25 2019-03-12 15:23:57 -0700 Kevin Mehall $
    55#
    66# Project:  Google Summer of Code 2007, 2008 (http://code.google.com/soc/)
    … …  
    4141
    4242import math
    43 from multiprocessing import Pool
    44 from functools import partial
     43from multiprocessing import Pipe, Pool, Process, Manager
    4544import os
    4645import tempfile
    … …  
    6362    numpy_available = False
    6463
    65 __version__ = "$Id: gdal2tiles.py 17c3fa6fefeb3b305a27ff6ed1590145815d7ee3 2019-03-14 22:12:27 +0100 Even Rouault $"
     64__version__ = "$Id: gdal2tiles.py fae3a65f16af509cf9e0dd16cd16858d8e49eb25 2019-03-12 15:23:57 -0700 Kevin Mehall $"
    6665
    6766resampling_list = ('average', 'near', 'bilinear', 'cubic', 'cubicspline', 'lanczos', 'antialias')
    … …  
    703702            input_srs.ImportFromWkt(input_srs_wkt)
    704703
    705     input_srs.SetAxisMappingStrategy(osr.OAMS_TRADITIONAL_GIS_ORDER)
    706704    return input_srs, input_srs_wkt
    707705
    … …  
    712710    """
    713711    output_srs = osr.SpatialReference()
    714     output_srs.SetAxisMappingStrategy(osr.OAMS_TRADITIONAL_GIS_ORDER)
    715712
    716713    if options.profile == 'mercator':
    … …  
    896893    return dataset.RasterCount
    897894
    898 def create_base_tile(tile_job_info, tile_detail):
     895def create_base_tile(tile_job_info, tile_detail, queue=None):
    899896
    900897    dataBandsCount = tile_job_info.nb_data_bands
    … …  
    999996                ).encode('utf-8'))
    1000997
     998    if queue:
     999        queue.put("tile %s %s %s" % (tx, ty, tz))
    10011000
    10021001
    … …  
    15271526        srs4326 = osr.SpatialReference()
    15281527        srs4326.ImportFromEPSG(4326)
    1529         srs4326.SetAxisMappingStrategy(osr.OAMS_TRADITIONAL_GIS_ORDER)
    15301528        if self.out_srs and srs4326.ExportToProj4() == self.out_srs.ExportToProj4():
    15311529            self.kml = True
    … …  
    27522750
    27532751
    2754 def worker_tile_details(input_file, output_folder, options):
    2755       gdal2tiles = GDAL2Tiles(input_file, output_folder, options)
    2756       gdal2tiles.open_input()
    2757       gdal2tiles.generate_metadata()
    2758       tile_job_info, tile_details = gdal2tiles.generate_base_tiles()
    2759       return tile_job_info, tile_details
     2752def worker_tile_details(input_file, output_folder, options, send_pipe=None):
     2753    try:
     2754        gdal2tiles = GDAL2Tiles(input_file, output_folder, options)
     2755        gdal2tiles.open_input()
     2756        gdal2tiles.generate_metadata()
     2757        tile_job_info, tile_details = gdal2tiles.generate_base_tiles()
     2758        return_data = (tile_job_info, tile_details)
     2759        if send_pipe:
     2760            send_pipe.send(return_data)
     2761
     2762        return return_data
     2763    except Exception as e:
     2764        print("worker_tile_details failed ", str(e))
     2765
     2766
     2767def progress_printer_thread(queue, nb_jobs):
     2768    pb = ProgressBar(nb_jobs)
     2769    pb.start()
     2770    for _ in range(nb_jobs):
     2771        queue.get()
     2772        pb.log_progress()
     2773        queue.task_done()
     2774
    27602775
    27612776class ProgressBar(object):
    … …  
    27992814        srs4326 = osr.SpatialReference()
    28002815        srs4326.ImportFromEPSG(4326)
    2801         srs4326.SetAxisMappingStrategy(osr.OAMS_TRADITIONAL_GIS_ORDER)
    28022816        if tile_job_info.kml and tile_job_info.in_srs_wkt:
    28032817            in_srs = osr.SpatialReference()
    2804             in_srs.SetAxisMappingStrategy(osr.OAMS_TRADITIONAL_GIS_ORDER)
    28052818            in_srs.ImportFromWkt(tile_job_info.in_srs_wkt)
    28062819            ct = osr.CoordinateTransformation(in_srs, srs4326)
    … …  
    28632876    os.environ['GDAL_CACHEMAX'] = '%d' % int(gdal.GetCacheMax() / nb_processes)
    28642877
    2865     pool = Pool(processes=nb_processes)
     2878    (conf_receiver, conf_sender) = Pipe(False)
    28662879
    28672880    if options.verbose:
    28682881        print("Begin tiles details calc")
    2869 
    2870     conf, tile_details = pool.apply(worker_tile_details, [input_file, output_folder, options])
    2871 
     2882    p = Process(target=worker_tile_details,
     2883                args=[input_file, output_folder, options],
     2884                kwargs={"send_pipe": conf_sender})
     2885    p.start()
     2886    # Make sure to consume the queue before joining. If the payload is too big, it won't be put in
     2887    # one go in the queue and therefore the sending process will never finish, waiting for space in
     2888    # the queue to send data
     2889    conf, tile_details = conf_receiver.recv()
     2890    p.join()
    28722891    if options.verbose:
    28732892        print("Tiles details calc complete.")
    2874        
    2875     if not options.verbose and not options.quiet:
    2876         progress_bar = ProgressBar(len(tile_details))
    2877         progress_bar.start()
    2878 
     2893    # Have to create the Queue through a multiprocessing.Manager to get a Queue Proxy,
     2894    # otherwise you can't pass it as a param in the method invoked by the pool...
     2895    manager = Manager()
     2896    queue = manager.Queue()
     2897    pool = Pool(processes=nb_processes)
    28792898    # TODO: gbataille - check the confs for which each element is an array... one useless level?
    28802899    # TODO: gbataille - assign an ID to each job for print in verbose mode "ReadRaster Extent ..."
    2881     for _ in pool.imap_unordered(partial(create_base_tile, conf), tile_details, chunksize=128):
    2882         if not options.verbose and not options.quiet:
    2883             progress_bar.log_progress()
     2900    for tile_detail in tile_details:
     2901        pool.apply_async(create_base_tile, (conf, tile_detail), {"queue": queue})
     2902
     2903    if not options.verbose and not options.quiet:
     2904        p = Process(target=progress_printer_thread, args=[queue, len(tile_details)])
     2905        p.start()
    28842906
    28852907    pool.close()
    28862908    pool.join()     # Jobs finished
     2909    if not options.verbose and not options.quiet:
     2910        p.join()        # Traces done
    28872911
    28882912    create_overview_tiles(conf, output_folder, options)
Note: See TracChangeset for help on using the changeset viewer.