Search code examples
latitude-longitudetmap

How to get from tmap the latitude longitude of each x,y point on the World map?


With the library tmap, a map can be plotted of the world coastlines and borders:

library(tmap)
data("World")
tm_shape(World) + tm_borders()

Is it possible to get the latitude longitude of each x,y point on the map that is used to draw coastlines and borders?

If not, is such a set of data with latitude longitude points of the world map to draw coastlines (and borders) available elsewhere?


Solution

  • You can do it in the following way:

    library(sf)
    library(tmap)
    
    data("World")
    tm_shape(World) + tm_borders()
    
    Test <- st_union(World)
    
    tm_shape(Test) + tm_borders()
    
    Test_coord <- st_cast(Test, "MULTIPOINT")
    
    tm_shape(Test_coord) + tm_dots()
    

    There are some lines and points in the file that are not coastal lines. I think that is so because of some problmes in the World object, so condier using a different shape file.