Skip to content

Instantly share code, notes, and snippets.

@mdsumner
Last active August 8, 2026 00:51
Show Gist options
  • Select an option

  • Save mdsumner/d4437a137647527a7686130608d198d8 to your computer and use it in GitHub Desktop.

Select an option

Save mdsumner/d4437a137647527a7686130608d198d8 to your computer and use it in GitHub Desktop.

https://github.com/hypertidy/bigcurve

{bigcurve} provides D3-level adaptive densifications at shape-segment level with bisecting line segments if required by the coordinate transformation, on a solid C++ basis, with {wk} for format wrangling and CRS transform, {wkpool} provides segments (with topology, future proof)

p <- geos::as_geos_geometry(terra::as.polygons(terra::rast(terra::ext(-150, 150, -85, 85), res = 15)))

tgt <- "+proj=laea"
tr <- PROJ::proj_trans_create(wk::wk_crs(p)$wkt, tgt)

plot(wk::wk_transform(p, tr))

x <- wk::wk_transform(wkpool::segments_to_wkb(bigcurve::densify(wkpool::establish_topology(p), tgt, source = wk::wk_crs(p)$wkt)), tr)
plot(x)
points(wk::wk_coords(x)[, c("x", "y"), drop = FALSE], pch = 19, cex = .5)

Created on 2026-08-07 with reprex v2.1.1

@mdsumner

mdsumner commented Aug 8, 2026

Copy link
Copy Markdown
Author

Finally we can now treat vector data in first-class topologically sane ways, vertices added where and when as needed, respecting the reality of the source data and the target coordinate system.

library(terra); library(wk); library(wkpool); library(geos); library(bigcurve)
#> terra 1.9.41
#> 
#> Attaching package: 'bigcurve'
#> The following object is masked from 'package:terra':
#> 
#>     densify
p <- as.polygons(rast(ext(-165, 165, -87, 87), res = c(15, 29)))
x <- bigcurve::densify(establish_topology(as_geos_geometry(p)), "+proj=stere")
op <- par(mfrow = c(2, 2))
plot(p); plot(as.points(p), add = TRUE); title("original")
plot(project(p, "+proj=stere")); title("terra project longlat")
plot(wk_coords(x)[, c("x", "y")]); title("bigcurve densified verts")
plot(project(vect(as_geos_geometry(x)), "+proj=stere"))

par(op)

library(terra); library(wk); library(wkpool); library(geos); library(bigcurve)
p <- as.polygons(rast(ext(-180, 180, -90, 90), res = c(15, 10)))

x <- bigcurve::densify(establish_topology(as_geos_geometry(p)), "+proj=laea")
y <- as_wkb(x)
plot(project(vect(as_geos_geometry(x)), "+proj=laea"))

plot(as.points(project(vect(as_geos_geometry(y)), "+proj=laea")))

plot(project(p, "+proj=laea")) ## old, default style, ugly
image

Created on 2026-08-08 with reprex v2.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment