I have a SpatialLineDataFrame
with 20 observations of 4 variables (in WGS84). I want to create waypoints every 10 meters. Every waypoint will has the x y coordinates. I tried to do it manually like:
point_first=SpatialPoints(cbind(x,y))
for the first point, but there are many points I want to do, so it is not possible to do it that way. I think I need a loop but I don't know how to do it in order to have the coordinates for every waypoint.
Is there any command that I should use?
Best Answer
There is a nice tutorial on segmentation of spatial lines which you can find here, and you could make use of
CreateSegment
to achieve your goal. But first of all, let's create some sample data.Since you'd like to work with meters rather than degrees, reproject the data (e.g. to UTM) and extract the coordinates which we will require later on as input for
CreateSegment
.Next, let's create a sequence representing the desired segmentation.
rgeos::gLength
comes in quite handy for that. I chose segments of 100 km in length.You can now loop over this sequence and extract the start and end coordinate of each single segment.
Finally,
rbind
the coordinates and assign the projection of our initial shapefile. That's it!