Module:Infobox dim
Appearance
| This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing. |
| This module is currently protected from editing. See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected. |
| This Lua module is used on approximately 369,000 pages. To avoid major disruption and server load, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Consider discussing changes on the talk page before implementing them. |
Code to convert information about physical size of objects into parameters for geohack or mapframes.
The following parameters describe the physical object size:
- length_km
- length_mi
- width_km
- width_mi
- area_km2
- area_mi2
- area_ha
- area_acre
When producing scale or zoom, module can use size of object on screen specified via |viewport_cm= or |viewport_px=. Defaults to 10cm, to match geohack.
In addition, the module can accept and convert between geohack parameters:
- dim
- scale
- type (e.g., "mountain" or "city")
- population (for type="city" only)
Usage
{{#invoke:Infobox dim|dim}}
Generates dim string (e.g, "24km") suitable for geohack link
{{#invoke:Infobox dim|scale}}
Generates scale (e.g, 100000) suitable for geohack link
{{#invoke:Infobox dim|zoom}}
Generates Open Street Map zoom level (e.g, 12) suitable for use in mapframes
--[[
geohackTypeToScale
Convert from Geohack's scale and dim levels to OSM style zoom levels as used by <maplink>
]]
local function geohackScaleToMapZoom(scale)
scale = tonumber(scale)
if not scale or scale <= 0 then return end
-- Approximation of https://wiki.openstreetmap.org/wiki/Zoom_levels
-- pixel/m from OSM is exact, so use zoom level 9 and 0.3 mm/pixel
return math.log(305.748*ppm/scale)/log2 + 9
end
local function geohackDimToScale(dim, units)
dim = tonumber(dim)
if not dim or dim <= 0 then return end
if units and string.lower(units) == 'km' then
dim = dim*1000
end
-- Using 0.3 mm/pixel from https://wiki.openstreetmap.org/wiki/Zoom_levels, and
-- assuming dim spans a map width of 800px (= 24cm on screen)
return ppm/800 * dim
end
--[[
geohackTypeToScale
Convert from Geohack's types to Geohack's scale levels
]]
local function geohackTypeToScale(type, population)
local typeScale = {
adm1st = 1000000,
adm2nd = 300000,
adm3rd = 100000,
airport = 30000,
city = 100000,
country = 10000000,
edu = 10000,
event = 50000,
forest = 50000,
glacier = 50000,
isle = 100000,
landmark = 10000,
mountain = 100000,
pass = 10000,
railwaystation = 10000,
river = 100000,
satellite = 10000000,
waterbody = 100000,
camera = 10000
}
local scale
if typeScale[type] then
scale = typeScale[type]
end
population = tonumber(population)
if type == 'city' and population and population > 0 then
-- assume city is a circle with density of 1000/square kilometer
-- compute diameter, in meters
local diam = 35.68*math.sqrt(population)
-- convert to scale
scale = geohackDimToScale(diam)
-- don't zoom in too far
if scale < 25000 then
scale = 25000
end
end
return scale
end