@@ -108,6 +108,7 @@ const geowarp = function geowarp({
108108 method = "median" ,
109109 read_bands = undefined , // which bands to read, used in conjunction with expr
110110 row_start = 0 , // which row in output data to start writing at
111+ row_end,
111112 expr = undefined , // band expression function
112113 round = false , // whether to round output
113114 theoretical_min, // minimum theoretical value (e.g., 0 for unsigned integer arrays)
@@ -289,9 +290,12 @@ const geowarp = function geowarp({
289290 } ) ;
290291 } ;
291292
293+ row_end ??= out_height ;
294+
292295 if ( method === "near" ) {
293296 const select = xdim . prepareSelect ( { data : in_data , layout : in_layout , sizes : in_sizes } ) ;
294- for ( let r = row_start ; r < out_height ; r ++ ) {
297+ const rmax = Math . min ( row_end , out_height ) ;
298+ for ( let r = row_start ; r < rmax ; r ++ ) {
295299 const y = out_ymax - out_pixel_height * r ;
296300 const segments = segments_by_row [ r ] ;
297301 for ( let iseg = 0 ; iseg < segments . length ; iseg ++ ) {
@@ -327,7 +331,8 @@ const geowarp = function geowarp({
327331 }
328332 } else if ( method === "bilinear" ) {
329333 const select = xdim . prepareSelect ( { data : in_data , layout : in_layout , sizes : in_sizes } ) ;
330- for ( let r = row_start ; r < out_height ; r ++ ) {
334+ const rmax = Math . min ( row_end , out_height ) ;
335+ for ( let r = row_start ; r < rmax ; r ++ ) {
331336 const y = out_ymax - out_pixel_height * r ;
332337 const segments = segments_by_row [ r ] ;
333338 for ( let iseg = 0 ; iseg < segments . length ; iseg ++ ) {
@@ -407,7 +412,8 @@ const geowarp = function geowarp({
407412 } else {
408413 let top , left , bottom , right ;
409414 bottom = out_ymax ;
410- for ( let r = row_start ; r < out_height ; r ++ ) {
415+ const rmax = Math . min ( row_end , out_height ) ;
416+ for ( let r = row_start ; r < rmax ; r ++ ) {
411417 top = bottom ;
412418 bottom = top - out_pixel_height ;
413419 const segments = segments_by_row [ r ] ;
0 commit comments