Dear all, I would like to ask you if R has a library that can work with different GPS formats For example I have a string of this format N50° 47.513 E006° 03.985 and I would like to convert to GPS decimal format. that means for example converting the part N50° 47.513 to 50 + 47/60 + 513/3600. Is it possible to do that with R? What is the name of such a library? I would like to thank you in advance for your help B.R Alex [[alternative HTML version deleted]]
Take a look at:
http://cran.r-project.org/web/views/Spatial.html
But I've always just parsed the string...
This is from the last time I did this, its not quite the same but you
can see the similarities.
## if data is presented as 43?02'46.60059" N need to split on the ?
symbol, ' and ".
to.decimal <- function(vec){
# convert all symbols to _
vec <- gsub('?','_',vec)
vec <- gsub('\'','_',vec)
vec <- gsub('\"','_',vec)
split <- str_split(vec,'_')
deg <- as.numeric(sapply(split,'[',1))
min <- as.numeric(sapply(split,'[',2))
sec <- as.numeric(sapply(split,'[',3))
deg <- deg + min/60 + sec/3600
return(deg)
}
On Wed, Mar 7, 2012 at 8:28 AM, Alaios <alaios at yahoo.com>
wrote:> Dear all,
> I would like to ask you if R has a library that can work with different GPS
formats
>
> For example
> I have a string of this format
>
> N50? 47.513 E006? 03.985
> and I would like to convert to GPS decimal format.
>
> that means for example converting the part N50? 47.513
> to 50 + 47/60 + 513/3600.
>
> Is it possible to do that with R?
> What is the name of such a library?
>
> I would like to thank you in advance for your help
>
> B.R
> Alex
>
> ? ? ? ?[[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
Gabor Grothendieck
2012-Mar-07 16:51 UTC
[R] GPS handling libraries or (String manipulation)
On Wed, Mar 7, 2012 at 11:28 AM, Alaios <alaios at yahoo.com> wrote:> Dear all, > I would like to ask you if R has a library that can work with different GPS formats > > For example > I have a string of this format > > N50? 47.513 E006? 03.985 > and I would like to convert to GPS decimal format. > > that means for example converting the part N50? 47.513 > to 50 + 47/60 + 513/3600. > > Is it possible to do that with R? > What is the name of such a library? >Use strapply to extract the digits and convert them to numeric followed by matrix multiplication to apply the formula: library(gsubfn) x <- "N50? 47.513" c(1, 1/60, 1/3600) %*% strapply(x, "\\d+", as.numeric, simplify = TRUE) -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
Wow... that is WAY better! Thanks Gabor! On Wed, Mar 7, 2012 at 8:51 AM, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:> On Wed, Mar 7, 2012 at 11:28 AM, Alaios <alaios at yahoo.com> wrote: >> Dear all, >> I would like to ask you if R has a library that can work with different GPS formats >> >> For example >> I have a string of this format >> >> N50? 47.513 E006? 03.985 >> and I would like to convert to GPS decimal format. >> >> that means for example converting the part N50? 47.513 >> to 50 + 47/60 + 513/3600. >> >> Is it possible to do that with R? >> What is the name of such a library? >> > > Use strapply to extract the digits and convert them to numeric > followed by matrix multiplication to apply the formula: > > library(gsubfn) > x <- "N50? 47.513" > > c(1, 1/60, 1/3600) %*% strapply(x, "\\d+", as.numeric, simplify = TRUE) > > > -- > Statistics & Software Consulting > GKX Group, GKX Associates Inc. > tel: 1-877-GKX-GROUP > email: ggrothendieck at gmail.com > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.