R/nearest_point.R
nearest_point.Rd
Function to select nearest community to a given sampling point (usually the centroid of a square grid for CSAS or of a hexagonal grid for S3M)
nearest_point(data, x1, y1, query, x2, y2, n = 1, duplicate = FALSE)
data | A matrix or data frame of input sampling locations to which nearest village locations are to be matched. Data frame should contain at least information on longitude and latitude coordinates |
---|---|
x1 | A character value specifying the variable name in |
y1 | A character value specifying the variable name in |
query | A data frame of village/community locations with at least information on longitude and latitude coordinates from which to query for nearest point |
x2 | A character value specifying the variable name in |
y2 | A character value specifying the variable name in |
n | Number of nearest village/community locations to select. Default is 1 |
duplicate | Logical. If TRUE, keep duplicate samples. If FALSE, remove duplicate samples. |
A data frame of selected nearest sampling village/community locations
# Use nearest_point() with test sampling points in Sennar sennar <- subset(sudan01, STATE == "Sennar") samp.points <- sp::spsample(sennar, type = "hexagonal", n = 20)#> Warning: Discarded datum WGS_1984 in CRS definition, #> but +towgs84= values preserved#> Warning: Discarded datum WGS_1984 in CRS definition, #> but +towgs84= values preserved#> Warning: Discarded datum WGS_1984 in CRS definition, #> but +towgs84= values preserved#> Warning: CRS object has comment, which is lost in outputnearest_point(data = samp.points@coords, x1 = "x", y1 = "y", query = sennar_villages, x2 = "x", y2 = "y", n = 3)#> spid id x y village locality #> 728 1 929 33.53883 12.26989 AlMazmoum AlDali and AlMazmoum #> 729 1 930 33.37906 12.04256 Hafir terus AlDali and AlMazmoum #> 730 1 931 33.33164 12.22647 Hafir umm koka AlDali and AlMazmoum #> 349 2 349 34.50039 12.59189 braish AlSooki #> 351 2 351 34.28500 12.43228 abo hager AlSooki #> 352 2 352 34.29117 12.41944 umdrman flaata AlSooki #> 717 3 918 33.21367 12.41053 Abu Ireif AlDali and AlMazmoum #> 718 3 919 33.36556 12.40275 AlMjawir AlDali and AlMazmoum #> 719 3 920 33.28083 12.61028 Galaa AlBeid AlDali and AlMazmoum #> 63 4 63 33.70803 12.59786 Alsahbaa Abu Hijar #> 727 4 928 33.49911 12.45197 Hilat Idris AlDali and AlMazmoum #> 732 4 933 33.75706 12.41561 Arab AlBalf (Kockry) Abu Hijar #> 68 5 68 34.18017 12.47111 AlZeaif Abu Hijar #> 357 5 357 34.16428 12.50389 Bunzga Janoob AlSooki #> 358 5 358 34.18850 12.48100 Kairan AlSooki #> 124 6 124 34.77686 12.85164 Om Sagit Al Dindir #> 126 6 126 34.79900 12.84908 Om Bagara Sharig Al Dindir #> 244 6 244 34.79008 12.82597 Um Bagara Garb Al Dindir #> 18 7 18 33.70356 12.77214 UmMarda Abu Hijar #> 19 7 19 33.56717 12.72828 Abo Rawag Abu Hijar #> 731 7 932 33.53467 12.72550 Hafir kamtor Abu Hijar #> 26 8 26 33.99511 12.88547 Tabat Abu Hijar #> 27 8 27 33.97611 12.89631 Khor AlLibda Abu Hijar #> 30 8 30 33.99053 12.93842 AlAmara Wad Baloola Abu Hijar #> 80 9 80 34.44878 12.93794 Araki Al Halaween Al Dindir #> 81 9 81 34.42286 12.92950 Wad Al Zalagam Al Dindir #> 83 9 83 34.40997 12.93781 Abd Al Banat Al Dindir #> 179 10 179 34.86331 13.02667 Um Bagaa Al Dindir #> 498 11 498 33.14969 13.36497 Dood Alamarna Sennar #> 500 11 500 33.15650 13.40961 Dood Albasheer Sennar #> 502 11 502 33.15931 13.34058 Dood Abdallah(Um Alaj) Sennar #> 506 12 506 33.70986 13.32258 Abdeen Al Ajooz Albarnu Sinja #> 508 12 508 33.71192 13.30561 Al Shigaig Sinja #> 510 12 510 33.71756 13.29853 Aldaraba Wad alaita Sinja #> 159 13 159 34.18036 13.27928 Al Rimaila Al Dindir #> 212 13 212 34.19547 13.33208 Wad Dayan Al Dindir #> 213 13 213 34.19164 13.31311 Wad Ragma Al Dindir #> 430 14 430 33.12422 13.84464 Baida Almagaweer Sennar #> 431 14 431 33.08758 13.88300 Um Wizzain Dafallah Sennar #> 432 14 432 33.07914 13.89189 Goaz Alhabeela Sennar #> 695 15 695 34.00000 13.78336 Darouma Sharg Sennar #> 696 15 696 33.99558 13.77711 Eid Misheilkha Sharg Sennar #> 697 15 697 34.03308 13.74931 Hanu Sleiman Sharg Sennar #> d #> 728 22.4855606 #> 729 19.9331003 #> 730 13.4760871 #> 349 76.2301730 #> 351 74.9589761 #> 352 69.7496792 #> 717 16.2299075 #> 718 12.2640410 #> 719 11.1255273 #> 63 25.1351204 #> 727 10.7369373 #> 732 10.2059015 #> 68 3.7277920 #> 357 3.1751858 #> 358 2.4040569 #> 124 54.5440632 #> 126 52.6688866 #> 244 51.5290913 #> 18 27.6219603 #> 19 21.5870073 #> 731 20.7801031 #> 26 4.7816015 #> 27 4.6538755 #> 30 2.2735658 #> 80 3.9984837 #> 81 3.8070010 #> 83 2.4181177 #> 179 12.4562117 #> 498 15.0689649 #> 500 12.7922493 #> 502 10.8524943 #> 506 1.8961438 #> 508 1.8472334 #> 510 1.6725948 #> 159 4.1163598 #> 212 1.9894734 #> 213 0.2297812 #> 430 19.9929640 #> 431 19.3796365 #> 432 17.6961054 #> 695 8.6318833 #> 696 8.2721783 #> 697 7.4325035