GeoTIFF / georaster

Wrapper around Georeferenced Rasters like GeoTIFF and soon JPG and PNG that provides a standard interface
Apache License 2.0
84 stars 32 forks source link

maxs/mins/ranges calculation incorrect #74

Closed jcphill closed 1 year ago

jcphill commented 1 year ago

The following code from processResult() has two problems:

  1. Because max and min are declared outside the line 18 rasterIndex loop and not reset, later rasters cannot have a higher min or lower max than earlier rasters.
  2. Because of the else on line 29, if the raster data is sorted from largest to smallest with no repeats then max is never assigned, and if the first element is the true maximum then the next-largest value will be reported instead.

https://github.com/GeoTIFF/georaster/blob/ad4681a27e8bfb61b428242ce9a16c741a255098/src/parseData.js#L15-L37

For a test case, parseGeoraster([ [ [3, -3] ], [ [2, -2] ], [ [1, -1] ] ], metadata) will calculate maxs: [undefined, 2, 2], mins: [-3, -3, -3], ranges: [NaN, 5, 5]

DanielJDufour commented 1 year ago

Great catch! I'm working on a fix for this now!

DanielJDufour commented 1 year ago

This should be fixed now by the newest version of georaster I just published. Please reopen of course if this is still a problem for you.