def make_pyramid(layer): """ Build a pyramid from a dataset. """ logger.info('Building pyramid for {}'.format(layer)) # Get paths pyramid_path = utils.get_pyramid_path(layer) dataset_path = utils.get_bathymetry_path(layer) # Create pyramid try: pyramid = rasters.Pyramid(path=pyramid_path, compression='DEFLATE') if pyramid.has_data(): logger.info('Pyramid has data for {}'.format(layer)) return dataset = gdal.Open(str(dataset_path)) logger.info("Pyramid path: %r" % pyramid_path) logger.info("Dataset path: %r" % dataset_path) # it defaults to rijksdriehoek (28992) bathy_srs = utils.get_bathymetry_srs(dataset_path) logger.info("Bathy srs: %r" % bathy_srs) dataset.SetProjection(projections.get_wkt(bathy_srs)) pyramid.add(dataset) except rasters.LockError: logger.info('Pyramid busy for {}'.format(layer)) return logger.info('Pyramid completed for {}'.format(layer))
def __init__(self, layer, reload=False): """ Init pyramid and monolith, and order creation if necessary. """ logging.debug('Initializing StaticData for {}'.format(layer)) errors = [] # Initialize pyramid for bathymetry pyramid_path = utils.get_pyramid_path(layer) pyramid = rasters.Pyramid(path=pyramid_path, compression='DEFLATE') # Order building if necessary if not pyramid.has_data(): tasks.make_pyramid.delay(layer) errors.append('Pyramid not ready yet, task submitted.') #raise ValueError('Pyramid not ready yet, task submitted.') # If all ok, set pyramid attribute. self.pyramid = pyramid # Initialize monolith for quad layout monolith_path = os.path.join(config.CACHE_DIR, layer, 'monolith') monolith = rasters.Monolith(path=monolith_path, compression='DEFLATE') # Order building if necessary # TODO: this can be initiated multiple times, that's unnecessary if not monolith.has_data(): tasks.make_monolith.delay(layer=layer) errors.append('Pyramid not ready yet, task submitted.') #raise ValueError('Monolith not ready yet, task submitted.') if errors: raise ValueError(' '.join(errors)) # If all ok, set monolith attribute. self.monolith = monolith
def main(): """ Check and build pyramids for all missing cache entries for available 3Di models. layer is Directory name of model. """ logger.info('Build pyramids for all models that do not have pyramids yet') for layer in os.listdir(config.DATA_DIR): if not os.path.isdir(os.path.join(config.DATA_DIR, layer)): continue pyramid_path = utils.get_pyramid_path(layer) pyramid = rasters.Pyramid(path=pyramid_path, compression='DEFLATE') if not pyramid.has_data(): logger.info('%s: No pyramid data, going to build.' % layer) tasks.make_pyramid.delay(layer) monolith_path = os.path.join(config.CACHE_DIR, layer, 'monolith') monolith = rasters.Monolith(path=monolith_path, compression='DEFLATE') if not monolith.has_data(): logger.info('%s: No monolith data, going to build.' % layer) tasks.make_monolith.delay(layer=layer)