简体   繁体   中英

R package tmap: unable to overlay points on line & unable to show points in view mode

I have developed code to identify where freeway ramps terminate on surface streets and I would like to show those points on a map which also shows the freeways and ramps to check whether my code is correct.

I created an simple features (sf) object of freeways (motorways) and ramps (motorway_links) for a city from open streets maps using the osm package. My code identifies the coordinates of the points where the ramps terminate on surface streets and creates an sf object of the points. The coordinates in both sf objects are geographic. They are consistent because the ramp termini nodes are selected from the link endpoint coordinates.

I have checked that both objects are of class 'sf'. I can plot both sf objects using the plot command:

plot(st_geometry(Hwy_sf))
plot(st_geometry(RampTerminiNodes_sf), add = TRUE, col = "red")

I would like to plot them using the tmap package in 'view' mode to be able to zoom into areas to confirm that the ramp termini are correctly identified but I am running into 2 problems.

First I can't get ramp termini points to plot over the highway lines in tmap. I can get each layer to plot separately but can't get the point layer plotted on top of the line layer. This works to show the highways as lines:

tmap_mode("plot")
tm_shape(Hwy_sf) + tm_lines(lwd = 2)

And this works to show the ramp termini as points:

tmap_mode("plot")
tm_shape(RampTerminiNodes_sf) + tm_bubbles(size = 0.1, col = "red")

But this doesn't work (the lines are displayed but the points are not):

tmap_mode("plot")
tm_shape(Hwy_sf) + tm_lines(lwd = 2) + 
  tm_shape(RampTerminiNodes_sf) + tm_bubbles(size = 0.1, col = "red")

Second, I haven't been able to figure out how to display the point data in "view" mode. This doesn't work. The plot area shows the message: "Map data not yet available"

tmap_mode("view")
tm_shape(RampTerminiNodes_sf) + tm_bubbles(size = 0.1, col = "red")

System info is:
Windows 10
R version Rx64 4.0.2
R Studio version 1.3.1093

Solved the problem. I had an error in my code that changed the projection of the RampTerminiNodes_sf object. Correcting that solves the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM