Clean up the spot query and the map.
This commit is contained in:
@@ -7,8 +7,11 @@ library(ggplot2)
|
|||||||
library(geosphere)
|
library(geosphere)
|
||||||
library(rnaturalearth)
|
library(rnaturalearth)
|
||||||
|
|
||||||
# API URL
|
# API URL from the last 60 minutes
|
||||||
api_spots <- "http://[300:6f6a:b087:4dda::8]/api/v1/spots"
|
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
|
# Get the spots
|
||||||
spots_raw <- fromJSON(api_spots) %>% mutate(across(c(de_longitude, de_latitude,
|
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
|
# Convert to spatial
|
||||||
spots <- spots_raw %>% st_as_sf(coords = c("dx_longitude", "dx_latitude"),
|
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"),
|
spotters <- spots_raw %>% st_as_sf(coords = c("de_longitude", "de_latitude"),
|
||||||
crs = "EPSG:4326")
|
crs = "EPSG:4326")
|
||||||
# Make lines
|
# Make lines
|
||||||
@@ -41,7 +46,8 @@ great_circles <- bind_rows(great_circles_list,
|
|||||||
group_by(id) %>%
|
group_by(id) %>%
|
||||||
dplyr::summarize(do_union=FALSE) %>% # do_union=FALSE doesn't work as well
|
dplyr::summarize(do_union=FALSE) %>% # do_union=FALSE doesn't work as well
|
||||||
st_cast("LINESTRING") %>%
|
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),
|
station_bbox <- matrix(c(st_bbox(spots),
|
||||||
st_bbox(spotters)),
|
st_bbox(spotters)),
|
||||||
@@ -83,6 +89,21 @@ ggplot() +
|
|||||||
coord_sf(crs = "EPSG:4269",
|
coord_sf(crs = "EPSG:4269",
|
||||||
xlim = c(station_bbox$xmin, station_bbox$xmax),
|
xlim = c(station_bbox$xmin, station_bbox$xmax),
|
||||||
ylim = c(station_bbox$ymin, station_bbox$ymax)) +
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user