Rui Barradas
2022-Apr-27 11:07 UTC
[R] conversion of d m s (lat) d m s (long) coordinates into decimal coordinates
Hello, Thanks for answering in Portuguese but R-Help is a English language mailing list. Here are two ways. Both results are equal. # 1st lat <- "21d15'44\"N" lat1 <- sp::char2dms(lat, chd = "d", chm = "'", chs = "\"") as.numeric(lat1) #> [1] 21.26222 # 2nd chd = substr(lat, 3, 3)[1] chm = substr(lat, 6, 6)[1] chs = substr(lat, 9, 9)[1] lat2 <- sp::char2dms(lat, chd = chd, chm = chm, chs = chs) as.numeric(lat2) #> [1] 21.26222 Hope this helps, Rui Barradas ?s 10:53 de 27/04/2022, Nicolas Degallier escreveu:> Bom dia Rui (vejo que Vc. esta no Portugal), > > Avancei um pouco no tratamento dos meus dados de coordenadas geograficas. > Portanto tenho uma mensagem de erro (o arquivo texto tem apenas uma > linha de dados): > > ?coord <- read.table("coordDegal1.txt", header = TRUE) > > coord > ? ? ? ? ? nom ? ? ? ?lat ? ? ? long > D. antoinei 21d15'44"N 55d12'30"W > > > lat<-coord[2] > > lat > ? ? ? ? ?lat > 21d15'44"N > > lat1<-char2dms(lat,chd="d", chm=" ' ", chs="\"") > > Error in if (any(abs(object at deg) > 360)) return("abs(degree) > 360") > else if?(any(object at WS & ?: > ? valeur manquante l? o? TRUE / FALSE est requis > > Nao sei porque a fun??o /char2dms/ n?o deu certo para transformar a > coordenada 21d15'44"N em 21d15m44sN? > > Vc. teria uma explica??o ? > Atenciosamente > Nicolas > > > Le 26 avr. 2022 ? 22:04, Rui Barradas a ?crit : > >> Hello, >> >> You have a problem with the numbers format and with the smart single >> close quotes. Try to substitute single quotes for the problem characters. >> >> Hope this helps, >> >> Rui Barradas >> >> ?s 14:03 de 26/04/2022, Nicolas Degallier escreveu: >>> Hi Rui, >>> I succeded to convert a coordinate from decimal to DMS formats but >>> not the inverse!!! >>> ?dd<- -52.55684 >>> c<-dd2dms(dd, NS = FALSE) >>> c >>> [1] 52d33'24.624"W >>>> >>> The use of char2dms() function is not so easy because I cannot yet >>> read() the text file with the DMS coordinates (one col. with the >>> points names, lat col. and long. col.)!! >>> Cheers >>> Nicolas >>> Hello, >>> Here is the link to the archived versions of package measurements [1]. >>> But the edit to that answer has another solution, with sp::char2dms >>> and you are loading package sp. >>> [1] https://cran.hafro.is/src/contrib/Archive/measurements/ >>> <https://cran.hafro.is/src/contrib/Archive/measurements/> >>> Hope this helps, >>> Rui Barradas >>> ?s 10:57 de 25/04/2022, Nicolas Degallier escreveu: >>>> Hi Rui, >>>> Thanks for the information. >>>> Unfortunately, my versions of MacOS and of R are too old: >>>>> install.packages("measurements") >>>> Warning message: >>>> package ?measurements? is not available (for R version 3.2.1) >>>>> library(measurements) >>>> Warning message: >>>> le package ?measurements? a ?t? compil? avec la version R 3.2.5 >>>> There is no older package to do the same? >>>> Cheers >>>> Nicolas >>>> Le 25 avr. 2022 ? 11:12, Rui Barradas a ?crit : >>>>> Hello, >>>>> >>>>> See if this StackOverflow.com <http://StackOverflow.com> >>>>> <http://StackOverflow.com <http://StackOverflow.com>> post [1] >>>>> solves your problem. >>>>> >>>>> Also, examples should be minimal, you don't need all those packages >>>>> to solve this problem. >>>>> >>>>> >>>>> [1] https://stackoverflow.com/a/69485865/8245406 >>>>> <https://stackoverflow.com/a/69485865/8245406> >>>>> <https://stackoverflow.com/a/69485865/8245406 >>>>> <https://stackoverflow.com/a/69485865/8245406>> >>>>> >>>>> >>>>> Hope this helps, >>>>> >>>>> Rui Barradas >>>>> >>>>> ?s 21:43 de 24/04/2022, Nicolas Degallier escreveu: >>>>>> Dear R Users, >>>>>> I am using a 'simple' script to draw maps with points. >>>>>> It runs fine with the following libraries: >>>>>> library(sp) >>>>>> library(maptools) >>>>>> library(maps) >>>>>> library(mapdata) >>>>>> library(RColorBrewer) >>>>>> library(MASS) >>>>>> library(rgeos) >>>>>> library(GISTools) >>>>>> Until now, to prepare the input data, I have used manually some >>>>>> free net converter because the number of points to plot was not >>>>>> too high. >>>>>> Now I have much more points coordinates to convert from a GPS ? ' >>>>>> " (d m s) format to a decimal format which will be accepted by the >>>>>> R script to build maps. >>>>>> My initial data is of the form (tab delimited text file): >>>>>> nomlatlong >>>>>> "D. antoinei"6?04' S50?12'W >>>>>> "D. antoinei"3?45'S49?40'W >>>>>> "D. antoinei"3?1'49"N53?6'24"W >>>>>> "D. barberoi"13?03.3?S71?32.7?W >>>>>> "D. barberoi"10?59.3?S75?25.5?W" >>>>>> and I need them in the format (tab delimited): >>>>>> nomlatlong >>>>>> "D. antoinei"-11.944478527683975-71.28298997950684 >>>>>> "D. antoinei"-12.833333-69.333333 >>>>>> "D. antoinei"3.333333-60.283333 >>>>>> "D. barberoi"-10.366667-67.683333 >>>>>> "D. barberoi"-15.314500-55.970300 >>>>>> Is there some 'simple' R script to do such a conversion? >>>>>> I am using R v. 3.2.1. on a iMac OS 10.6.8. >>>>>> May be this topic had already been resolved but I was unable to >>>>>> find the result in the FAQs. >>>>>> Cheers >>>>>> Nicolas Degallier >>>>>> <nicolas.degallier at free.fr <mailto:nicolas.degallier at free.fr> >>>>>> <mailto:nicolas.degallier at free.fr <mailto:nicolas.degallier at free.fr>>> >>>>>> <omalodes at yahoo.fr <mailto:omalodes at yahoo.fr> >>>>>> <mailto:omalodes at yahoo.fr <mailto:omalodes at yahoo.fr>>> >>>>>> Publications : >>>>>> https://www.documentation.ird.fr/listes/parauteur/DEGALLIER/NICOLAS/tout/annee >>>>>> <https://www.documentation.ird.fr/listes/parauteur/DEGALLIER/NICOLAS/tout/annee> >>>>>> <https://www.documentation.ird.fr/listes/parauteur/DEGALLIER/NICOLAS/tout/annee >>>>>> <https://www.documentation.ird.fr/listes/parauteur/DEGALLIER/NICOLAS/tout/annee>> >>>>>> ______________________________________________ >>>>>> R-help at r-project.org <mailto:R-help at r-project.org> >>>>>> <mailto:R-help at r-project.org <mailto:R-help at r-project.org>> >>>>>> mailing list -- To UNSUBSCRIBE and more, see >>>>>> https://stat.ethz.ch/mailman/listinfo/r-help >>>>>> <https://stat.ethz.ch/mailman/listinfo/r-help> >>>>>> <https://stat.ethz.ch/mailman/listinfo/r-help >>>>>> <https://stat.ethz.ch/mailman/listinfo/r-help>> >>>>>> PLEASE do read the posting guide >>>>>> http://www.R-project.org/posting-guide.html >>>>>> <http://www.R-project.org/posting-guide.html> >>>>>> <http://www.R-project.org/posting-guide.html >>>>>> <http://www.R-project.org/posting-guide.html>> >>>>>> and provide commented, minimal, self-contained, reproducible code. >>>>>> >>>>>> ______________________________________________ >>>>>> R-help at r-project.org <mailto:R-help at r-project.org> mailing list -- >>>>>> To UNSUBSCRIBE and more, see >>>>>> https://stat.ethz.ch/mailman/listinfo/r-help >>>>>> <https://stat.ethz.ch/mailman/listinfo/r-help> >>>>>> PLEASE do read the posting guide >>>>>> http://www.R-project.org/posting-guide.html >>>>>> <http://www.R-project.org/posting-guide.html> >>>>>> and provide commented, minimal, self-contained, reproducible code. >