@@ -549,7 +549,7 @@ const geowarp = function geowarp({
549549 let forward_turbocharged , inverse_turbocharged ;
550550 if ( turbo ) {
551551 if ( forward ) {
552- out_bbox_in_srs ??= reprojectBoundingBox ( out_bbox , inverse , { density : 100 } ) ;
552+ out_bbox_in_srs ??= reprojectBoundingBox ( out_bbox , inverse , { density : 100 , nan_strategy : "skip" } ) ;
553553 intersect_bbox_in_srs ??= intersect ( in_bbox , out_bbox_in_srs ) ;
554554 forward_turbocharged = turbocharge ( {
555555 bbox : intersect_bbox_in_srs ,
@@ -583,8 +583,9 @@ const geowarp = function geowarp({
583583 if ( method === "near-vectorize" || method === "nearest-vectorize" ) {
584584 if ( debug_level >= 2 ) console . log ( '[geowarp] choosing between "near" and "vectorize" for best speed' ) ;
585585
586- out_bbox_in_srs ??= same_srs ? out_bbox : reprojectBoundingBox ( out_bbox , inverse , { density : 100 } ) ;
586+ out_bbox_in_srs ??= same_srs ? out_bbox : reprojectBoundingBox ( out_bbox , inverse , { density : 100 , nan_strategy : "skip" } ) ;
587587
588+ // average of how large each output pixel is in the input spatial reference system
588589 out_sample_height_in_srs = ( out_bbox_in_srs [ 3 ] - out_bbox_in_srs [ 1 ] ) / out_height_in_samples ;
589590 out_sample_width_in_srs = ( out_bbox_in_srs [ 2 ] - out_bbox_in_srs [ 0 ] ) / out_width_in_samples ;
590591
@@ -613,7 +614,8 @@ const geowarp = function geowarp({
613614 // const [cfwd, clear_forward_cache] = cacheFunction(fwd);
614615
615616 // reproject bounding box of output (e.g. a tile) into the spatial reference system of the input data
616- out_bbox_in_srs ??= same_srs ? out_bbox : reprojectBoundingBox ( out_bbox , inverse , { density : 100 } ) ;
617+ // setting nan_strategy to skip trims the box in case the output bbox extends over the bounds of the input projection
618+ out_bbox_in_srs ??= same_srs ? out_bbox : reprojectBoundingBox ( out_bbox , inverse , { density : 100 , nan_strategy : "skip" } ) ;
617619 let [ left , bottom , right , top ] = out_bbox_in_srs ;
618620
619621 out_sample_height_in_srs ??= ( top - bottom ) / out_height_in_samples ;
@@ -888,11 +890,18 @@ const geowarp = function geowarp({
888890 // combing srs reprojection and srs-to-image mapping, ensures that bounding box corners
889891 // are reprojected fully before calculating containing bbox
890892 // (prevents drift in increasing bbox twice if image is warped)
891- const [ leftInRasterPixels , topInRasterPixels , rightInRasterPixels , bottomInRasterPixels ] = reprojectBoundingBox (
892- [ left , bottom , right , top ] ,
893- out_srs_pt_to_in_img_pt
894- ) ;
895-
893+ let leftInRasterPixels , topInRasterPixels , rightInRasterPixels , bottomInRasterPixels ;
894+ try {
895+ [ leftInRasterPixels , topInRasterPixels , rightInRasterPixels , bottomInRasterPixels ] = reprojectBoundingBox (
896+ [ left , bottom , right , top ] ,
897+ out_srs_pt_to_in_img_pt ,
898+ { nan_strategy : "throw" }
899+ ) ;
900+ } catch ( error ) {
901+ // if only one pixel (or row of pixels) extends over the edge of the projection's bounds, we probably don't want to fail the whole thing
902+ // an example would be warping the globe from 3857 to 4326
903+ continue ;
904+ }
896905 if ( debug_level >= 4 ) console . log ( "[geowarp] leftInRasterPixels:" , leftInRasterPixels ) ;
897906 if ( debug_level >= 4 ) console . log ( "[geowarp] rightInRasterPixels:" , rightInRasterPixels ) ;
898907 if ( debug_level >= 4 ) console . log ( "[geowarp] topInRasterPixels:" , topInRasterPixels ) ;
0 commit comments