parzer parses messy coordinates

You may get data from a published study or a colleague, and the coordinates may be in some messy format that you’d like to clean up to e.g., have all decimal degree numeric data.

parzer API:

  • parse_hemisphere
  • parse_lat
  • parse_lat_lon
  • parse_lon
  • parse_parts_lat
  • parse_parts_lon
  • pz_d
  • pz_degree
  • pz_m
  • pz_minute
  • pz_s
  • pz_second

Installation

remotes::install_github("ropenscilabs/parzer")
library("parzer")

parse

latitudes

longitudes

both lon and lat together

lons <- c("45W54.2356", "181", 45, 45.234234, "-45.98739874")
lats <- c("40.123°", "40.123N", "191.89", 12, "N45 04.25764")
parse_lat_lon(lons, lats)
#>         lon      lat
#> 1 -45.90393 40.12300
#> 2 181.00000 40.12300
#> 3  45.00000      NaN
#> 4  45.23423 12.00000
#> 5 -45.98740 45.07096

parse into degree, min, sec parts

get hemisphere from lat/lon coords

parse_hemisphere("74.123E", "45N54.2356")
#> [1] "NE"
parse_hemisphere("-120", "40.4183318")
#> [1] "NW"
parse_hemisphere("-120", "-40.4183318")
#> [1] "SW"
parse_hemisphere("120", "-40.4183318")
#> [1] "SE"

get degree, minutes, or seconds separately

coords <- c(45.23323, "40:25:6N", "40° 25´ 5.994\" N")
pz_degree(lat = coords)
#> [1] 45 40 40
pz_minute(lat = coords)
#> [1] 13 25 25
pz_second(lat = coords)
#> [1] 59.630119  6.005895  5.992162

coords <- c(15.23323, "40:25:6E", "192° 25´ 5.994\" E")
pz_degree(lon = coords)
#> [1]  15  40 192
pz_minute(lon = coords)
#> [1] 13 25 25
pz_second(lon = coords)
#> [1] 59.626686  6.005895  6.005895

add or subtract degrees, minutes, or seconds

pz_d(31)
#> 31
pz_d(31) + pz_m(44)
#> 31.73333
pz_d(31) - pz_m(44)
#> 30.26667
pz_d(31) + pz_m(44) + pz_s(59)
#> 31.74972
pz_d(-121) + pz_m(1) + pz_s(33)
#> -120.9742

Similar art

  • sp::char2dms: is most similar to parzer::parse_lat and parzer::parse_lon. However, with sp::char2dms you have to specify the termination character for each of degree, minutes and seconds. parzer does this for the user.
  • biogeo::dms2dd: very unlike functions in this package. You must pass separate degrees, minutes, seconds and direction to dms2dd. No exact analog is found in parzer, whos main focus is parsing messy geographic coordinates in strings to a more machine readable version

Meta