Modul:Karte/Work: Unterschied zwischen den Versionen

keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
(5 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 24: Zeile 24:
-- =p.karte(mw.getCurrentFrame(), {pagename="Zum Adler", location="Restaurant Zum Adler, Fürth, Bayern, Deutschland"})
-- =p.karte(mw.getCurrentFrame(), {pagename="Zum Adler", location="Restaurant Zum Adler, Fürth, Bayern, Deutschland"})
local t = ""
local t = ""
local pagename = args["pagename"] or wik.pagename() -- nur zum Debugging pagename vorgebbar
local geoobjects = {}
local kategorien = {}
local pagename = args["pagename"] or wik.pagename() -- nur zum Debuggen pagename vorgebbar


-- geocode location and locationlist
-- geocode location and locationlist
local geoobjects = {}
local minimum_one_geocode_ok = false -- Flag, dass mindestens ein geocode erfolgreich war
local minimum_one_geocode_ok = false
-- locationlist und location zusammenführen
-- locationlist und location zusammenführen
local locations_merged = str.splitAndStrip(args["locationlist"] or "", ";")
local locationlist = str.splitAndStrip(args["locationlist"] or "", ";")
local location = str.strip(args["location"] or "")
table.insert(locationlist,
if location ~= "" then
(args["location"] or "") .. "~" ..
table.insert(locations_merged, args["location"] ..
(args["popuptitle"] or "") .. "~" ..
"~" .. (args["popuptitle"] or "") ..
(args["popuptext"] or ""))
"~" .. (args["popuptext"] or ""))
end
-- alle locations durchiterieren und für jedes ein subobject erstellen
-- alle locations durchiterieren und für jedes ein subobject erstellen
for _, l in ipairs(locations_merged) do
for _, l in ipairs(locationlist) do
local geoobject_entry = {}
-- Aufteilung location ~ popuptitle ~ popuptext
-- Aufteilung location ~ popuptitle ~ popuptext
l = str.split2(l, "~")
l = str.split2(l, "~")
Zeile 45: Zeile 43:
local popuptitle = str.strip(l[2] or "")
local popuptitle = str.strip(l[2] or "")
local popuptext = str.strip(l[3] or "")
local popuptext = str.strip(l[3] or "")
-- Prüfung Koordinate (Zahl) oder textuelle Objektlokation
-- wenn Objektlokation und Ehemals, dann nicht auswerten
if location ~= "" and
  string.match(location, "%d") == nil and
  com.isTrue(args["Ehemals"]) then
location = ""
t = t .. "[[Kategorie:Hat Objektlokation, ist aber ehemaliges Objekt]]"
end
-- location geocode
if location ~= "" then
if location ~= "" then
geoobject_entry["Geolokation"] = location
local geoobject_entry = {["Geolokation"] = location}
local geocode = geocode(frame, location)
-- Prüfung Koordinate (Zahl) oder textuelle Objektlokation
if geocode ~= "Geocoding failed" then
-- wenn Objektlokation und Ehemals, dann nicht auswerten
geoobject_entry["Geokoordinate"] = geocode
if string.match(location, "%d") == nil and -- Keine-Zahl-Erkennung
minimum_one_geocode_ok = true
  com.isTrue(args["Ehemals"]) then
kategorien["Hat Objektlokation, ist aber ehemaliges Objekt"] = true
else
else
t = t .. "[[Kategorie:Hat Geo-Kodierungsfehler]]"
-- location geocode
smw_geokoordinate = mw.smw.ask(
local geocode = geocode(frame, location)
"[[-Has subobject::" .. pagename .. "]]" ..
if geocode ~= "Geocoding failed" then
"[[Geolokation::" .. location .. "]]" ..
geoobject_entry["Geokoordinate"] = geocode
"|?Geokoordinate|limit=1")
geoobject_entry["Quellangaben"] = "location"
if smw_geokoordinate ~= nil and
smw_geokoordinate[1]["Geokoordinate"] ~= nil then
t = t .. "[[Kategorie:Hat Geo-Kodierungsfehler, aber noch Geokoordinate in SMW-DB]]"
geoobject_entry["Geokoordinate"] =
smw_geokoordinate[1]["Geokoordinate"]
minimum_one_geocode_ok = true
minimum_one_geocode_ok = true
end
else
end
-- geocode nicht erfolgreich => SMW-DB nehmen, sofern vorhanden
end
kategorien["Hat Geo-Kodierungsfehler"] = true
geoobject_entry["KartePopupTitle"] = popuptitle
local smw_geokoordinate = mw.smw.ask(
geoobject_entry["KartePopupText"] = popuptext
"[[-Has subobject::" .. pagename .. "]]" ..
geoobjects:insert(geoobject_entry)
"[[Geolokation::" .. location .. "]]" ..
end
"|?Geokoordinate|limit=1") or {{}}
smw_geokoordinate = smw_geokoordinate[1]["Geokoordinate"]
if smw_geokoordinate ~= nil then
-- SMW-DB Geokoordinate übernehmen
kategorien["Hat Geo-Kodierungsfehler, aber Geokoordinate in SMW-DB noch vorhanden"] = true
geoobject_entry["Geokoordinate"] = smw_geokoordinate
geoobject_entry["Quellangaben"] = "SMW-DB"
minimum_one_geocode_ok = true
end
end -- if geocode ~= "Geocoding failed" then
end -- if Zahlerkennung
set_popuptitle_popuptext(geoobject_entry, popuptitle, popuptext)
table.insert(geoobjects, geoobject_entry)
end -- if location ~= "" then
end -- for _, l in ipairs(locations_merged) do


-- geocode lon/lat
-- geocode lon/lat, nur wenn location/locationlist nicht erfolgreich oder ehemals
if (not minimum_one_geocode_ok or com.isTrue(args["Ehemals"])) and args["lat"] ~= nil and args["lon"] ~= nil then
if (not minimum_one_geocode_ok or com.isTrue(args["Ehemals"])) and  
  not com.isEmpty(args["lat"]) and not com.isEmpty(args["lon"]) then
local geoobject_entry = {}
local geocode = geocode(frame, args["lat"] .. "," .. args["lon"])
local geocode = geocode(frame, args["lat"] .. "," .. args["lon"])
if geocode ~= "Geocoding failed" then
if geocode ~= "Geocoding failed" then
local geoobject_entry = {["Geokoordinate"] = geocode}
geoobject_entry["Geokoordinate"] = geocode
geoobject_entry["KartePopupTitle"] = popuptitle
geoobject_entry["Quellangaben"] = "lat/lon"
geoobject_entry["KartePopupText"] = popuptext
else
geoobjects:insert(geoobject_entry)
kategorien["Hat Geo-Kodierungsfehler"] = true
end
end
set_popuptitle_popuptext(geoobject_entry, popuptitle, popuptext)
table.insert(geoobjects, geoobject_entry)
end
end
-- geoobjects setzen
-- subobjects setzen
mw.logObject(geoobjects, "geoobjects")
mw.logObject(geoobjects, "geoobjects")
for _, o in ipairs(geoobjects) do
for _, o in ipairs(geoobjects) do
Zeile 101: Zeile 104:
-- bisherige Vorlagen-Karte
-- bisherige Vorlagen-Karte
t = t .. frame:expandTemplate{title = "Karte/Legacy", args = args}
t = t .. frame:expandTemplate{title = "Karte/Legacy", args = args}
-- Kategorien setzen
for k, _ in pairs(kategorien) do
t = t .. "[[Kategorie:" .. k .. "]]"
end


mw.logObject(t, "t")
mw.logObject(t, "t")
Zeile 106: Zeile 114:
end
end


function geocode(frame, l)
function geocode(frame, location)
return frame:callParserFunction(
return frame:callParserFunction(
"#geocode", {l, format="float", directional="no"})
"#geocode", {location, format="float", directional="no"})
end
end


function set_popuptitle_popuptext(geoobject_entry, popuptitle, popuptext)
function set_popuptitle_popuptext(geoobject_entry, popuptitle, popuptext)
if not com.isEmpty(popuptitle) then
geoobject_entry["KartePopupTitle"] = popuptitle
end
if not com.isEmpty(popuptext) then
geoobject_entry["KartePopupText"] = popuptext
end
end
end


return p
return p