Template:Rapid transit OSM map: Difference between revisions
No edit summary |
Startupedia (talk | contribs) m 1 revision imported |
(No difference)
|
Latest revision as of 14:06, 22 May 2025
The template generally works if the lines that make up the system have their own Wikidata entries (e.g. (Q7388350) for Zürich S-Bahn), and the entries are connected to an OpenStreetMap line child feature.
Each Wikidata line entity's (P5817) should be (Q55654238) and should include the (P16) property (for instance on the (Q7388350) entity, (P16) -> (Q636091)).
This is a wrapper for Template:Maplink. It fetches `geoline` features and shows them within the template. The template works through a SPARQL Wikidata query. The vital field is `system_qid`, which determines the central item from which all other data is pulled.
First, try this on the Wikipedia page of an item that is supposed to show up on the map (e.g. a metro line):
<syntaxhighlight lang="wikitext"><mapframe height="200" text="Map" width="300">{"properties":{"stroke-width":2,"stroke":"#ff0000","title":"Rapid transit OSM map"},"type":"ExternalData","service":"geoline"}</mapframe></syntaxhighlight>
If it's not displayed, the item might not yet be linked to an OSM feature.
Usage
<syntaxhighlight lang="wikitext"> <mapframe height="200" text="Map" width="300">[ { "type": "ExternalData", "service": "geoline", "properties": { "stroke-width": }, "query": "SELECT ?id (if(BOUND(?idhexcolor), concat('#', str(?idhexcolor)), if(BOUND(?hexcolor), concat('#', str(?hexcolor)), '#07c63e')) as ?stroke) (concat('Line length: ', str(?length), ' km') as ?description) (if(BOUND(?link), concat('', ?idLabel, ''), ?idLabel) as ?title) WHERE { VALUES ?sys { wd: } { ?id p:P5817/ps:P5817 wd:Q55654238. ?id wdt:P16/wdt:P361* ?sys. } MINUS { VALUES ?rem { wd:Q548662 wd:Q55697304 } ?id wdt:P31/wdt:P279* ?rem. } OPTIONAL { ?id wdt:P465 ?idhexcolor. } OPTIONAL { ?id wdt:P462 ?color. ?color wdt:P465 ?hexcolor.} SERVICE wikibase:label { bd:serviceParam wikibase:language 'en,mul' . ?id rdfs:label ?idLabel . } OPTIONAL {?link schema:about ?id. ?link schema:isPartOf <https://en.wikipedia.org/> . } } GROUP BY ?id ?link ?idLabel ?length ?hexcolor ?idhexcolor "}, ]</mapframe>
</syntaxhighlight>
Examples
Rapid transit system
Frankfurt
<mapframe zoom="10" align="left" text="Frankfurt" height="440" width="500">[ { "type": "ExternalData", "service": "geoline", "properties": { "stroke-width": 4 }, "query": "SELECT ?id (if(BOUND(?idhexcolor), concat('#', str(?idhexcolor)), if(BOUND(?hexcolor), concat('#', str(?hexcolor)), '#07c63e')) as ?stroke) (concat('Line length: ', str(?length), ' km') as ?description) (if(BOUND(?link), concat('', ?idLabel, ''), ?idLabel) as ?title) WHERE { VALUES ?sys { wd:Q705684 } { ?id p:P5817/ps:P5817 wd:Q55654238. ?id wdt:P16/wdt:P361* ?sys. } MINUS { VALUES ?rem { wd:Q548662 wd:Q55697304 } ?id wdt:P31/wdt:P279* ?rem. } OPTIONAL { ?id wdt:P465 ?idhexcolor. } OPTIONAL { ?id wdt:P462 ?color. ?color wdt:P465 ?hexcolor.} SERVICE wikibase:label { bd:serviceParam wikibase:language 'en,mul' . ?id rdfs:label ?idLabel . } OPTIONAL {?link schema:about ?id. ?link schema:isPartOf <https://en.wikipedia.org/> . } } GROUP BY ?id ?link ?idLabel ?length ?hexcolor ?idhexcolor "}, ]</mapframe>
Moscow
<mapframe text="Moscow" align="left" longitude="37.6" latitude="55.75" height="440" width="500">[ { "type": "ExternalData", "service": "geoline", "properties": { "stroke-width": 4 }, "query": "SELECT ?id (if(BOUND(?idhexcolor), concat('#', str(?idhexcolor)), if(BOUND(?hexcolor), concat('#', str(?hexcolor)), '#07c63e')) as ?stroke) (concat('Line length: ', str(?length), ' km') as ?description) (if(BOUND(?link), concat('', ?idLabel, ''), ?idLabel) as ?title) WHERE { VALUES ?sys { wd:Q5499 } { ?id p:P5817/ps:P5817 wd:Q55654238. ?id wdt:P16/wdt:P361* ?sys. } MINUS { VALUES ?rem { wd:Q548662 wd:Q55697304 } ?id wdt:P31/wdt:P279* ?rem. } OPTIONAL { ?id wdt:P465 ?idhexcolor. } OPTIONAL { ?id wdt:P462 ?color. ?color wdt:P465 ?hexcolor.} SERVICE wikibase:label { bd:serviceParam wikibase:language 'en,mul' . ?id rdfs:label ?idLabel . } OPTIONAL {?link schema:about ?id. ?link schema:isPartOf <https://en.wikipedia.org/> . } } GROUP BY ?id ?link ?idLabel ?length ?hexcolor ?idhexcolor "}, ]</mapframe>
A specific line of a system
<mapframe zoom="11" text="Zurich S6" align="left" height="440" latitude="47.34" longitude="8.57" width="400">[ { "type": "ExternalData", "service": "geoline", "properties": { "stroke-width": 4 }, "query": "SELECT ?id (if(BOUND(?idhexcolor), concat('#', str(?idhexcolor)), if(BOUND(?hexcolor), concat('#', str(?hexcolor)), '#07c63e')) as ?stroke) (concat('Line length: ', str(?length), ' km') as ?description) (if(BOUND(?link), concat('', ?idLabel, ''), ?idLabel) as ?title) WHERE { VALUES ?sys { wd:Q7388350 } { ?id p:P5817/ps:P5817 wd:Q55654238. ?id wdt:P16 */wdt:P361* ?sys. } MINUS { VALUES ?rem { wd:Q548662 wd:Q55697304 } ?id wdt:P31/wdt:P279* ?rem. } OPTIONAL { ?id wdt:P465 ?idhexcolor. } OPTIONAL { ?id wdt:P462 ?color. ?color wdt:P465 ?hexcolor.} SERVICE wikibase:label { bd:serviceParam wikibase:language 'en,mul' . ?id rdfs:label ?idLabel . } OPTIONAL {?link schema:about ?id. ?link schema:isPartOf <https://en.wikipedia.org/> . } } GROUP BY ?id ?link ?idLabel ?length ?hexcolor ?idhexcolor "}, { "type": "ExternalData", "service": "geopoint", "properties": { "marker-symbol": "rail-metro", "marker-size" : "small"}, "query": "SELECT DISTINCT ?id ?geo ?marker_color (if(BOUND(?image), concat('File:', substr(str(?image), 52, 400), ''), ?typeLabel) as ?description) (if(BOUND(?link), concat('', ?idLabel, ''), ?idLabel) as ?title) WHERE { VALUES ?sqid { wd:Q7388350 } { ?id p:P5817/ps:P5817 wd:Q55654238; wdt:P81/wdt:P16*|wdt:P1192/wdt:P16* ?sqid; wdt:P625 ?geo. } MINUS { VALUES ?not { wd:Q6501349 } ?id wdt:P31/wdt:P279* ?not. } OPTIONAL { ?id wdt:P18 ?image. } OPTIONAL { ?sqid wdt:P465 ?idhexcolor. } OPTIONAL { ?sqid wdt:P462/wdt:P465 ?hexcolor. } BIND(COALESCE(?idhexcolor,?hexcolor,'5c72f2') as ?marker_color) SERVICE wikibase:label { bd:serviceParam wikibase:language 'en,mul' . ?id rdfs:label ?idLabel . } OPTIONAL {?link schema:about ?id. ?link schema:isPartOf <https://en.wikipedia.org/> . } }" }]</mapframe>
Rapid transit network of a region
<mapframe zoom="10" text="Athens" align="left" height="440" latitude="37.99" longitude="23.73" width="500">[ { "type": "ExternalData", "service": "geoline", "properties": { "stroke-width": 4 }, "query": "SELECT ?id (if(BOUND(?idhexcolor), concat('#', str(?idhexcolor)), if(BOUND(?hexcolor), concat('#', str(?hexcolor)), '#07c63e')) as ?stroke) (concat('Line length: ', str(?length), ' km') as ?description) (if(BOUND(?link), concat('', ?idLabel, ''), ?idLabel) as ?title) WHERE { VALUES ?sys { wd:Q1814382 } { ?id p:P5817/ps:P5817 wd:Q55654238. ?id wdt:P16/wdt:P361* ?sys. } MINUS { VALUES ?rem { wd:Q548662 wd:Q55697304 } ?id wdt:P31/wdt:P279* ?rem. } OPTIONAL { ?id wdt:P465 ?idhexcolor. } OPTIONAL { ?id wdt:P462 ?color. ?color wdt:P465 ?hexcolor.} SERVICE wikibase:label { bd:serviceParam wikibase:language 'en,mul' . ?id rdfs:label ?idLabel . } OPTIONAL {?link schema:about ?id. ?link schema:isPartOf <https://en.wikipedia.org/> . } } GROUP BY ?id ?link ?idLabel ?length ?hexcolor ?idhexcolor "}, ]</mapframe>