Modul:CoordinateConverter

A modult a Modul:CoordinateConverter/doc lapon tudod dokumentálni

-- Module to convert Wikidata coordinates to decimal latitude and longitude

local p = {}

-- Function to convert degrees, minutes, and seconds to decimal degrees
local function dms_to_decimal(dms)
    local degrees, minutes, seconds = string.match(dms, "(%d+)°%s?(%d+)'%s?(%d+%.?%d*)")
    degrees = tonumber(degrees)
    minutes = tonumber(minutes)
    seconds = tonumber(seconds)
    local decimal = degrees + minutes / 60 + seconds / 3600
    return decimal
end

-- Function to convert the coordinate string to decimal latitude and longitude
function p.convertCoordinates(frame)
    local coord_string = frame.args[1] or ''
    local lat, lon = string.match(coord_string, "([%d%.]+°?%s?[%d%.]+'?%s?[%d%.]*\"?%s?[NS]),%s?([%d%.]+°?%s?[%d%.]+'?%s?[%d%.]*\"?%s?[EW])")
    local lat_decimal = dms_to_decimal(lat)
    local lon_decimal = dms_to_decimal(lon)
    return lat_decimal, lon_decimal
end

function p.lat(frame)
    local coord_string = frame.args[1] or ''
    local lat, lon = string.match(coord_string, "([%d%.]+°?%s?[%d%.]+'?%s?[%d%.]*\"?%s?[NS]),%s?([%d%.]+°?%s?[%d%.]+'?%s?[%d%.]*\"?%s?[EW])")
    local lat_decimal = dms_to_decimal(lat)
    local lon_decimal = dms_to_decimal(lon)
    return lat_decimal
end

function p.long(frame)
    local coord_string = frame.args[1] or ''
    local lat, lon = string.match(coord_string, "([%d%.]+°?%s?[%d%.]+'?%s?[%d%.]*\"?%s?[NS]),%s?([%d%.]+°?%s?[%d%.]+'?%s?[%d%.]*\"?%s?[EW])")
    local lat_decimal = dms_to_decimal(lat)
    local lon_decimal = dms_to_decimal(lon)
    return   lon_decimal
end
return p