I want to merge additional spatial coordinates into a preexisting spatial line.
My data:
- Spatial coordinates representing coastlines.
- Spatial coordinates representing observations.
Observations do not necessarily match coordinates on the lines, so I have snapped the observations to the lines. This gives a new coordinate for the observation: its place on the preexisting line.
I want to merge this new coordinate into the original spatial lines data, in the correct place so it does not disrupt the correct order of original coordinates along the line.
I have looked into the sp
object manipulations, but cannot figure out how to produce the data structure I am after.
# Pre-existing line
> head(grpCoords)
LONG LAT
[1,] 140.6615 -8.846777
[2,] 140.5811 -8.728320
[3,] 140.4897 -8.620410
[4,] 140.1017 -8.300586
[5,] 140.0029 -8.195508
[6,] 139.9833 -8.166504
# Observation
> xy
[,1] [,2]
[1,] 167 -45
# New coordinate for observation on the line
> dist2Line(xy, grpCoords)
distance lon lat
[1,] 4123324 150.4824 -10.63691
For example: For XY coordinates representing the line:
XY[1,1] _ _ _ _ _ _ _ XY[1,9] _ _ XY[1,12]
Where:
LONG LAT
1 1
1 9
1 12
If the observed coordinate is XY[1,8], I would expect:
XY[1,1] _ _ _ _ _ _ XY[1,8] XY[1,9] _ _ XY[1,12]
And the merged data to be:
LONG LAT
1 1
1 8
1 9
1 12