User:SM5POR/Geography

From Wikidata
Jump to navigation Jump to search

Maps[edit]

Finding geographic centers[edit]

SELECT ?territory ?territoryLabel ?location ?distance
WHERE {
  SERVICE wikibase:around { 
    ?territory wdt:P5140 ?location.
    bd:serviceParam wikibase:center "Point(18.0 60.0)"^^geo:wktLiteral.
    bd:serviceParam wikibase:radius "100000".
    bd:serviceParam wikibase:distance ?distance.
  }
  #OPTIONAL {?item wdt:P31 ?class}.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ?distance
LIMIT 100
Try it!

Finding thematic maps[edit]

SELECT ?class ?classLabel ?qobject ?qobjectLabel ?object ?objectLabel
WHERE {
  #OPTIONAL {?item wdt:P31 ?class}.
  ?stmt pq:P180 ?qobject.
  ?stmt ?ps ?object.
  ?wd wikibase:statementProperty ?object.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ?class ?classLabel ?qobject ?qobjectLabel ?object ?objectLabel
LIMIT 100
Try it!

Orientation[edit]

Statistics[edit]

A matter of time[edit]

Around the World in 80 million Time Zones

Finding number of items with time zone specified, grouped by country[edit]

SELECT DISTINCT ?country ?countryLabel ?zones ?items (ROUND((100*?items)/?zones)/100 AS ?obsession) (ROUND((100000*?items)/?area)/100 AS ?itemdensity) WHERE {
  {
    SELECT DISTINCT ?country (COUNT(DISTINCT ?zone) AS ?zones) (COUNT(DISTINCT ?item) AS ?items) WHERE {
      ?item wdt:P421 ?zone.
      ?item wdt:P17 ?country.
    }
    GROUP BY ?country
  }
  ?country wdt:P2046 ?area.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY DESC(?obsession)
Try it!

Finding classes of items with time zone specified[edit]

SELECT DISTINCT ?class ?classLabel ?zones ?items WHERE {
  {
    SELECT DISTINCT ?class (COUNT(DISTINCT ?zone) AS ?zones) (COUNT(DISTINCT ?item) AS ?items) WHERE {
      ?item wdt:P421 ?zone.
      ?item wdt:P31 ?class.
    }
    GROUP BY ?class
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY DESC(?items)
Try it!

Transport infrastructure[edit]

SELECT DISTINCT ?point ?pointLabel ?class1 ?class1Label (COUNT(DISTINCT ?class) AS ?classes) (MIN(?instances) AS ?min) (MAX(?instances) AS ?max) (SUM(?instances) AS ?sum) WHERE {
  {
    SELECT DISTINCT ?point ?class1 ?class (COUNT(DISTINCT ?instance) AS ?instances) WHERE {
      VALUES ?point {wd:Q228332}
      #VALUES ?point {wd:Q548662 wd:Q55488 wd:Q55678}
      #VALUES ?point {wd:928830 wd:Q1248784 wd:Q2298537 wd:Q20202390 wd:Q87979897}
      OPTIONAL {?class1 wdt:P279 ?point.
                ?subclass wdt:P279* ?class1.}
      BIND(COALESCE(?subclass, ?point) AS ?class)
      #OPTIONAL {?class ?property ?value.}
      #?property rdf:type owl:DatatypeProperty.
      OPTIONAL {?instance wdt:P31 ?class.}
    }
    GROUP BY ?point ?class1 ?class
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?point ?pointLabel ?class1 ?class1Label
ORDER BY CONCAT(STR(?point), "  ", IF(BOUND(?class1), STR(?class1Label), " "))
Try it!

Obtaining Wikidata statistics for items related to geography[edit]

SELECT DISTINCT ?geography ?geographyLabel ?class1 ?class1Label (COUNT(DISTINCT ?class) AS ?classes) (MIN(?instances) AS ?min) (MAX(?instances) AS ?max) (SUM(?instances) AS ?sum) WHERE {
  {
    SELECT DISTINCT ?geography ?class1 ?class (COUNT(DISTINCT ?instance) AS ?instances) WHERE {
      VALUES ?geography {wd:Q4006}
      #VALUES ?geography {wd:Q8008} # wd:Q2221906 wd:Q2625603 wd:Q27096213}
      OPTIONAL {?class1 wdt:P279 ?geography.
                ?subclass wdt:P279* ?class1.}
      BIND(COALESCE(?subclass, ?geography) AS ?class)
      OPTIONAL {?class ?property ?value.}
      #?property rdf:type owl:DatatypeProperty.
      OPTIONAL {?instance wdt:P31 ?class.}
    }
    GROUP BY ?geography ?class1 ?class
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?geography ?geographyLabel ?class1 ?class1Label
ORDER BY CONCAT(STR(?geography), "  ", IF(BOUND(?class1), STR(?class1Label), " "))
Try it!

Finding properties commonly used in geography[edit]

SELECT DISTINCT ?property (COUNT(?item) AS ?items)
WHERE {
  ?item wdt:P31 wd:Q6256.
  ?item ?property ?value.
  ?property rdf:type owl:DatatypeProperty.
}
GROUP BY ?property
ORDER BY DESC(?items)
Try it!
SELECT DISTINCT ?property ?paintings ?pvalues (COUNT(?item) AS ?items) (COUNT(?value) AS ?values)
WHERE {
  {
    SELECT DISTINCT ?pproperty (COUNT(DISTINCT ?painting) AS ?paintings) (COUNT(DISTINCT ?pvalue) AS ?pvalues) WHERE {
      ?painting wdt:P31 wd:Q3305213.
      ?painting ?pproperty ?pvalue.
      ?pproperty rdf:type owl:DatatypeProperty.
    }
    GROUP BY ?pproperty
  }
  ?item wdt:P31/wdt:P279* wd:Q6256.
  #?item ?property ?value.
  #?property rdf:type owl:DatatypeProperty.
  #OPTIONAL {?painting ?property ?pvalue.}
}
GROUP BY ?property ?paintings ?pvalues
ORDER BY DESC(?items)
Try it!

Finding subclasses of country[edit]

SELECT DISTINCT ?class ?classLabel (COUNT(?item) AS ?items)
WHERE {
  ?class wdt:P279* wd:Q6256.
  OPTIONAL {?item wdt:P31 ?class.}
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?class ?classLabel
ORDER BY DESC(?items)
Try it!

Population densities[edit]

SELECT DISTINCT ?country ?countryLabel ?population ?area ?stmt ?height
WHERE {
  ?country wdt:P31 wd:Q6256.
  ?country wdt:P1082 ?population.
  ?country wdt:P2046 ?area.
  ?country p:P610 ?stmt.
  ?stmt pq:P2044 ?height.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
#GROUP BY ?country
#ORDER BY DESC(?items)
Try it!
SELECT DISTINCT ?x ?y ?countryLabel
WHERE {
  ?country wdt:P31/wdt:P279* wd:Q56061.
  ?country wdt:P1082 ?population.
  ?country wdt:P2046 ?area.
  ?country p:P610 ?hpt.
  ?hpt pq:P2044 ?height.
  ?country p:P1589 ?lpt.
  ?lpt pq:P2044 ?depth.
  {
    SELECT ?x ?y WHERE {
      BIND(?population/?area AS ?density)
      BIND(?area/?population AS ?idensity)
      BIND((?depth+?height) AS ?span) 
      BIND((?span*?span)/?area AS ?inclination)
      BIND(?density / ?inclination AS ?slopiness)
      BIND((STRLEN(ROUND(300000000*?density*?density*?density*?density))-9)/4.0 AS ?x)
      BIND((STRLEN(ROUND(300000000*?inclination*?inclination))-9)/4.0 AS ?y)
    }
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?countryLabel ?x ?y 
#ORDER BY DESC(?slopiness)
Try it!

Finding databases from different countries[edit]

SELECT ?item ?itemLabel ?ctryLabel ?fowLabel (COUNT(DISTINCT ?p) AS ?size)
WHERE {
  ?item wdt:P31/wdt:P279* wd:Q8513.
  ?item wdt:P17 ?ctry.
  OPTIONAL {?item wdt:P101 ?fow.}
  ?item ?p ?v.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?item ?itemLabel ?ctryLabel ?fowLabel
ORDER BY ?ctryLabel
Try it!

Politics[edit]

Elections[edit]

Find constituencies

Find legislative election data