Skip to contents

Get lat/lon flexibly - from file, data.frame, data.table, or lat/lon vectors Like latlon_from_anything() but this also adds a ejam_uniq_id column

Usage

sitepoints_from_any(
  anything,
  lon_if_used,
  invalid_msg_table = FALSE,
  set_invalid_to_na = TRUE,
  interactiveprompt = TRUE
)

Arguments

anything

see latlon_from_anything(), which this is passed to

lon_if_used

see latlon_from_anything(), which this is passed to

invalid_msg_table

set to TRUE if you want columns "valid" and "invalid_msg" also

set_invalid_to_na

used by latlon_df_clean()

interactiveprompt

passed to latlon_from_any()

Value

data.frame with lat,lon, and ejam_uniq_id as colnames, one row per point

Examples

 sitepoints_from_any(testpoints_10)
#>         lat        lon sitenumber        sitename ejam_uniq_id
#> 1  37.64122 -122.41065          1  Example Site 1            1
#> 2  43.92249  -72.66370          2  Example Site 2            2
#> 3  40.69351  -73.98002          3  Example Site 3            3
#> 4  45.29520  -92.98184          4  Example Site 4            4
#> 5  39.43730  -74.72370          5  Example Site 5            5
#> 6  45.67487  -94.81534          6  Example Site 6            6
#> 7  33.14865 -117.19895          7  Example Site 7            7
#> 8  34.01176  -80.95414          8  Example Site 8            8
#> 9  43.01026  -89.45952          9  Example Site 9            9
#> 10 40.74625  -74.25955         10 Example Site 10           10
 sitepoints_from_any(lon_if_used = testpoints_10$lon, anything = testpoints_10$lat)
#>         lat        lon ejam_uniq_id
#> 1  37.64122 -122.41065            1
#> 2  43.92249  -72.66370            2
#> 3  40.69351  -73.98002            3
#> 4  45.29520  -92.98184            4
#> 5  39.43730  -74.72370            5
#> 6  45.67487  -94.81534            6
#> 7  33.14865 -117.19895            7
#> 8  34.01176  -80.95414            8
#> 9  43.01026  -89.45952            9
#> 10 40.74625  -74.25955           10
 sitepoints_from_any(testpoints_10$lat, testpoints_10$lon)
#>         lat        lon ejam_uniq_id
#> 1  37.64122 -122.41065            1
#> 2  43.92249  -72.66370            2
#> 3  40.69351  -73.98002            3
#> 4  45.29520  -92.98184            4
#> 5  39.43730  -74.72370            5
#> 6  45.67487  -94.81534            6
#> 7  33.14865 -117.19895            7
#> 8  34.01176  -80.95414            8
#> 9  43.01026  -89.45952            9
#> 10 40.74625  -74.25955           10
 pts = c("33,-100", "32,-101")
 sitepoints_from_any(pts)
#>   lat  lon ejam_uniq_id
#> 1  33 -100            1
#> 2  32 -101            2
 pts = data.frame(Longitude = testpoints_10$lon, Latitude = testpoints_10$lat)
 sitepoints_from_any(pts)
#> Replaced column names that were inferred to be and therefore renamed as the lat and/or lon columns!
#>           lon      lat ejam_uniq_id
#> 1  -122.41065 37.64122            1
#> 2   -72.66370 43.92249            2
#> 3   -73.98002 40.69351            3
#> 4   -92.98184 45.29520            4
#> 5   -74.72370 39.43730            5
#> 6   -94.81534 45.67487            6
#> 7  -117.19895 33.14865            7
#> 8   -80.95414 34.01176            8
#> 9   -89.45952 43.01026            9
#> 10  -74.25955 40.74625           10
 pts = data.table(Lat = testpoints_10$lat, Long = testpoints_10$lon)
#> Error in data.table(Lat = testpoints_10$lat, Long = testpoints_10$lon): could not find function "data.table"
 sitepoints_from_any(pts)
#> Replaced column names that were inferred to be and therefore renamed as the lat and/or lon columns!
#>           lon      lat ejam_uniq_id
#> 1  -122.41065 37.64122            1
#> 2   -72.66370 43.92249            2
#> 3   -73.98002 40.69351            3
#> 4   -92.98184 45.29520            4
#> 5   -74.72370 39.43730            5
#> 6   -94.81534 45.67487            6
#> 7  -117.19895 33.14865            7
#> 8   -80.95414 34.01176            8
#> 9   -89.45952 43.01026            9
#> 10  -74.25955 40.74625           10
 
 sitepoints_from_anything(testpoints_bad, set_invalid_to_na = F, invalid_msg_table = T)
#> Warning: Some lat or lon values are invalid - NA or number entirely outside expected ranges (US including Island Areas)
#>          lat        lon                     note  valid
#>        <num>      <num>                   <char> <lgcl>
#> 1:  40.64459  -75.19943             stateborder1   TRUE
#> 2:  40.64042  -75.19278             stateborder2   TRUE
#> 3:  40.64570  -75.19662             stateborder3   TRUE
#> 4:  41.53891  -77.88995                    rural   TRUE
#> 5:  40.74500  -73.98426                    urban   TRUE
#> 6:  39.00000  -71.76199           invalid-nonusa   TRUE
#> 7: -73.98426   40.74500  invalid-lat-lon-swapped  FALSE
#> 8: 200.00000 -200.00000 invalid-impossiblelatlon  FALSE
#> 9:        NA         NA               invalid-na  FALSE
#>                                     invalid_msg ejam_uniq_id
#>                                          <char>        <int>
#> 1:                                                         1
#> 2:                                                         2
#> 3:                                                         3
#> 4:                                                         4
#> 5:                                                         5
#> 6:                                                         6
#> 7: latlon may be outside States/PR/Island Areas            7
#> 8:                            latlon impossible            8
#> 9:                               latlon missing            9
 
 if (FALSE) { # \dontrun{
 if (interactive()) {
   pts <- sitepoints_from_any()
 }} # }
 if (FALSE) { # \dontrun{
 pts = system.file("testdata/latlon/testpoints_10.xlsx", package = "EJAM")
 sitepoints_from_any(pts)
 } # }