વિભાગ:Coordinates: આવૃત્તિઓ વચ્ચેનો તફાવત

Content deleted Content added
નાનું I missed a category
નાનુંNo edit summary
લીટી ૧૨:
 
Functions:
*function pcoordinates.LocationTemplateCore(frame)
**function pcoordinates.GeoHack_link(frame)
***function pcoordinates.lat_lon(frame)
****function pcoordinates._deg2dms(deg,lang)
***function pcoordinates.externalLink(frame)
****function pcoordinates._externalLink(site, globe, latStr, lonStr, lang, attributes)
**function pcoordinates._getHeading(attributes)
**function pcoordinates.externalLinksSection(frame)
***function pcoordinates._externalLink(site, globe, latStr, lonStr, lang, attributes)
*function pcoordinates.getHeading(frame)
*function pcoordinates.deg2dms(frame)
 
]]
 
coordinates = {};
 
-- =======================================
Line ૩૦ ⟶ ૩૨:
-- =======================================
local i18n = require('Module:I18n/coordinates') -- get localized translations of site names
local Fallback = require('Module:Fallback') -- get fallback functions
local yesno = require('Module:Yesno')
 
Line ૭૦ ⟶ ૭૩:
NNW = 337.5,
NBW = 348.75,
}
 
-- files to use for different headings
local heading_icon = {
[ 1] = 'File:Compass-icon bb N.svg',
[ 2] = 'File:Compass-icon bb NbE.svg',
[ 3] = 'File:Compass-icon bb NNE.svg',
[ 4] = 'File:Compass-icon bb NEbN.svg',
[ 5] = 'File:Compass-icon bb NE.svg',
[ 6] = 'File:Compass-icon bb NEbE.svg',
[ 7] = 'File:Compass-icon bb ENE.svg',
[ 8] = 'File:Compass-icon bb EbN.svg',
[ 9] = 'File:Compass-icon bb E.svg',
[10] = 'File:Compass-icon bb EbS.svg',
[11] = 'File:Compass-icon bb ESE.svg',
[12] = 'File:Compass-icon bb SEbE.svg',
[13] = 'File:Compass-icon bb SE.svg',
[14] = 'File:Compass-icon bb SEbS.svg',
[15] = 'File:Compass-icon bb SSE.svg',
[16] = 'File:Compass-icon bb SbE.svg',
[17] = 'File:Compass-icon bb S.svg',
[18] = 'File:Compass-icon bb SbW.svg',
[19] = 'File:Compass-icon bb SSW.svg',
[20] = 'File:Compass-icon bb SWbS.svg',
[21] = 'File:Compass-icon bb SW.svg',
[22] = 'File:Compass-icon bb SWbW.svg',
[23] = 'File:Compass-icon bb WSW.svg',
[24] = 'File:Compass-icon bb WbS.svg',
[25] = 'File:Compass-icon bb W.svg',
[26] = 'File:Compass-icon bb WbN.svg',
[27] = 'File:Compass-icon bb WNW.svg',
[28] = 'File:Compass-icon bb NWbW.svg',
[29] = 'File:Compass-icon bb NW.svg',
[30] = 'File:Compass-icon bb NWbN.svg',
[31] = 'File:Compass-icon bb NNW.svg',
[32] = 'File:Compass-icon bb NbW.svg'
}
 
Line ૧૧૨ ⟶ ૭૯:
local SiteURL = {
GeoHack = '//tools.wmflabs.org/geohack/geohack.php?pagename=$page&params=$lat_N_$lon_E_$attr&language=$lang',
GoogleEarth = '//tools.wmflabs.org/{{fullurl:toollabs:geocommons/earth.kml?|latdegdec=$lat&londegdec=$lon&scale=10000&commons=1}}',
Proximityrama = '//tools.wmflabs.org/{{fullurl:toollabs:geocommons/proximityrama?|latlon=$lat,$lon}}',
OpenStreetMap = '//tools.wmflabs.org/{{fullurl:toollabs:wiwosm/osm-on-ol/commons-on-osm.php?|zoom=16&lat=$lat&lon=$lon}}',
GoogleMaps = {
Mars = '//www.google.com/mars/#lat=$lat&lon=$lon&zoom=8',
Moon = '//www.google.com/moon/#lat=$lat&lon=$lon&zoom=8',
Earth = 'https://maps.google.com/maps?ll=$lat,$lon&spn=0.01,0.01&t=k&q=http://tools.wmflabs.org/geocommons/web.kml&hl=$lang'
}
}
Line ૧૨૭ ⟶ ૯૪:
Gallery = '[[Category:Galleries with coordinates]]',
Category = '[[Category:Categories with coordinates]]',
wikidata1 = '[[Category:Pages with local coordinates and matching wikidata coordinates]]',
wikidata2 = '[[Category:Pages with local coordinates and similar wikidata coordinates]]',
wikidata3 = '[[Category:Pages with local coordinates and mismatching wikidata coordinates]]',
wikidata4 = '[[Category:Pages with local coordinates and missing wikidata coordinates]]',
globe = '[[Category:Media with %s locations]]',
default = '[[Category:Media with default locations]]',
Line ૧૩૮ ⟶ ૧૦૧:
 
local NoLatLonString = 'latitude, longitude'
 
local function langSwitch(list,lang)
local langList = mw.language.getFallbacksFor(lang)
table.insert(langList,1,lang)
for i,language in ipairs(langList) do
if list[language] then
return list[language]
end
end
end
 
local function add_maplink(lat, lon, marker, text)
local tstr = ''
if text then
tstr = string.format('text="%s" ', text)
end
return string.format('<maplink %szoom="13" latitude="%f" longitude="%f">{'..
' "type": "Feature",'..
' "geometry": { "type":"Point", "coordinates":[%f, %f] },'..
' "properties": { "marker-symbol":"%s", "marker-size": "large", "marker-color": "0050d0" }'..
'}</maplink>', tstr, lat, lon, lon, lat, marker)
end
 
local function info_box(text)
return string.format('<table class="messagebox plainlinks layouttemplate" style="border-collapse:collapse; border-width:2px; border-style:solid; width:100%%; clear: both; '..
'border-color:#f28500; background:#ffe;direction:ltr; border-left-width: 8px; ">'..
'<tr>'..
'<td class="mbox-image" style="padding-left:.9em;">'..
' [[File:Commons-emblem-issue.svg|class=noviewer|45px]]</td>'..
'<td class="mbox-text" style="">%s</td>'..
'</tr></table>', text)
end
 
local function mergeWithWikidata(wikidata, lat1, lon1)
-- we are given wikidata q-code so look up the coordinates
local data = require('Module:Wikidata')
local args = {}
local cat = ''
args.property='P625'
args.item=wikidata
args.numval = 1
args.link = '-'
args.displayformat='latitude'
lat2 = data.formatStatements(args)
args.displayformat='longitude'
lon2 = data.formatStatements(args)
if not lat1 or not lon1 then -- wikidata coordinates only
return lat2, lon2, wikidata, cat
elseif lat1 and lon1 and not lat2 and not lon2 then
cat = string.format("The above coordinates are missing from linked Wikidata item [[d:%s|%s]]. Please copy them. "..
"You can use [http://tools.wmflabs.org/wikidata-todo/quick_statements.php QuickStatements] tool with string <code>%s P625 @%f/%f S143 Q565</code> after replacing spaces with tabs in a text editor. ",
wikidata, wikidata, wikidata, lat1, lon1)
cat = CoorCat.wikidata4 .. info_box(cat)
elseif lat1 and lon1 and lat2 and lon2 then
local dLat = math.rad(lat1-lat2)
local dLon = math.rad(lon1-lon2)
local d = math.pow(math.sin(dLat/2),2) + math.pow(math.sin(dLon/2),2) * math.cos(math.rad(lat1)) * math.cos(math.rad(lat2))
d = 2 * math.atan2(math.sqrt(d), math.sqrt(1-d)) -- angular distance in radians
d = 6371000 * d -- radians to meters conversion
local frame = mw.getCurrentFrame()
local info = frame:preprocess(add_maplink(lat2, lon2, 'marker')) -- fancy link to OSM
info = string.format("There is a discrepancy of %i meters between the above coordinates and the ones stored at linked Wikidata item [[d:%s|%s]] (%s). Please reconcile them. "..
"To copy Commons coordinates to Wikidata, you can use [http://tools.wmflabs.org/wikidata-todo/quick_statements.php QuickStatements] tool with string "..
"<code>%s P625 @%f/%f S143 Q565</code> after replacing spaces with tabs in a text editor. ",
math.floor(d+0.5), wikidata, wikidata, info, wikidata, lat1, lon1)
 
if d<20 then
cat = CoorCat.wikidata1
elseif d<1000 then
cat = CoorCat.wikidata2 .. info_box(info)
else
cat = CoorCat.wikidata3 .. info_box(info)
end
end
return lat1, lon1, wikidata, cat
end
 
-- =======================================
-- === Functions =========================
-- =======================================
p = {}
 
-- parse attribute variable returning desired field
function pcoordinates.parseAttribute(frame)
return string.match(mw.text.decode(frame.args[1]), mw.text.decode(frame.args[2]) .. ':' .. '([^_]*)') or ''
end
Line ૨૨૯ ⟶ ૧૧૫:
try to convert it to an angle
==============================================================================]]
function pcoordinates.getHeading(frame)
local attributes
if frame.args[1] then
Line ૨૩૮ ⟶ ૧૨૪:
return ''
end
local hNum = pcoordinates._getHeading(attributes)
if hNum == nil then
return ''
Line ૨૪૫ ⟶ ૧૩૧:
end
-- Helper core function for getHeading.
function pcoordinates._getHeading(attributes)
if attributes == nil then
return nil
Line ૨૭૨ ⟶ ૧૫૮:
3) language used in formating of the number
==============================================================================]]
function pcoordinates.deg2dms(frame)
local deg = tonumber(frame.args[1])
local degPrec = tonumber(frame.args[2]) or 0-- precision in degrees
local lang = frame.args.lang
if not (frame.args.lang and mw.language.isSupportedLanguage(frame.args.lang)) then
lang = frame:callParserFunction("int",".args.lang") -- get user's chosen language
else -- get user's chosen language
lang = mw.message.new( "lang" ):plain()
end
if deg==nil then
return frame.args[1];
else
return pcoordinates._deg2dms(deg, degPrec, lang)
end
end
Line ૨૯૪ ⟶ ૧૮૨:
* lang - language to used when formating the number
==============================================================================]]
function pcoordinates._deg2dms(deg, degPrec, lang)
local dNum, mNum, sNum, dStr, mStr, sStr, formatStr, secPrec, c, k
local Lang = mw.language.new(lang)
Line ૩૪૪ ⟶ ૨૩૨:
* prec = geolocation precission in meters
==============================================================================]]
function pcoordinates.lat_lon(frame)
local lat = tonumber(frame.args.lat)
local lon = tonumber(frame.args.lon)
Line ૩૫૪ ⟶ ૨૪૨:
end
end
local lang = frame.args.lang
if not (frame.args.lang and mw.language.isSupportedLanguage(frame.args.lang)) then
lang = frame:callParserFunction("int",".args.lang") -- get user's chosen language
else -- get user's chosen language
lang = mw.message.new( "lang" ):plain()
end
if lat==nil or lon==nil then
return NoLatLonString
else
local nsew = langSwitchFallback._langSwitch(i18n.NSEW, lang) -- find set of localized translation of N, S, W and E in the desired language
local SN, EW, latStr, lonStr, lon2m, lat2m, phi
if lat<0 then SN = nsew.S else SN = nsew.N end -- choose S or N depending on latitude degree sign
Line ૩૭૨ ⟶ ૨૬૨:
lat2m = 111000 -- average latitude degree size in meters
end
latStr = pcoordinates._deg2dms(math.abs(lat), prec/lat2m, lang) -- Convert latitude degrees to degrees/minutes/seconds
lonStr = pcoordinates._deg2dms(math.abs(lon), prec/lon2m, lang) -- Convert longitude degrees to degrees/minutes/seconds
return string.format('%s&nbsp;%s, %s&nbsp;%s', latStr, SN, lonStr, EW)
--return string.format('<span class="latitude">%s %s</span>, <span class="longitude">%s %s</span>', latStr, SN, lonStr, EW)
Line ૩૯૧ ⟶ ૨૮૧:
* attributes = attributes to be passed to GeoHack
==============================================================================]]
function pcoordinates.externalLink(frame)
args = frame.args
localif args.lang =and framemw.language.isSupportedLanguage(args.lang) then
lang = args.lang
if not (lang and mw.language.isSupportedLanguage(lang)) then
lang = frame:callParserFunction("int","lang") else -- get user's chosen language
lang = mw.message.new( "lang" ):plain()
end
returnlocal pstr = coordinates._externalLink(args.site or 'GeoHack', args.globe or 'Earth', args.lat, args.lon, lang, args.attributes or '')
return frame:preprocess(str)
end
Line ૪૧૨ ⟶ ૩૦૪:
* attributes = attributes to be passed to GeoHack
==============================================================================]]
function pcoordinates._externalLink(site, globe, latStr, lonStr, lang, attributes)
local URLstr = SiteURL[site];
if site == 'GoogleMaps' then
Line ૪૩૭ ⟶ ૩૨૯:
* mode = set by each calling template
==============================================================================]]
function pcoordinates.alterAttributes(attributes, mode)
-- indicate which template called it
if mode=='camera' then -- Used by {{Location}} and {{Location dec}}
Line ૪૬૮ ⟶ ૩૬૦:
* attributes = attributes to be passed to GeoHack
==============================================================================]]
function pcoordinates.GeoHack_link(frame)
-- create link and coordintate string
local latlon = pcoordinates.lat_lon(frame)
if latlon==NoLatLonString then
return latlon
else
frame.args.site = 'GeoHack'
local url = pcoordinates.externalLink(frame)
return string.format('<span class="plainlinksneverexpand">[%s %s]</span>', url, latlon) --<span class="plainlinks nourlexpansion">
end
Line ૪૯૩ ⟶ ૩૮૫:
* namespace = namespace name: File, Category, (Gallery)
==============================================================================]]
function pcoordinates.externalLinksSection(frame)
local args = frame.args
localif args.lang =and framemw.language.isSupportedLanguage(args.lang) then
lang = args.lang
if not (lang and mw.language.isSupportedLanguage(lang)) then
lang = frame:callParserFunction("int","lang") else -- get user's chosen language
lang = mw.message.new( "lang" ):plain()
end
if not args.namespace then
Line ૫૦૩ ⟶ ૩૯૬:
end
local str, link1, link2
if args.globe=='Earth' then -- Earth locations will have 3 or 4 links
str = string.format('[%s %s] - [%s %s]', -- - [%s %s]',
link1 = p._externalLink('OpenStreetMap', 'Earth', args.lat, args.lon, lang, '')
link2 = p coordinates._externalLink('GoogleEarthOpenStreetMap' , 'Earth', args.lat, args.lon, lang, ''),
Fallback._langSwitch(i18n.OpenStreetMaps, lang),
-- GoogleMap link no longer works due to changes in the website software
-- GoogleMap link no longer works due to changes in the website software
-- link3 = p._externalLink('GoogleMaps' , 'Earth', args.lat, args.lon, lang, '') %langSwitch(i18n.GoogleMaps, lang)
--coordinates._externalLink('GoogleMaps' , 'Earth', args.lat, args.lon, lang, ''),
str = string.format('[%s %s] - [%s %s]',
link1, langSwitch--Fallback._langSwitch(i18n.OpenStreetMapsGoogleMaps, lang),
coordinates._externalLink('GoogleEarth' , 'Earth', args.lat, args.lon, lang, ''),
link2, langSwitch(i18n.GoogleEarth, lang))
Fallback._langSwitch(i18n.GoogleEarth, lang))
if args.namespace=="Category" then
str = string.format('%s - [%s %s]', str,
link1 = p._externalLink('Proximityrama', 'Earth', args.lat, args.lon, lang, '')
coordinates._externalLink('Proximityrama', 'Earth', args.lat, args.lon, lang, ''),
str = string.format('%s - [%s %s]', str, link1, langSwitch(i18n.Proximityrama, lang))
Fallback._langSwitch(i18n.Proximityrama, lang))
end
elseif args.globe=='Mars' or args.globe=='Moon' then
link1str = pstring.format('[%s %s]',
coordinates._externalLink('GoogleMaps', args.globe, args.lat, args.lon, lang, ''),
str = string Fallback.format('[%s %s]', link1, langSwitch_langSwitch(i18n.GoogleMaps, lang))
end
return frame:preprocess(str) -- use preprocess to expand {{#fullurl}}
return str
--return str
end
 
Line ૫૩૯ ⟶ ૪૩૬:
* prec = geolocation precission in meters
==============================================================================]]
function pcoordinates.LocationTemplateCore(frame)
-- prepare arguments
args = frame.args
Line ૫૪૬ ⟶ ૪૪૩:
end
if not (args.lang and mw.language.isSupportedLanguage(args.lang)) then
args.lang = frame:callParserFunctionmw.message.new("int", "lang" ):plain() -- get user's chosen language
end
if not (args.namespace) then -- if namespace not provided than look it up
Line ૫૫૯ ⟶ ૪૫૬:
Status = 'secondary'
end
args.attributes = pcoordinates.alterAttributes(args.attributes or '', args.mode)
-- check for errors and add Geo (microformat) code for machine readability.
-- Convert coordinates from string to numbers
local lat = tonumber(args.lat)
local lon = tonumber(args.lon)
if args.wikidata and args.wikidata~='' and (not lat or not lon) then
if lon then -- get longitude to be in -180 to 180 range
-- if lat/lon is not provided but we are given wikidata q-code than look up the coordinates
local data = require('Module:Wikidata')
local args2 = {}
args2.property='P625'
args2.item=args.wikidata
args2.numval = 1
args2.link = '-'
args2.displayformat='latitude'
lat = data.formatStatements(args2)
args2.displayformat='longitude'
lon = data.formatStatements(args2)
end
if lon then -- get longitude to be in -180 to 180 range
lon=lon%360
if lon>180 then
Line ૫૭૦ ⟶ ૪૮૦:
end
end
-- If wikidata link provided than compare coordinates
local Categories, geoMicroFormat, coorTag, wikidata_link = '', '', '', ''
if args.wikidata and args.wikidata~='' then
-- if lat/lon is not provided but we are given wikidata q-code than look up the coordinates
lat, lon, q, Categories = mergeWithWikidata(args.wikidata, lat, lon)
wikidata_link = string.format("\n[[File:Wikidata-logo.svg|20px|Edit coordinates on Wikidata|link=wikidata:%s]]",q,q);
end
 
args.lat = string.format('%010.6f', lat or 0)
args.lon = string.format('%011.6f', lon or 0)
frame.args = args
local Categories, geoMicroFormat, coorTag = '', '', ''
 
-- Categories, {{#coordinates}} and geoMicroFormat will be only added to File, Category and Gallery pages
Line ૫૮૭ ⟶ ૪૮૯:
if lat and lon then -- if lat and lon are numbers...
if lat==0 and lon==0 then -- lat=0 and lon=0 is a common issue when copying from flickr and other sources
Categories = Categories .. CoorCat.default
end
if frame.args.attributes and string.find(frame.args.attributes, '=') then
Line ૬૧૬ ⟶ ૫૧૮:
 
-- Call helper functions to render different parts of the template
local coorstr1, str2, info_linkstr3, str4, inner_table, heading, OSM = '','','','','','',''
coorstr1 = pcoordinates.GeoHack_link(frame) -- the pcoordinates and link to GeoHack
heading = pcoordinates._getHeading(frame.args.attributes) -- get heading arrow section
if heading then
--str1 = string.format('%s&nbsp;&nbsp;<span style="{{Transform-rotate|%f}}">[[File:North Pointer.svg|20px|link=|alt=]]</span>', str1, 360-heading)
local k = math.fmod(math.floor(0.5+math.fmod(heading+360,360)/11.25),32)+1
local fname = string.format('{{Compass rose file|%f|style=heading}}', heading)
local fname = heading_icon[k]
coorstr1 = string.format('%s&nbsp;&nbsp;<span title="%s°">[[%s|25px|link=|alt=Heading=%s°]]</span>', coorstr1, heading, fname, heading)
end
str2 = Fallback._langSwitch(i18n.LocationTemplateLinkLabel, args.lang) -- header of the link section
if args.globe=='Earth' then
str3 = coordinates.externalLinksSection(frame) or '' -- external link section
local icon = 'marker'
str4 = string.format('[[File:Circle-information.svg|18x18px|alt=info|link=%s]]', Fallback._langSwitch(i18n.COM_GEO, args.lang) )
if args.mode=='camera' then
inner_table = string.format('<td style="border:none;">%s</td><td style="border:none;">%s %s</td><td style="border:none;">%s%s</td>', str1, str2, str3, str4, geoMicroFormat)
icon = 'camera'
end
OSM = frame:preprocess(add_maplink(args.lat, args.lon, icon, '[[File:Openstreetmap logo.svg|20px|link=]]')) -- fancy link to OSM
end
external_link = p.externalLinksSection(frame) -- external link section
if external_link then
external_link = langSwitch(i18n.LocationTemplateLinkLabel, args.lang) .. ' ' .. external_link -- header of the link section
end
info_link = string.format('[[File:Circle-information.svg|18x18px|alt=info|link=%s]]', langSwitch(i18n.COM_GEO, args.lang) )
inner_table = string.format('<td style="border:none;">%s&nbsp;%s</td><td style="border:none;">%s</td><td style="border:none;">%s%s%s</td>',
coor, OSM, external_link or '', info_link, wikidata_link, geoMicroFormat)
-- combine strings into a table
Line ૬૪૭ ⟶ ૫૩૯:
local field_name = 'Location'
if args.mode=='camera' then
field_name = langSwitchFallback._langSwitch(i18n.CameraLocation, args.lang)
elseif args.mode=='object' then
field_name = langSwitchFallback._langSwitch(i18n.ObjectLocation, args.lang)
elseif args.mode=='globe' then
field_list = langSwitchFallback._langSwitch(i18n.GlobeLocation, args.lang)
if args.globe and i18n.GlobeLocation['en'][args.globe] then -- verify globe is provided and is recognized
field_name = field_list[args.globe]
end
end
local style = frame:expandTemplate{ title="Infobar-Layout", args={ ["lang"] = lang, ["class"] = 'commons-file-information-table' } }
--Create HTML text
templateText = string.format('<table lang="%s" %s><tr><th class="type fileinfo-paramfield">%s</th>%s</tr></table>', lang, style, field_name, inner_table)
local dir, text_align
if mw.language.new( args.lang ):isRTL() then
dir = 'rtl'
text_align = 'right'
else
dir = 'ltr'
text_align = 'left'
end
local style = string.format('class="toccolours mw-content-%s layouttemplate commons-file-information-table" cellpadding="2" style="width: 100%%; direction:%s;" lang="%s"',
args.lang, dir, text_align, args.lang)
templateText = string.format('<table lang="%s" %s><tr><th class="type fileinfo-paramfield">%s</th>%s</tr></table>',
args.lang, style, field_name, inner_table)
end
return frame:preprocess(templateText .. Categories .. coorTag)
end
 
return pcoordinates