MCPcopy Index your code
hub / github.com/WebODM/WebODM / export_raster

Function export_raster

app/raster_utils.py:91–470  ·  view source on GitHub ↗
(input, output, progress_callback=None, **opts)

Source from the content-addressed store, hash-verified

89 return Window(w.col_off - pad, w.row_off - pad, w.width + pad * 2, w.height + pad * 2)
90
91def 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

Callers

nothing calls this directly

Calls 15

hillshadeMethod · 0.95
LightSourceClass · 0.90
hsv_blendFunction · 0.90
compute_subwindowsFunction · 0.85
setFunction · 0.85
processFunction · 0.85
update_rgb_colorinterpFunction · 0.85
padded_windowFunction · 0.85
writeMethod · 0.80
pFunction · 0.70
getMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected