(input, output, progress_callback=None, **opts)
| 89 | return Window(w.col_off - pad, w.row_off - pad, w.width + pad * 2, w.height + pad * 2) |
| 90 | |
| 91 | def export_raster(input, output, progress_callback=None, **opts): |
| 92 | now = time.time() |
| 93 | |
| 94 | current_progress = 0 |
| 95 | last_update = 0 |
| 96 | |
| 97 | def p(text, perc=0): |
| 98 | nonlocal current_progress |
| 99 | nonlocal last_update |
| 100 | |
| 101 | t = time.time() |
| 102 | current_progress += perc |
| 103 | |
| 104 | if t - last_update >= 1: |
| 105 | if progress_callback is not None: |
| 106 | progress_callback(text, current_progress) |
| 107 | last_update = t |
| 108 | |
| 109 | epsg = opts.get('epsg') |
| 110 | proj = opts.get('proj') |
| 111 | expression = opts.get('expression') |
| 112 | export_format = opts.get('format') |
| 113 | rescale = opts.get('rescale') |
| 114 | color_map = opts.get('color_map') |
| 115 | hillshade = opts.get('hillshade') |
| 116 | asset_type = opts.get('asset_type') |
| 117 | name = opts.get('name', 'raster') # KMZ specific |
| 118 | crop_wkt = opts.get('crop') |
| 119 | |
| 120 | dem = asset_type in ['dsm', 'dtm'] |
| 121 | path_base, _ = os.path.splitext(output) |
| 122 | resampling = 'nearest' |
| 123 | if dem: |
| 124 | resampling = 'bilinear' |
| 125 | |
| 126 | if crop_wkt is not None: |
| 127 | crop = GEOSGeometry(crop_wkt) |
| 128 | |
| 129 | crop_geojson = os.path.join(path_base, "crop.geojson") |
| 130 | raster_vrt = os.path.join(path_base, "raster.vrt") |
| 131 | |
| 132 | os.makedirs(os.path.dirname(crop_geojson), exist_ok=True) |
| 133 | with open(crop_geojson, "w", encoding="utf-8") as f: |
| 134 | f.write(crop.geojson) |
| 135 | |
| 136 | subprocess.check_output(["gdalwarp", "-cutline", crop_geojson, |
| 137 | '--config', 'GDALWARP_DENSIFY_CUTLINE', 'NO', |
| 138 | '-crop_to_cutline', '-of', 'VRT', '-r', resampling, |
| 139 | input, raster_vrt]) |
| 140 | |
| 141 | input = raster_vrt |
| 142 | |
| 143 | with COGReader(input) as ds_src: |
| 144 | src = ds_src.dataset |
| 145 | profile = src.meta.copy() |
| 146 | units = ds_src.dataset.units |
| 147 | win = Window(0, 0, src.width, src.height) |
| 148 |
nothing calls this directly
no test coverage detected