def create(dir_data, dir_temp, bounds=None): database = get_database(dir_data, bounds) file = __create_waypoint_file(database, dir_temp) list = FileList() list.add(file, True) return list
def __convert(dir_temp, input_file, rc): print('Converting terrain to JP2 format...') output_file = os.path.join(dir_temp, 'terrain.jp2') args = [ __cmd_geojasper, '-f', input_file, '-F', output_file, '-T', 'jp2', '-O', 'rate=1.0', '-O', 'tilewidth=256', '-O', 'tileheight=256' ] if not __use_world_file: args.extend([ '-O', 'xcsoar=1', '-O', 'lonmin=' + str(rc.left), '-O', 'lonmax=' + str(rc.right), '-O', 'latmax=' + str(rc.top), '-O', 'latmin=' + str(rc.bottom) ]) subprocess.check_call(args) output = FileList() output.add(output_file, False) world_file_tiff = os.path.join(dir_temp, "terrain.tfw") world_file = os.path.join(dir_temp, "terrain.j2w") if __use_world_file and os.path.exists(world_file_tiff): os.rename(world_file_tiff, world_file) output.add(world_file, True) return output
def create(bounds, arcseconds_per_pixel, downloader, dir_temp): # Make sure the tiles are available tiles = __retrieve_tiles(downloader, dir_temp, bounds) if len(tiles) < 1: return FileList() try: terrain_file = __create(dir_temp, tiles, arcseconds_per_pixel, bounds) return __convert(dir_temp, terrain_file, bounds) finally: __cleanup(dir_temp)
def create(bounds, downloader, dir_temp): topology = downloader.manifest()['topology'] layers = topology['layers'] datasets = topology['datasets'] files = FileList() index = [] for layer in layers: __create_layer(bounds, layer, datasets[layer['dataset']], downloader, dir_temp, files, index) files.add(__create_index_file(dir_temp, index), True) return files
def create(bounds, downloader, dir_temp, compressed=False, level_of_detail=3): topology = downloader.manifest()['topology'] layers = topology['layers'] datasets = topology['datasets'] files = FileList() index = [] for layer in layers: if layer['level_of_detail'] <= level_of_detail: __create_layer(bounds, layer, datasets[layer['dataset']], downloader, dir_temp, files, index, compressed) files.add(__create_index_file(dir_temp, index), True) return files
def __init__(self, dir_data, dir_temp): ''' Constructor of the MapGenerator class @param dir_data: Path of the data folder @param dir_temp: Path of the temporary folder ''' self.__downloader = Downloader(dir_data) self.__dir_temp = os.path.abspath(dir_temp) if not os.path.exists(self.__dir_temp): os.mkdir(self.__dir_temp) self.__bounds = None self.__files = FileList()
def __convert(dir_temp, input_file, rc): print('Converting terrain to JP2 format...') output_file = os.path.join(dir_temp, 'terrain.jp2') args = [ 'gdal_translate', '-of', 'JP2OpenJPEG', '-co', 'BLOCKXSIZE=256', '-co', 'BLOCKYSIZE=256', '-co', 'QUALITY=95', input_file, output_file ] subprocess.check_call(args) output = FileList() output.add(output_file, False) world_file_tiff = os.path.join(dir_temp, "terrain.tfw") world_file = os.path.join(dir_temp, "terrain.j2w") if __use_world_file and os.path.exists(world_file_tiff): os.rename(world_file_tiff, world_file) output.add(world_file, True) return output
def create(bounds, arcseconds_per_pixel, downloader, dir_temp): # calculate height and width (in pixels) of map from geo coordinates px = round((bounds.right - bounds.left) * 3600 / arcseconds_per_pixel) py = round((bounds.top - bounds.bottom) * 3600 / arcseconds_per_pixel) # round up so only full jpeg2000 tiles (256x256) are used # works around a bug in openjpeg 2.0.0 library px = (int(px / 256) + 1) * 256 py = (int(py / 256) + 1) * 256 # and back to geo coordinates for size bounds.right = bounds.left + (px * arcseconds_per_pixel / 3600) bounds.bottom = bounds.top - (py * arcseconds_per_pixel / 3600) # Make sure the tiles are available tiles = __retrieve_tiles(downloader, dir_temp, bounds) if len(tiles) < 1: return FileList() try: terrain_file = __create(dir_temp, tiles, arcseconds_per_pixel, bounds) return __convert(dir_temp, terrain_file, bounds) finally: __cleanup(dir_temp)