How to connect Spatialpoints in leaflet with lines?

13 Views Asked by At

I have a map in leaflet with spatialpoints. The points represent the trajectory of a fish, so I would like to convert the points into a line instead. But I cannot figure out how to do it (I'm new to R).

I have this code so far:

map <- leaflet(data=longlatcoor)
map <- addTiles(map)
map <- addCircles(map, data=longlatcoor, radius=2)
map

Longlatcoor is a Formal class SpatialPoints, and looks like this:

(https://i.stack.imgur.com/PRzrp.png)

The coordinates are under 'longlatcoor - coords' (see above).

I have tried to use addPolylines, but it doesn't work. I suppose it is because it's SpatialPoints and not SpatialLines. I don't know how to convert the SpatialPoints to SpatialLines.

How do I turn the points into a line? I would like to keep the trajectory on the leaflet map.

Thank you in advance!

I have tried to use addPolylines, but it doesn't work. I suppose it is because it's SpatialPoints and not SpatialLines. I don't know how to convert the SpatialPoints to SpatialLines (I have tried).

I have looked online to find a solution, but it has been unsuccessful. I have found similar posts, but they don't match 100%. I also struggle to navigate in the posted R scripts since I'm unfamiliar with them.

0

There are 0 best solutions below