Hello,
You will find hereafter the reprex() of my function test, shape file and picture of the result.
I would like that the point green and red must be in the same position to ensure the overlay of the segments and background map.
Note : I tried to upload a shape file but it's not possible.
Thanks in advance to your help!
rm(list=ls())
library(sf)
#> Linking to GEOS 3.6.2, GDAL 2.2.3, PROJ 4.9.3
#data(flowdata)
map <- st_read("MGP_TER.shp")
#> Cannot open data source MGP_TER.shp
#> Error in CPL_read_ogr(dsn, layer, query, as.character(options), quiet, : Open failed.
nodes <- data.frame(stringsAsFactors = FALSE,
Xi= c(651786.1,651786.1,651786.1),
Yi=c(6862044,6862044,6862044),
Xj=c(651786.1,662465.4,665350.7),
Yj=c(6862044,6858149,6851330)
)
p.X <- sf::st_as_sf(x = nodes, coords = c("Xi", "Yi"), crs = 4326)
p.Y<- sf::st_as_sf(x = nodes, coords = c("Xj", "Yj"), crs = 4326)
nodes<-cbind(p.Y,p.X)
test<-function(tab){
plot(tab$geometry, col = "green", lwd = 2)
plot(tab$geometry.1, add=TRUE ,col = "green", lwd = 2)
trace <- arrows(tab$Xi, tab$Yi, tab$Xj, tab$Yj, code = 0, col = "black")
}
dev.off()
#> null device
#> 1
par(bg = "NA")
plot(st_geometry(map), col = "blue") # background
#> Error in st_geometry(map): objet 'map' introuvable
plot(st_centroid(map), add=TRUE,col = "red")
#> Error in st_centroid(map): objet 'map' introuvable
par(new=TRUE)
#> Warning in par(new = TRUE): appel de par(new=TRUE) sans graphe
test(nodes)
#> Warning in st_is_longlat(x): bounding box has potentially an invalid value
#> range for longlat data