query-8632334e23d1db4e9efc976e6caf1358
DaanvrAS get almoost all items in map vieuw (coordinat box)
Use at
- https://query.wikidata.org/sparql
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX schema: <http://schema.org/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX bd: <http://www.bigdata.com/rdf#>
#defaultView:ImageGride
SELECT
?itemNew ?itemNewLabel ?itemNewDescription
?geo ?img ?categorie
(GROUP_CONCAT(?instanceLabel; SEPARATOR = ", ") AS ?instancesof) # a nices String with the labels of the different instances of related to the item
WHERE
{
{
SELECT
?itemNew
(SAMPLE(?geo_) AS ?geo) # The SAMPLE code is needed to inform the GROUP BY code what to do when there are more than one.
(SAMPLE(?img_) AS ?img)
WHERE
{
#### Selection based on location ####
SERVICE wikibase:box
{
?itemNew wdt:P625 ?geo_.
bd:serviceParam wikibase:cornerWest "Point(2.30 48.87)"^^geo:wktLiteral.
bd:serviceParam wikibase:cornerEast "Point(2.32 48.86)"^^geo:wktLiteral.
}
MINUS { ?itemNew (wdt:P31/(wdt:P279*)) wd:Q376799. } # Remove everything related to roads
?itemNew wdt:P18 ?img_. # Only keep items with pictures
}
GROUP BY ?itemNew
}
#### Categorise items ####
BIND(
IF(EXISTS {?itemNew (wdt:P31/(wdt:P279*)) wd:Q811979},
"Architectural",
IF(EXISTS {?itemNew (wdt:P31/(wdt:P279*)) wd:Q1656682},
"Event",
"Other"
)
)
AS ?categorie)
OPTIONAL { ?itemNew wdt:P31 ?instance. } # Get instances
#### Wikipedia link ####
OPTIONAL {
?article schema:about ?itemNew . # Get wikipedia link
?article schema:isPartOf <https://en.wikipedia.org/>. # Only keep EN language
}
#### Labels & discription ####
SERVICE wikibase:label { # Get labels
bd:serviceParam wikibase:language "en".
?instance rdfs:label ?instanceLabel. # The specification of the variables to be labeld is needed for grouping the instances of correctly
?itemNew rdfs:label ?itemNewLabel.
?itemNew schema:description ?itemNewDescription.
}
}
GROUP BY ?itemNew ?itemNewLabel ?itemNewDescription ?geo ?img ?categorie ?article
Query found at
- https://www.wikidata.org/wiki/User:Daanvr
- https://www.wikidata.org/wiki/Wikidata:Request_a_query/Archive/2020/10
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v8("?article")
v6("?categorie"):::projected
v4("?geo"):::projected
v2("?geo_")
v5("?img"):::projected
v3("?img_")
v7("?instance")
v9("?instanceLabel"):::projected
v12("?instancesof")
v1("?itemNew"):::projected
v11("?itemNewDescription"):::projected
v10("?itemNewLabel"):::projected
a1((" "))
c7([sPoint(2.32 48.86)^^<http://www.opengis.net/ont/geosparql#wktLiteral>"]):::literal
c5([sPoint(2.30 48.87)^^<http://www.opengis.net/ont/geosparql#wktLiteral>"]):::literal
c10(["wd:Q376799"]):::iri
c17(["en"]):::literal
c14([https://en.wikipedia.org/]):::iri
c3(["bd:serviceParam"]):::iri
subgraph s1["http://wikiba.se/ontology#box"]
style s1 stroke-width:4px;
v1 --"wdt:P625"--> v2
c3 --"wikibase:cornerWest"--> c5
c3 --"wikibase:cornerEast"--> c7
end
subgraph minus0["MINUS"]
style minus0 stroke-width:6px,fill:pink,stroke:red;
v1 --"wdt:P31"--> a1
a1 --"wdt:P279"--> c10
end
v1 --"wdt:P18"--> v3
bind3[/"sample(?geo_)"/]
v2 --o bind3
bind3 --as--o v4
bind4[/"sample(?img_)"/]
v3 --o bind4
bind4 --as--o v5
v1 --"wdt:P31"--> null
null --"wdt:P279"--> null
v1 --"wdt:P31"--> null
null --"wdt:P279"--> null
bind5[/"if( ,'Architectural',if( ,'Event','Other'))"/]
subgraph bind5e0["Exists Clause"]
e0v1 --"wdt:P31"--> e0a1
e0a1 --"wdt:P279"--> e0c3
e0v1("?itemNew"):::projected
e0a1((" ")):::projected
e0c3(["wd:Q811979"]):::iri
end
bind5--EXISTS--> bind5e0
subgraph bind5e1["Exists Clause"]
e1v1 --"wdt:P31"--> e1a1
e1a1 --"wdt:P279"--> e1c3
e1v1("?itemNew"):::projected
e1a1((" ")):::projected
e1c3(["wd:Q1656682"]):::iri
end
bind5--EXISTS--> bind5e1
v1 --o bind5
c8 --o bind5
null --o bind5
c9 --o bind5
null --o bind5
null --o bind5
null --o bind5
bind5 --as--o v6
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v1 -."wdt:P31".-> v7
end
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v8 -."schema:about".-> v1
v8 --"schema:isPartOf"--> c14
end
subgraph s2["http://wikiba.se/ontology#label"]
style s2 stroke-width:4px;
c3 --"wikibase:language"--> c17
v7 --"rdfs:label"--> v9
v1 --"rdfs:label"--> v10
v1 --"schema:description"--> v11
end
bind7[/"?instanceLabel"/]
v9 --o bind7
bind7 --as--o v12