Skip to content

Instantly share code, notes, and snippets.

@josephlewis
Created February 11, 2018 19:39
Show Gist options
  • Save josephlewis/93d54a817f17edb12201531be0c41073 to your computer and use it in GitHub Desktop.
Save josephlewis/93d54a817f17edb12201531be0c41073 to your computer and use it in GitHub Desktop.
road_pts <- list()
for (i in unique(wales_roads$Name)) {
known_pts <- gInterpolate(wales_roads[wales_roads$Name == i,], d = seq(0, gLength(wales_roads[wales_roads$Name == i,]), by = gLength(wales_roads[wales_roads$Name == i,])), normalized = FALSE)
known_pts@coords
A <- known_pts@coords[1,]
B <- known_pts@coords[2,]
AtoB <- shortestPath(Conductance, A, B, output="SpatialLines")
plot(AtoB, add = TRUE, col = "red")
LCP_pts <- gInterpolate(AtoB, d = seq(0, gLength(AtoB), by = 250), normalized = FALSE)
dist <- as.data.frame(t(gDistance(AtoB, LCP_pts, byid = TRUE)))
AtoBdf <- SpatialLinesDataFrame(AtoB, data.frame(id = dist[,1]), match.ID = FALSE)
writeOGR(road_pts, dsn=getwd(), layer= paste("LCP_dist_test", i),driver="ESRI Shapefile")
road_pts[[i]] <- AtoBdf
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment