0
votes

I want to show points on the map. Those points are represented as coordinates (long/lat) and are stored in a data frame as numerics. I'm wondering if I really need to transform numeric coordinates (lon/lat) to sf object of POINT type. I don't know what benefits of such convertion are. In this example I use numeric coordinates from 2 columns and show them on the map:

data(quakes)

leaflet(data = quakes[1:20,]) %>% addTiles() %>%
  addMarkers(~long, ~lat)

Here data frame (quakes) is not spatial, lon/lat are numeric. However, I can do exactly the same converting numeric coordinates to sf POINTs, then show them on a map:

coords <- quakes %>%
  sf::st_as_sf(coords = c("long","lat"), crs = 4326) %>%
  sf::st_geometry()

leaflet(data = coords[1:20,]) %>% addTiles() %>%
  addMarkers()

Question is: in case of showing points (markers) on the map - should we convert to spatial objects first or just use numeric columns? What's the point of using POINTs at all if I can do exactly the same using numeric lon/lat? Performance issues?

1
If you want, you can use points in tm_dots in tmap rather than the coordinates using leaflet.william3031
Ok, I know that I can use it but what's the difference in using sf POINTs or numeric coordinates (float)? Maybe it's no difference? Or maybe it's all about performance or precision on the map?mustafa00

1 Answers

1
votes

You don't need to convert, and if the only purpose of your spatial object is drawing a {leaflet} map - i.e. you do no other calculations, statistics, modelling or so on - there is little point in transforming.

The {leaflet} documentation is quite straigforward about data types supported - {sf} objects, {sp} objects & regular lat / lon data.frames.

The only - very slight - benefit of using one of the special spatial formats is that you don't need to specify your latitude & longitude mappings in your addMarker() call. I wouldn't expect any effect on performance.

Note though that while {leaflet} supports multiple ways of data input it will not be able to process data in projected coordinate systems (eastings and northings).