Clean up the spot query and the map.

This commit is contained in:
mattbk
2026-03-07 10:27:59 -06:00
parent 3d005fdc82
commit c71a2eda33

View File

@@ -7,8 +7,11 @@ library(ggplot2)
library(geosphere)
library(rnaturalearth)
# API URL
api_spots <- "http://[300:6f6a:b087:4dda::8]/api/v1/spots"
# API URL from the last 60 minutes
api_spots <- "http://[300:6f6a:b087:4dda::8]/api/v1/spots?max_age=3600"
# What time is it?
time <- `attr<-`(Sys.time(),"tzone","UTC")
# Get the spots
spots_raw <- fromJSON(api_spots) %>% mutate(across(c(de_longitude, de_latitude,
@@ -17,7 +20,9 @@ spots_raw <- fromJSON(api_spots) %>% mutate(across(c(de_longitude, de_latitude,
# Convert to spatial
spots <- spots_raw %>% st_as_sf(coords = c("dx_longitude", "dx_latitude"),
crs = "EPSG:4326")
crs = "EPSG:4326") %>%
mutate(color = band_color) %>%
select(c(-dx_flag, -de_flag))
spotters <- spots_raw %>% st_as_sf(coords = c("de_longitude", "de_latitude"),
crs = "EPSG:4326")
# Make lines
@@ -41,7 +46,8 @@ great_circles <- bind_rows(great_circles_list,
group_by(id) %>%
dplyr::summarize(do_union=FALSE) %>% # do_union=FALSE doesn't work as well
st_cast("LINESTRING") %>%
left_join(spots_raw, by = "id")
left_join(spots_raw, by = "id") %>%
mutate(color = band_color)
station_bbox <- matrix(c(st_bbox(spots),
st_bbox(spotters)),
@@ -83,6 +89,21 @@ ggplot() +
coord_sf(crs = "EPSG:4269",
xlim = c(station_bbox$xmin, station_bbox$xmax),
ylim = c(station_bbox$ymin, station_bbox$ymax)) +
theme_bw()
theme_bw() +
theme(#axis.title.x=element_blank(),
axis.title.y=element_blank()) +
labs(x = time)
ggsave("out/farpn_map_simple.png",
scale = 0.75)
# Export spatial data
st_write(spots, "out/spots.geojson", delete_dsn = T)
st_write(spotters, "out/spotters.geojson", delete_dsn = T)
st_write(great_circles, "out/great_circles.geojson", delete_dsn = T)
# Try to combine in one file
st_write(spots %>% bind_rows(spotters) %>% bind_rows(great_circles), "out/all.geojson", delete_dsn = T)