0

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?

1 Answers1

0

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.

Orlando Sabogal
  • 1,470
  • 7
  • 20
  • Dear Orlando, Many thanks for your time and effort to answer my question. I ran your code just fine. I try to export the result (Test_coord) and get the following error: `The object "dataframe" must have class data.frame` Forgive me my ignorance, but you would help me great when you show me how to do this. Best, Eric – Eric Melse May 11 '20 at 16:27
  • Eric, which function are you using? as Test_coord is still an spatial object you should export it as such. Try st_write(Test_coord, "Test.shp") – Orlando Sabogal May 11 '20 at 17:14
  • Dear Orlando, yes, this actually does the job real fine! I got the latitude longitude points of the world map exported to a shape file and I am able to work with that further. Again, many thanks for your kind assistance. – Eric Melse May 12 '20 at 07:36
  • I am glad it helped you. Do not forget to upvote the answer and marked it as solved :) – Orlando Sabogal May 12 '20 at 22:16