From c71a2eda334a04c9bb9262c87da548001a9dd0f2 Mon Sep 17 00:00:00 2001 From: mattbk Date: Sat, 7 Mar 2026 10:27:59 -0600 Subject: [PATCH] Clean up the spot query and the map. --- src/farpn-map.R | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/farpn-map.R b/src/farpn-map.R index a71580d..55882bd 100644 --- a/src/farpn-map.R +++ b/src/farpn-map.R @@ -7,17 +7,22 @@ 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" -# Get the spots +# 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, dx_longitude, dx_latitude), as.numeric)) # 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) + + + \ No newline at end of file