New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
st_geod_segmentize #43
Comments
I've seen simplifiers, but no segmentizers yet! I'll keep an eye out. |
There's a reference to
|
That seems to be dealing with crossing edges, and I also cannot find any Although For segmentizing in S2 closest I have seen is S2Polyline::Interpolate(), but this wouldn't work for polygons, where it would also be needed. |
It's a bit more "manual", but one could also loop through edges and subdivide them...the |
Also, the blog post looks great! |
I'll have a closer look at how this is done in GEOS, but because a Alternatively, one could just work with the vertices (something like export to WKB, split edges, then re-import), although my sense is that working with the edges will result in cleaner code (even though it will take a while to figure out). |
As far as I can tell there's no segmentizer built-in...the code is mostly focused on removing as many vertices as possible whenever possible. The algorithm isn't complex...given a 0...1 vector interp_xyz <- matrix(
p2_xyz * rep(t_norm01, each = 3) +
p1_xyz * rep(1 - t_norm01, each = 3),
ncol = 3,
byrow = TRUE
) |
Going the other direction (projected -> spherical), this is where the |
This is now possible after #115. It doesn't make much sense to have an library(s2)
library(sf)
#> Warning: package 'sf' was built under R version 4.0.5
#> Linking to GEOS 3.8.1, GDAL 3.2.0, PROJ 7.2.0
tessellate_geod <- function(x, distance, radius = s2_earth_radius_meters()) {
coords_tes <- wk::wk_handle(
x,
s2_unprojection_filter(
s2_projection_filter(
wk::sfc_writer(),
tessellate_tol = distance / radius
)
)
)
coords_tes %>% st_set_crs(st_crs(x))
}
plot(tessellate_geod(sf::st_as_sfc("LINESTRING (0 0, 0 45, -60 45)"), 100)) Created on 2021-06-05 by the reprex package (v0.3.0) |
Trying to get this into sf; I'm not getting what I do wrong here: library(sf)
# Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
# Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
sf = st_sf(a=1, geom=st_sfc(st_linestring(rbind(c(0,0),c(1,1)))), crs = 4326)
library(s2)
tessellate_geod <- function(x, distance, radius = s2::s2_earth_radius_meters()) {
if (!requireNamespace("wk", quietly = TRUE))
stop("package wk not available: install it first?")
tol = if (units::ud_are_convertible(units(distance), "rad"))
units::set_units(distance, "rad", mode = "standard")
else
units::set_units(distance, "m", mode = "standard") / radius
coords_tes <- wk::wk_handle(
x,
s2::s2_unprojection_filter(
s2::s2_projection_filter(
wk::sfc_writer(),
tessellate_tol = units::drop_units(tol)
)
)
)
st_set_crs(coords_tes, st_crs(x))
}
(seg = tessellate_geod(sf, units::set_units(100, km)))
# Geometry set for 1 feature
# Geometry type: LINESTRING
# Dimension: XY
# Bounding box: xmin: 0 ymin: 0 xmax: 1 ymax: 1
# Geodetic CRS: WGS 84
# LINESTRING (0 0, 1 1) |
sorry for the noise, fixed. |
I now understand what this does, and it seems useful, for instance when plotting, but not a replacement / drop-in for |
In order to be able to drop dependency on
lwgeom
entirely,sf
needs a replacement oflwgeom::st_geod_segmentize
, to use insf::st_segmentize
for geographic data. S2Polylines have anInterpolate
method that could accomplish this. A tricky thing is thatsegmentize
adds points, at regular intervals bound by a maximum distance, to the existing points of a linestring.The text was updated successfully, but these errors were encountered: