Closed sckott closed 4 years ago
e.g,. N 04.25164, E 101.70695
from noam
c("N 04.1683, E 101.5823", "N 04.25164, E 101.70695", "N04.82344, E101.61320",
"N05.03062, E101.75172", "N05.03062,E101.75172", "N4.9196, E101.345",
"N4.9196, E101.346", "N4.9196, E101.347")
Function I (he) wrote to deal with these (I knew the hemisphere):
latlong_to_lat_long <- function(latlong) {
caps <- stri_match_first_regex(latlong, "N\\h*([\\d\\.]+),\\h*E\\h*([\\d\\.]+)")
lat <- as.double(caps[,2])
long <- as.double(caps[,3])
return(list(lat = lat, long = long))
}
a bit of experimenting on branch parse-string-lat-and-lon
Hi @sckott,
I wrote a function that does that (here https://github.com/AlbanSagouis/iClean/blob/master/R/coordinate_conversions.R). It is not elegant, it is pure R code (no Rcpp), it depends on biogeo::dmsparse and it is highly redundant with parzer. But it works on the example you provided here and on other formats.
c('52.473892, 13.40444',
'52,473892; 13,40444', '52,473892 13,40444',
'52°28’26”, 13°24’16”', '52°28’26”N, 13°24’16”E','N52°28’26”, E13°24’16”',
'52°28’26’’, 13°24’16’’','52°28’26"’, 13°24’16"', "52°28'26'', 13°24'16''",
'52 28 26, 13 24 16', '52 28 26.13 24 16', '52°28’26” 13°24’16”',
'S52°28’26”, W13°24’16”', '52°28’26”S, 13°24’16”W', 'S52°28’26” E13°24’16”',
'13.40444E, 52.473892N', '13°24’16”E, 52°28’26”N',
'13.40444, 52.473892', '13°24’16”, 52°28’26”',
# Examples from here https://www.codeproject.com/articles/15659/longitude-latitude-string-parser-and-formatter
'45:26:46N, 65:56:55W',
'45:26:46.302N, 65:56:55.903W',
'45°26’21"N, 65°58’36"W',
'45N26 21, 65W58 36',
'45.446195N, 65.948862W',
'45.446195, -65.948862',
'N45° 26.7717’, W65° 56.93172’',
# example from parzer test
"45W54.2356, 45N54.2356",
# example from parzer
"N 04.1683, E 101.5823", "N 04.25164, E 101.70695", "N04.82344, E101.61320",
"N05.03062, E101.75172", "N05.03062,E101.75172", "N4.9196, E101.345",
"N4.9196, E101.346", "N4.9196, E101.347",
# expected errors
'52°28’260”, 13°64’16”', '92°28’26”, 190°24’16”'
I would be happy to contribute to your branch parse-string-lat-and-lon
. Could that be useful?
thanks very much for dropping in here @AlbanSagouis !
Looks good, but this package has all the work done on the C++ side, with the R side only being a thin function interface over the C++ code. Do you think you could translate your R code to C++?
Well, I'll try translating my code to Rcpp/C++. It is not my main project so please let me know if you need it ready for milestone 0.2.
Thanks for updating the branch!
thx. let me know if you have any questions
the c++ code only does one or the other
so make c++ stuff to do the parsing, then u can feed that in