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:

  • d
  • m
  • parse_hemisphere
  • parse_lat
  • parse_lat_lon
  • parse_lon
  • parse_parts_lat
  • parse_parts_lon
  • pz_degree
  • pz_minute
  • pz_second
  • s

Installation

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

parse

latitudes

longitudes

both lat and lon together

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

parse into degree, min, sec parts

get hemisphere from lat/lon coords

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

get degree, minutes, or seconds separately

coords <- c(45.23323, "40:25:6N", "40° 25´ 5.994\" N")
pz_degree(coords)
#> [1] 45 40 40
pz_minute(coords)
#> [1] 13 25 25
pz_second(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

d(31)
#> 31
d(31) + m(44)
#> 31.73333
d(31) - m(44)
#> 30.26667
d(31) + m(44) + s(59)
#> 31.74972
d(-121) + m(1) + s(33)
#> -120.9742

Meta