Skip to content

Instantly share code, notes, and snippets.

library(libs2)
# lifted from ggstereo (probably a better way to replicate this in s2)
# this is essentially generating a "cap" but with somewhat irregular
# coordinate spacing
great_circle <- function(x, y, z, length.out = 200) {
stopifnot(length(x) == 1, length(y) == 1, length(z) == 1)
# dot-product = 0 for orthogonality
library(libs2)
make_hemisphere <- function(lon = 0, detail = 100, epsilon = 1) {
lat_values <- seq(90, -90, length.out = detail)
coord_df <- unique(
data.frame(
lon = c(rep(lon - 90 + 1, detail), rep(lon + 90 - 1, detail)),
# .External2 is needed because the 'op' and 'args'
# SEXPs are what need to be passed to GErecordGraphicOperation()
test_point <- function() {
.External2(getNativeSymbolInfo("C_testPoint", "wk"))
}
# Needed for Rcpp to pick up on "C_testPoint"
test_point2 <- function() {
.Call("C_testPoint")
library(dplyr)
tibble(a = 1, x = 1:2) %>%
group_by(a, x) %>%
summarise(sum(x))
tibble(a = 1, x = 1:2) %>%
group_by(a, x) %>%
summarise(1:5)
nc_wkb <- geovctrs::geo_nc$geometry
nc_WKB <- nc_wkb
class(nc_WKB) <- "WKB"
nc_sfc <- sf::st_as_sfc(nc_WKB, EWKB = TRUE)
nc_sp <- sf::as_Spatial(nc_sfc)
wkt_ptype <- geovctrs::geo_wkt()
wkb_ptype <- geovctrs::geo_wkb()
bench::mark(
wk:::wkb_translate_wkt(nc_wkb),
We can't make this file beautiful and searchable because it's too large.
lon,lat,temp_f,dbt_ft,dbt_m,speed_kts,heading_de
-122.981941699999993,50.108469999999997,66.920000000000002,25.360841669999999,7.729984293000000,0.000000000000000,0.000000000000000
-122.981906699999996,50.108418329999999,66.920000000000002,25.524883330000002,7.779984191000000,0.000000000000000,0.000000000000000
-122.981911699999998,50.108379999999997,66.920000000000002,24.310974999999999,7.409984943000000,0.000000000000000,0.000000000000000
-122.981883300000007,50.108361670000001,66.920000000000002,23.818850000000001,7.259985248000000,1.900000000000000,75.900000000000006
-122.981871699999999,50.108339999999998,66.920000000000002,23.392341670000000,7.129985512000000,0.000000000000000,75.900000000000006
-122.981876700000001,50.108291670000000,66.920000000000002,21.555074999999999,6.569986650000000,0.000000000000000,75.900000000000006
-122.981848299999996,50.108186670000002,66.920000000000002,21.292608330000000,6.489986812000000,0.500000000000000,170.500000000000000
-122.981848299999996,50.108159999999998,66.920
library(tidyr)
# remotes::install_github("tidyverse/dplyr")
library(dplyr)
# remotes::install_github("paleolimbot/geovctrs")
library(geovctrs)
nc <- geo_nc %>% select(NAME, geometry)
nc
# explode coordinates
Rcpp::sourceCpp(
code = '
#include "geovctrs/geos-operator.hpp"
// [[Rcpp::depends(geovctrs)]]
class BufferOp: public UnaryGeometryOperator {
GEOSGeometry* operateNext(GEOSContextHandle_t context, GEOSGeometry* geometry, size_t i) {
// width, segments per quandrant
return GEOSBuffer_r(context, geometry, 2, 30);
library(sf)
library(geovctrs)
nc_sf <- read_sf(system.file("shape/nc.shp", package = "sf"))
nc_sfc <- st_geometry(nc_sf)
nc_geo <- geo_nc
nc_wkb <- geo_nc$geometry
nc_wkt <- as_geo_wkt(nc_wkb)
# bbox
library(furrr)
slow_func <- function(x) {
Sys.sleep(0.1)
x
}
bench::mark(lapply(1:10, slow_func))
# use this!