Skip to content

Instantly share code, notes, and snippets.

@mdsumner
Created December 11, 2025 05:32
Show Gist options
  • Select an option

  • Save mdsumner/f9f72870bcb1d25b74e2b6a7307f8b74 to your computer and use it in GitHub Desktop.

Select an option

Save mdsumner/f9f72870bcb1d25b74e2b6a7307f8b74 to your computer and use it in GitHub Desktop.
# that antimeridian thing, first in R

library(reproj)
## it's easy to get a range across the antimeridian
ex <- c(179.98, 180.12, -17, -16.8)

## this is fine
(utmex <- reproj_extent(ex, "EPSG:32760", source = "EPSG:4326"))

## but when we return (because we want to craft a &bbox=xmin,ymin,xmax,ymax)
## we actually get the "inside" of the interval we wanted
reproj_extent(utmex, "EPSG:4326", source = "EPSG:32760")

## it's easy at the ex stage, just craft two stac queries and bundle the assets:
## &bbox=179.98,-17,180,-16.8
## &bbox=-180,-17,-179.98,-16.8

## but, there's probably code that builds utmex somewhere in odc 
#(I do it in gh:mdsumner/scene, cheat with -1,-1,1,1 scaled i.e. 5000m, 
## local laea lon_0=180, reproj that to utmex, unproject - FAIL)
# so
src_srs <- PROJ::proj_crs_text("EPSG:32760", format = 1L)  ## projstring
reproj_extent(utmex, "EPSG:4326", source = sprintf("%s +over", src_srs))  ## BETTER


reticulate::use_python("~/workenv/bin/python")
library(reticulate)
geobox <- import("geobox")
geo <- import("odc.geo")

bb <- geo$BoundingBox(left = utmex[1], bottom = utmex[3], right = utmex[2], top = utmex[4], 
                crs = "EPSG:32760")

bb$to_crs("EPSG:4326")  # BAAD
#BoundingBox(left=-179.87784701098, bottom=-17.00213174776393, right=179.98003372328395, top=-16.794765954702655, crs=CRS('EPSG:4326'))

bb <- geo$BoundingBox(left = utmex[1], bottom = utmex[3], right = utmex[2], top = utmex[4], 
                      crs = sprintf("%s +over", src_srs))

bb$to_crs("EPSG:4326")  # GOOD
#BoundingBox(left=179.97680969742675, bottom=-17.00213174776393, right=180.1255338184529, top=-16.794765954702655, crs=CRS('EPSG:4326'))
@mdsumner
Copy link
Author

explore the complaint at opendatacube/odc-geo#208

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment