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
Equivalent function to rgeos::gProject()
in sf
#2291
Comments
No, but I'd be happy to consider a PR (probably under a different name). |
For guidance, see: https://r-forge.r-project.org/scm/viewvc.php/pkg/R/rgeos_linearref.R?root=rgeos and https://r-forge.r-project.org/scm/viewvc.php/pkg/src/rgeos_linearref.c?root=rgeos. However, see https://paleolimbot.github.io/geos/reference/geos_project.html for:
or equivalently:
|
Thanks, that looks relatively trivial to implement. |
So this is implemented in a branch (for now): library(sf)
# Linking to GEOS 3.11.1, GDAL 3.6.4, PROJ 9.1.1; sf_use_s2() is TRUE
st_interpolate_line(st_as_sfc("LINESTRING (0 0, 1 1)"), 1)
# Geometry set for 1 feature
# Geometry type: POINT
# Dimension: XY
# Bounding box: xmin: 0.7071068 ymin: 0.7071068 xmax: 0.7071068 ymax: 0.7071068
# CRS: NA
# POINT (0.7071068 0.7071068)
st_interpolate_line(st_as_sfc("LINESTRING (0 0, 1 1)"), 1, TRUE)
# Geometry set for 1 feature
# Geometry type: POINT
# Dimension: XY
# Bounding box: xmin: 1 ymin: 1 xmax: 1 ymax: 1
# CRS: NA
# POINT (1 1)
st_project_point(st_as_sfc("LINESTRING (0 0, 10 10)"), st_as_sfc("POINT (5 5)"))
# [1] 7.071068
st_project_point(st_as_sfc("LINESTRING (0 0, 10 10)"), st_as_sfc("POINT (5 5)"), TRUE)
# [1] 0.5 |
Maybe we want to follow PostGIS' naming here? https://postgis.net/docs/ST_LineInterpolatePoint.html and https://postgis.net/docs/ST_LineLocatePoint.html |
Since we already have |
Thanks! It will be of great help! |
I settled on |
gProject()
returns the distance along geometry to point nearest the specified point and as far I know, there is no direct equivalent insf
. The functionsf::st_nearest_points()
however does part of the job, by returning the point on the line nearest to the specified point. The issue is that getting the distance likegProject
involves a lot of R code because we cannot split a line with a point due to floating point precision issues. Thus, does a native equivalent is planned?Below is how I am currently replicating
gProject()
:The text was updated successfully, but these errors were encountered: