Skip to content

Instantly share code, notes, and snippets.

@7yl4r
Last active July 24, 2020 19:54
Show Gist options
  • Save 7yl4r/d03f9617212db5efded1f8a0d34550d3 to your computer and use it in GitHub Desktop.
Save 7yl4r/d03f9617212db5efded1f8a0d34550d3 to your computer and use it in GitHub Desktop.
notes on how to generate overview mosaics

How to generate an overview mosaic

NOTE: GDAL > v2.0.0 is needed. Assumes running from a unix-like system with prereqs installed.

  1. put all the input files in a directory; name w/ extension .tif; cd to that dir
  2. build the vrt gdalbuildvrt -a_srs EPSG:4326 my_overview_file.vrt *tif
  3. edit the vrt xml to include your mosaic algorithm example:
        <VRTRasterBand dataType="Byte" band="1" subClass="VRTDerivedRasterBand">
            <PixelFunctionType>maximu</PixelFunctionType>
            <PixelFunctionLanguage>Python</PixelFunctionLanguage>
            <PixelFunctionCode><![CDATA[
    import numpy as np
    def maximu(in_ar, out_ar, xoff, yoff, xsize, ysize, raster_xsize,
                 raster_ysize, buf_radius, gt, **kwargs):
         np.round_(np.clip(np.max(in_ar, axis = 0),0,11),
            out = out_ar)
            ]]></PixelFunctionCode>
    • NOTE: the indention on the python code will probably copy and paste wrong and you will need to fix it manually
    • NOTE: the "0" and "11" usied in np.clip should be set to match your output bounds; 15, 31, 63, 127, 255 are other common values.
  4. enable python execution export GDAL_VRT_ENABLE_PYTHON=YES
  5. make an "overview" at scale 1:1: gdaladdo --config BIGTIFF_OVERVIEW YES -ro my_overview_file.vrt 1
  6. (optional) make additional changes to the result using gdal_edit
    • gdal_edit.py -a_srs EPSG:4326 my_overview_file.vrt.ovr
@7yl4r
Copy link
Author

7yl4r commented Dec 5, 2019

Running for swtx:

[tylar@tylar-pc circe_output]$ pwd
/mnt/ftp-ingest/circe_output

[tylar@tylar-pc circe_output]$ time gdalbuildvrt -a_srs EPSG:4326 swtx_2019-12-05.vrt swtx/*tif
0...10...20...30...40...50...60...70...80...90...100 - done.
real	0m0.672s
user	0m0.418s
sys	0m0.117s

[tylar@tylar-pc circe_output]$ atom swtx_2019-12-05.vrt 
[tylar@tylar-pc circe_output]$ atom swtx_2019-12-05.vrt 
[tylar@tylar-pc circe_output]$ export GDAL_VRT_ENABLE_PYTHON=YES
[tylar@tylar-pc circe_output]$ gdaladdo -ro swtx_2019-12-05.vrt 1
Warning: Overview with subsampling factor of 1 requested. This will copy the full resolution dataset in the overview!
0...10

@7yl4r
Copy link
Author

7yl4r commented Dec 9, 2019

Count() method for showing coverage available here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment