Skip to content

Commit

Permalink
Applied fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ben smith committed Jan 23, 2023
1 parent a08a28a commit 0a8f359
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ Imports:
sf,
lubridate,
tibble,
grid
grid,
s2
RoxygenNote: 7.2.2
Binary file removed ErrorPlot.png
Binary file not shown.
19 changes: 15 additions & 4 deletions R/plot_starmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ plot_starmap <- function(location,
# Data Transformation
flip <- matrix(c(-1, 0, 0, 1), 2, 2)

hemisphere <- st_sfc(st_point(c(lon, lat)), crs = 4326) %>%
hemisphere_1 <- s2::s2_buffer_cells(
s2::as_s2_geography(paste0("POINT(", lon, " ", lat, ")")),
distance = 1e7,
max_cells = 5000)

hemisphere_2 <- st_sfc(st_point(c(lon, lat)), crs = 4326) %>%
st_buffer(dist = 1e7) %>%
st_transform(crs = projString)

Expand All @@ -97,10 +102,16 @@ plot_starmap <- function(location,
capture.output(
constellation_lines_sf <- invisible(st_read(url1, stringsAsFactors = FALSE)) %>%
st_wrap_dateline(options = c("WRAPDATELINE=YES", "DATELINEOFFSET=360")) %>%
# Use s2 for the cut
st_as_s2() %>%
s2::s2_intersection(hemisphere_1) %>%
# Back to sf
st_as_sf() %>%
st_transform(crs = projString) %>%
st_intersection(hemisphere) %>%
filter(!is.na(st_is_valid(.))) %>%
mutate(geometry = geometry * flip)
mutate(geometry = geometry * flip) %>%
# Filter if empty, since the cut can produce empty geometries
filter(!st_is_empty(.))
)
)

Expand All @@ -112,7 +123,7 @@ plot_starmap <- function(location,
capture.output(
stars_sf <- st_read(url2,stringsAsFactors = FALSE) %>%
st_transform(crs = projString) %>%
st_intersection(hemisphere) %>%
st_intersection(hemisphere_2) %>%
mutate(geometry = geometry * flip)
)
)
Expand Down

0 comments on commit 0a8f359

Please sign in to comment.