Sintaxe
M
fnGrausParaDecimais(graus as nullable text) as nullable numberParâmetros
- grausnullable textObrigatório
Coordenada no formato G°M'S"D, com D = N, S, E, L, W ou O.
M"23°34'45""S"
Tipo de retorno
nullable number
Exemplos
M
fnGrausParaDecimais("23°34'45""S")
// -23.5791666666667
fnGrausParaDecimais("46°37'14""W")
// -46.6205555555556
fnGrausParaDecimais("12°15'30""N")
// 12.2583333333333Código completo
M
let
fnGrausParaDecimais = (graus as nullable text) as nullable number =>
let
// Padroniza símbolos: ′ ’ → ' ″ ” '' → " vírgula → ponto
vTexto = Text.Upper(Text.Trim(List.Accumulate(
{{"′", "'"}, {"’", "'"}, {"″", """"}, {"”", """"}, {"''", """"}, {",", "."}},
graus ?? "",
(t, par) => Text.Replace(t, par{0}, par{1})
))),
fnNumero = (t as text) as number => Number.FromText(Text.Trim(t), "en-US"),
vGraus = Number.Abs(fnNumero(Text.BeforeDelimiter(vTexto, "°"))),
vMinutos = fnNumero(Text.BetweenDelimiters(vTexto, "°", "'")),
vSegundos = fnNumero(Text.BetweenDelimiters(vTexto, "'", """")),
vNegativo = List.Contains({"S", "W", "O"}, Text.End(vTexto, 1)) or Text.StartsWith(vTexto, "-")
in
if graus = null then null
else (vGraus + vMinutos / 60 + vSegundos / 3600) * (if vNegativo then -1 else 1),
Documentacao = [
Documentation.Name = "fnGrausParaDecimais",
Documentation.Description = "Converte coordenada em graus, minutos e segundos para grau decimal.",
Documentation.LongDescription = "Formato esperado: G°M'S""D, com D = N, S, E, L, W ou O. S, W, O ou sinal negativo geram valor negativo. Lê números com ponto ou vírgula decimal, independente da cultura do arquivo.",
Documentation.Category = "Geografia",
Documentation.Author = "Paulo André Jesus",
Documentation.Version = "2.0",
Documentation.Examples = {
[Description = "Latitude sul", Code = "fnGrausParaDecimais(""23°34'45""""S"")", Result = "-23.5791666666667"],
[Description = "Longitude oeste", Code = "fnGrausParaDecimais(""46°37'14""""W"")", Result = "-46.6205555555556"],
[Description = "Latitude norte", Code = "fnGrausParaDecimais(""12°15'30""""N"")", Result = "12.2583333333333"]
}
]
in
Value.ReplaceType(fnGrausParaDecimais, Value.ReplaceMetadata(Value.Type(fnGrausParaDecimais), Documentacao))Mais informações
- Fonte
- Paulo André Jesus — OfficeTuning
- Versão
- 2.0