USF-IMARS / wv-land-cover

:earth_americas: Processing scripts for decision-tree land use classification on worldview 2 imagery
5 stars 5 forks source link

mosaic using "count()" method #24

Closed 7yl4r closed 4 years ago

7yl4r commented 4 years ago

mosaic of the count of images covering this area

does gdal have a count method?

7yl4r commented 4 years ago

does gdal have a count method?

No. We would need to use gdal_calc. Seems like a "gdal fn reduce" implmentation is needed for both this & #17

7yl4r commented 4 years ago

A reduce implementation for count would look something like:

reduce( lambda a,b: b+int(a > 0), list_of_images)

for #17 it might be like:

reduce( max, list_of_images)
7yl4r commented 4 years ago

Done using vrt methods described on #17

  <VRTRasterBand dataType="Byte" band="1" subClass="VRTDerivedRasterBand">
    <PixelFunctionType>count</PixelFunctionType>
    <PixelFunctionLanguage>Python</PixelFunctionLanguage>
    <PixelFunctionCode><![CDATA[
import numpy as np
def count(in_ar, out_ar, xoff, yoff, xsize, ysize, raster_xsize,
                   raster_ysize, buf_radius, gt, **kwargs):
    np.clip(np.count_nonzero(in_ar, axis = 0),0,15, out = out_ar)
]]>
    </PixelFunctionCode>

edit: changed clip 255 to 15

7yl4r commented 4 years ago

Tested w/ clip 255 on my pc:

[tylar@tylar-pc circe_output]$ time gdaladdo -ro swtx_2019-12-05_coverage.vrt 10
0...10...20...30...40...50...60...70...80...90...100 - done.

real    226m20.006s
user    203m30.257s
sys 21m17.668s