query-944188c1f12e2fcd7a938ccbd2a0f6c6

rq turtle/ttl

TODO

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX psn: <http://www.wikidata.org/prop/statement/value-normalized/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT DISTINCT ?country ?area_sqkm ?population {
     ## Define Country
     #- Sovereign state, territory, state with limited recognition, and country (respectively)
     VALUES ?countryclass {wd:Q3624078 wd:Q183366 wd:Q15634554 wd:Q6256} .
     ?countrystat wdt:P31 ?countryclass .
     ## Define Area
     #- and convert m² to km² with 2 decimal places
     ?countrystat p:P2046 [ a wikibase:BestRank; 
                              psn:P2046/wikibase:quantityAmount ?area_sqm ] 
                  FILTER(?area_sqm > 0) .
     BIND( ROUND(?area_sqm/10000)/100 as ?area_sqkm)
     ## Define Population
     ?countrystat p:P1082 [ a wikibase:BestRank; 
                              ps:P1082 ?population ] 
                  FILTER(?population >= 0 ) .
     ## Define the Country label
     ?countrystat rdfs:label ?country FILTER(lang(?country)="en").
     SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . }
}
ORDER BY ASC(?country)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v6("?area_sqkm"):::projected v3("?area_sqm") v1("?country"):::projected v4("?countryclass") v5("?countrystat") v2("?population"):::projected a1((" ")) a2((" ")) a3((" ")) c5(["wikibase:BestRank"]):::iri c13(["bd:serviceParam"]):::iri c15(["#91;AUTO_LANGUAGE#93;,en"]):::literal f0[["?country = 'en'"]] f0 --> v1 f1[["?population >= '0^^xsd:integer'"]] f1 --> v2 f2[["?area_sqm > '0^^xsd:integer'"]] f2 --> v3 bind3[/VALUES ?countryclass/] bind3-->v4 bind30(["wd:Q3624078"]) bind30 --> bind3 bind31(["wd:Q183366"]) bind31 --> bind3 bind32(["wd:Q15634554"]) bind32 --> bind3 bind33(["wd:Q6256"]) bind33 --> bind3 v5 --"p:direct/P31"--> v4 a1 --"a"--> c5 a1 --"p:statement/value-normalized/P2046"--> a2 a2 --"wikibase:quantityAmount"--> v3 v5 --"p:P2046"--> a1 bind4[/"numeric-round(?area_sqm / '10000^^xsd:integer') / '100^^xsd:integer'"/] v3 --o bind4 bind4 --as--o v6 a3 --"a"--> c5 a3 --"p:statement/P1082"--> v2 v5 --"p:P1082"--> a3 v5 --"rdfs:label"--> v1 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c13 --"wikibase:language"--> c15 end