Describe the bug
When using read_stac() with local file paths (without file:// prefix), the link_open() function fails to resolve relative URLs correctly. The base URL stored in rstac:base_url remains as a local path, causing URL resolution errors.
To Reproduce
setwd("~/r+")
catalog_path <- "stac/collections/tc_original/collection.json"
col <- rstac::read_stac(catalog_path)
item_links <- rstac::links(col, rel == "item")
rstac::link_open(item_links[[1]])
Error:
Error in open.connection(con, "rb") : cannot open the connection
In addition:
Warning message:
In open.connection(con, "rb") :
cannot open file ':///~/r+/stac/collections/tc_original/items/...': No such file or directory
Additional context
The read_stac() function does not normalize local file paths to file:// URLs with absolute paths. When link_open() attempts to resolve relative URLs using the malformed base URL, it creates invalid file paths.
Local file paths should be automatically normalized to file:// URLs with absolute paths, allowing proper resolution of relative links in static catalogs.
Workaround
Users can manually provide the base_url with file:// prefix to link_open():
catalog_path <- "stac/collections/tc_original/collection.json"
col <- rstac::read_stac(catalog_path)
item_links <- rstac::links(col, rel == "item")
# Convert to absolute path with file:// prefix
base_url <- file.path(getwd(), catalog_path)
base_url <- paste0("file://", base_url)
rstac::link_open(item_links[[1]], base_url = base_url)
Describe the bug
When using
read_stac()with local file paths (withoutfile://prefix), thelink_open()function fails to resolve relative URLs correctly. The base URL stored inrstac:base_urlremains as a local path, causing URL resolution errors.To Reproduce
Error:
Additional context
The
read_stac()function does not normalize local file paths tofile://URLs with absolute paths. Whenlink_open()attempts to resolve relative URLs using the malformed base URL, it creates invalid file paths.Local file paths should be automatically normalized to
file://URLs with absolute paths, allowing proper resolution of relative links in static catalogs.Workaround
Users can manually provide the base_url with
file://prefix tolink_open():