0

I want to merge additional spatial coordinates into a preexisting spatial line.

My data:

  1. Spatial coordinates representing coastlines.
  2. 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
jay.sf
  • 60,139
  • 8
  • 53
  • 110
jat
  • 93
  • 1
  • 8
  • 1
    Hi, could you please [make this more reproducible](https://stackoverflow.com/a/5963610/6574038) and on-topic for Stack Overflow with it? – jay.sf Jul 10 '19 at 08:45
  • I would look at this question: https://gis.stackexchange.com/a/270814/32531 to turn your points into a line instead of "merging" – jsta Jul 14 '19 at 15:49

0 Answers0