-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
st_warp (stars native) flips longitudes a full cycle
when longitudes are outside the target longitude bounds, they will be flipped a full cycle (360 degrees) in the direction of the closest bound. st_warp(..., use_gdal=TRUE) already did this. relevant for #256 #264 #269
- Loading branch information
Showing
2 changed files
with
9 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,6 +198,11 @@ colrow_from_xy = function(x, obj, NA_outside = FALSE) { | |
if (inherits(obj, "dimensions")) | ||
gt = get_geotransform(obj) | ||
|
||
if (isTRUE(st_is_longlat(st_crs(obj)))) { | ||
bb = st_bbox(obj) | ||
sign = ifelse(x[,1] < bb["xmin"], 1., ifelse(x[,1] > bb["xmax"], -1., 0.)) | ||
x[,1] = x[,1] + sign * 360. | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
mmyrte
|
||
} | ||
if (!any(is.na(gt))) { # have geotransform | ||
inv_gt = gdal_inv_geotransform(gt) | ||
if (any(is.na(inv_gt))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Apparently, this logic also wraps around even if there is no need to - see attached image of the situation, I'm trying to
st_crop
a stars object using an sf object. (violet: base raster, greyscale: cropped raster using QGIS, red: polygon in the middle of the US, nowhere near the dateline)I don't have time open a proper issue or even make a PR, sorry! Just jotting this down for the time being. For the record: