Description Usage Arguments Examples
View source: R/anem_geoprocessing.R
Get nearest point on
1 | get_nearest_point_on_line(loc, m, b)
|
loc |
Points as |
m |
Slope of the line |
b |
Intercept of the line (if |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | ## Not run:
bounds <- data.frame(bound_type=c("CH","NF","NF","NF"),
m=c(Inf,0,Inf,0),b=c(0,0,100,100)) %>% define_bounds()
loc <- c(150,150)
get_nearest_point_on_line(loc,bounds[1,]$m,bounds[1,]$b)
bounds <- data.frame(bound_type=c("CH","NF","NF","NF"),
m=c(-2,0.5,-2,0.5),b=c(0,0,100,20)) %>% define_bounds()
loc <- data.frame(x=c(-100,0,100),y=c(-150,0,150))
nearest <- get_nearest_point_on_line(loc,bounds[1,]$m,bounds[1,]$b)
ggplot() +
geom_segment(data=bounds,aes(x1,y1,xend=x2,yend=y2)) +
geom_abline(data=bounds[1,],aes(slope=m,intercept=b),linetype="dashed") +
geom_point(data=loc,aes(x,y),color="black") +
geom_point(data=nearest,aes(x,y),color="red",alpha=0.5) +
coord_equal()
loc_rep <- data.frame(x=rep(0,4),y=rep(75,4))
nearest <- get_nearest_point_on_line(loc_rep,m=bounds$m,b=bounds$b)
ggplot() +
geom_segment(data=bounds,aes(x1,y1,xend=x2,yend=y2)) +
geom_abline(data=bounds,aes(slope=m,intercept=b),linetype="dashed") +
geom_point(data=loc_rep,aes(x,y),color="black") +
geom_point(data=nearest,aes(x,y),color="red",alpha=0.5) +
coord_equal()
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.