77891

Interpolating an irregular grid

Question:

I have a dataset with lat/lon and depth parameters, taken on an irregular grid. I'd like to plot an interpolated bathymetry map. I've seen several solutions for regular grids, but that just doesn't apply... Any suggestions would be appreciated.

A 50-point subset of my data:

df <- structure(list(Lat = c(49.33805, 49.33805, 49.33817, 49.33819, 49.33823, 49.33823, 49.33827, 49.33829, 49.33834, 49.33844, 49.33846, 49.33846, 49.33847, 49.33847, 49.33847, 49.33848, 49.33849, 49.33849, 49.33849, 49.33856, 49.33859, 49.33861, 49.33862, 49.33865, 49.33866, 49.33868, 49.33869, 49.33869, 49.3387, 49.33871, 49.33872, 49.33875, 49.33877, 49.33878, 49.33882, 49.33883, 49.33883, 49.33884, 49.33884, 49.33884, 49.33887, 49.33888, 49.33889, 49.33891, 49.33891, 49.33891, 49.33893, 49.33893, 49.33894, 49.33895), Long = c(-117.76914, -117.76943, -117.76852, -117.76878, -117.76912, -117.76953, -117.76981, -117.76847, -117.76991, -117.76768, -117.76883, -117.76914, -117.76679, -117.76954, -117.76989, -117.76743, -117.76655, -117.76788, -117.76844, -117.77002, -117.76815, -117.76704, -117.76775, -117.76608, -117.76644, -117.7695, -117.76883, -117.76986, -117.76573, -117.76911, -117.76843, -117.76741, -117.76673, -117.77012, -117.76543, -117.76715, -117.76813, -117.76512, -117.76611, -117.76781, -117.76572, -117.76477, -117.76641, -117.76451, -117.7688, -117.76952, -117.76912, -117.76987, -117.76739, -117.76507), Depth = c(5.75, 5.75, 5.75, 5.75, 9.75, 5.75, 4.75, 10.75, 3.75, 6.75, 12.75, 15.75, 4.75, 8.75, 5.75, 2.75, 5.75, 9.75, 15.75, 2.75, 14.75, 14.75, 16.75, 5.75, 12.75, 10.75, 16.75, 7.75, 7.75, 15.75, 16.75, 14.75, 11.75, 2.75, 5.75, 15.75, 17.75, 5.75, 10.75, 15.75, 13.75, 3.75, 16.75, 4.75, 16.75, 12.75, 16.75, 8.75, 16.75, 7.75), N = c(389L, 390L, 352L, 353L, 388L, 391L, 426L, 351L, 427L, 316L, 354L, 387L, 247L, 392L, 425L, 280L, 246L, 317L, 350L, 428L, 318L, 279L, 315L, 216L, 245L, 393L, 355L, 424L, 215L, 386L, 349L, 281L, 248L, 429L, 187L, 278L, 319L, 186L, 217L, 314L, 214L, 161L, 244L, 160L, 356L, 394L, 385L, 423L, 282L, 185L ), VelMagnit = c(7.84, 5.74, 5.41, 9.59, 7.02, 9.39, 13.1, 7.16, 29.22, 2.02, 1.44, 6.88, 35.82, 8, 12.6, 37.27, 26.95, 13.3, 3.35, 11.1, 7.48, 23.57, 18.77, 38.21, 20.69, 4.53, 7, 8.84, 74.77, 9.49, 18.75, 8.26, 32.66, 2.77, 39.31, 22.61, 29.11, 36.88, 33.37, 30.51, 21.39, 37.23, 16.66, 20.46, 8.66, 7.08, 19.23, 4.16, 16.01, 25.98), VelAngle = c(109.359, 234.926, 64.855, 73.644, 100.67, 63.435, 159.905, 331.645, 331.593, 147.095, 123.69, 57.465, 268.24, 167.005, 178.636, 224.239, 253.179, 246.519, 17.354, 178.968, 307.942, 253.487, 279.814, 260.661, 277.778, 223.21, 30.964, 201.922, 260.764, 288.435, 346.112, 308.118, 277.212, 154.359, 271.166, 231.103, 318.203, 248.025, 256.13, 271.315, 234.898, 250.543, 248.518, 241.054, 328.696, 193.055, 324.739, 170.311, 321.34, 248.076), North = c(5465321.35407466, 5465320.45673062, 5465334.20185859, 5465335.84649416, 5465340.32938523, 5465340.53806541, 5465345.46949452, 5465347.29204307, 5465353.67668219, 5465362.67550185, 5465366.05612295, 5465366.13117831, 5465365.62894912, 5465368.30742982, 5465368.10764226, 5465366.85006568, 5465367.60985361, 5465369.27129842, 5465369.44129325, 5465378.49168744, 5465380.30823023, 5465381.65815607, 5465383.53421217, 5465384.93126624, 5465386.83124086, 5465391.62499386, 5465391.43748737, 5465392.17083906, 5465390.93768874, 5465393.93779788, 5465395.22644872, 5465396.81815796, 5465398.99484539, 5465402.67778048, 5465404.02489866, 5465406.43767199, 5465406.45411863, 5465405.13054023, 5465406.62568988, 5465408.19081624, 5465409.83421333, 5465409.91360362, 5465411.67748384, 5465413.14356129, 5465416.11549776, 5465416.75272559, 5465418.21530199, 5465418.6115072, 5465418.87768738, 5465417.78379895 ), East = c(444125.003387342, 444103.946731878, 444170.258760669, 444151.770882767, 444126.431718875, 444097.212992858, 444076.978665012, 444174.228007541, 444069.150472669, 444231.481904453, 444148.344059708, 444125.684605454, 444296.448416587, 444096.50059478, 444071.375433859, 444249.563863466, 444313.78879066, 444216.996727711, 444176.233348778, 444061.593340175, 444197.652741389, 444278.150298904, 444227.007871585, 444347.827629692, 444321.648646752, 444099.506214185, 444148.486188144, 444073.2190657, 444373.88336123, 444127.863992462, 444177.120505223, 444251.29961245, 444300.804805398, 444054.654670874, 444395.709813492, 444270.773540085, 444199.146474186, 444418.264802441, 444346.449347451, 444222.979333791, 444374.314694461, 444443.29084392, 444324.123924214, 444462.496268479, 444151.098575609, 444098.352789667, 444127.224871463, 444073.059940659, 444253.383634326, 444421.480670821), angle = c(5.945307017286, 3.75374943543428, 0.438863040413974, 0.285466052456192, 6.09695867599179, 0.463646715792294, 5.06311289357295, 2.06568443619789, 2.06659200740893, 5.28668957075342, 5.6951838821827, 0.567842872136355, 3.17231044842489, 4.93919451668135, 4.73619527138189, 3.94027277259492, 3.43517448706776, 3.55141341525058, 1.2679118884038, 4.73040077826527, 2.4793798287981, 3.42979887297162, 2.97030604079907, 3.30458895243354, 3.00584094436967, 3.95823221059794, 1.03037257720737, 4.32977790176249, 3.30279126330399, 2.81984120598464, 1.81318765331187, 2.47630804931459, 3.01571950793596, 5.15990885388856, 3.12124211451154, 3.82047337273803, 2.30029159425097, 3.52512875671555, 3.38366982084141, 3.11864157392607, 3.75423812762484, 3.48118136615033, 3.51652428350322, 3.64679565887207, 2.1171541958392, 4.48453624653683, 2.18621687434062, 4.88149393161042, 2.24554061561591, 3.52423863879703), EEnd = c(444127.468963086, 444102.380839669, 444171.891201757, 444154.838181978, 444128.731259986, 444100.012551216, 444078.478954484, 444173.094500332, 444064.516846156, 444231.84769125, 444148.743444163, 444127.618030096, 444284.514049334, 444097.10023751, 444071.475410837, 444240.896688604, 444305.18982274, 444212.930508718, 444176.566422062, 444061.659980224, 444195.686415001, 444270.617678339, 444220.842763233, 444335.259781332, 444314.815430257, 444098.472355955, 444149.686686742, 444072.118945325, 444349.283143613, 444124.862991856, 444175.620350655, 444249.133451857, 444290.004269359, 444055.054225809, 444382.609193401, 444264.907933091, 444192.679266209, 444406.864613959, 444335.650346807, 444212.812012208, 444368.481430089, 444431.589557366, 444318.956366165, 444456.528248516, 444149.598724913, 444097.819698049, 444123.524365878, 444073.293316846, 444250.049831143, 444413.446962578 ), NEnd = c(5465320.48779101, 5465319.35726437, 5465334.9681139, 5465336.74669044, 5465339.89612933, 5465341.93784146, 5465341.36865202, 5465349.3923619, 5465362.24389325, 5465362.11018973, 5465365.78986733, 5465367.3645667, 5465365.26223633, 5465365.70905731, 5465363.90883235, 5465357.94954373, 5465365.01023277, 5465367.50485919, 5465370.50712937, 5465374.79228761, 5465381.8412898, 5465379.42503303, 5465384.60066272, 5465382.8644171, 5465387.76460223, 5465390.52443166, 5465393.4382991, 5465389.43723712, 5465386.93745905, 5465394.93813439, 5465401.29374106, 5465398.51774401, 5465400.36156861, 5465401.84537415, 5465404.29154015, 5465401.70523086, 5465413.68805938, 5465400.53035034, 5465403.95920727, 5465408.42420823, 5465405.73422226, 5465405.77984105, 5465409.64380369, 5465409.84278294, 5465418.58193088, 5465414.45372291, 5465423.44926401, 5465417.24462022, 5465423.04491277, 5465414.55035932), LatEnd = c(49.3380474342345, 49.3380349676146, 49.3381817413127, 49.3381961774213, 49.3382221137942, 49.3382378465177, 49.3382307534342, 49.3383115871151, 49.3384172309777, 49.3384313488661, 49.3384568417901, 49.3384690705233, 49.3384645117795, 49.3384513844775, 49.3384328439213, 49.3383947540559, 49.3384641332503, 49.3384781403051, 49.3385018169049, 49.3385298326984, 49.3386055088849, 49.3385906265511, 49.3386326282497, 49.3386274634674, 49.3386696711786, 49.3386747064999, 49.3387056057661, 49.3386625123754, 49.3386653770491, 49.3387168224261, 49.3387786336194, 49.3387603885808, 49.3387807064111, 49.3387725497545, 49.3388245039422, 49.3387904992063, 49.3388916724367, 49.3387928857403, 49.3388172315733, 49.3388461694421, 49.3388361915708, 49.3388423539545, 49.3388668368414, 49.3388811684793, 49.3389317464578, 49.3388898732875, 49.3389731367353, 49.338912727242, 49.3389810765077, 49.3389195855133), LonEnd = c(-117.769107642156, -117.769452798913, -117.768498238181, -117.768733207393, -117.769092988058, -117.769488562773, -117.769784874489, -117.768483695931, -117.769979980219, -117.767676786145, -117.768821165483, -117.769112160817, -117.766952315992, -117.769531981989, -117.769884434776, -117.76755165188, -117.766667694915, -117.76793792113, -117.768438864769, -117.770021063608, -117.768177279629, -117.767145568728, -117.767831407383, -117.766256298647, -117.766538384655, -117.769516575962, -117.768812056346, -117.769879158813, -117.766063845997, -117.769153946831, -117.768456198264, -117.767443953382, -117.766881652868, -117.770115783579, -117.765607558364, -117.767227274384, -117.768223129479, -117.765273174343, -117.766253868597, -117.767945278942, -117.765802218797, -117.764933584222, -117.766484443928, -117.764590885974, -117.768816790031, -117.769528915231, -117.769176368711, -117.76986689595, -117.767434770472, -117.765184527934 )), .Names = c("Lat", "Lon", "Depth", "N", "VelMagnit", "VelAngle", "North", "East", "angle", "EEnd", "NEnd", "LatEnd", "LonEnd"), row.names = c(NA, 50L), class = "data.frame") library(ggplot2) library(ggmap) prep <- get_googlemap( center = c(-117.7670, 49.34027), zoom = 17, maptype = 'hybrid', scale = 2) map <- ggmap(prep, size = c(100, 200), extent='device', darken = 0.5, legend = "bottom", base_layer = ggplot(data = df, aes(x = Lon, y = Lat))) map + geom_point(aes(fill = Depth), size = 3, shape = 21)

Answer1:

Read the Spatial Task View on CRAN and use one of the interpolation techniques mentioned there. In particular the automap package can do kriging and inverse distance weighting. You can get not only estimates from irregular samples onto a regular grid but error estimates too.

If you generate your output into a raster object you can use all the goodies from the raster package for visualisation and manipulation, and the rasterVis packages for visualisation.

Recommend