set up the ability to query wikidata

import urllib.parse
from IPython.display import IFrame
baseurl='https://query.wikidata.org/embed.html#'

def wdq(query='',width=800,height=500):
  return IFrame(baseurl+urllib.parse.quote(query), width=width, height=height)

Parishes in Australia, coloured by county. Note that some NSW circles appear to be the wrong colour, but I think they may actually have the wrong coordinates (in the Geographic Names Register). Still doing some Quality Assurance on this data.

wdq(width=1000,height=1000,query="""
#defaultView:Map{"layer":"?county"}

SELECT DISTINCT ?parish ?parishLabel ?coords ?county ?countyLabel WHERE {
     
     ?parish wdt:P31/wdt:P279* wd:Q28931907 .
     ?county wdt:P31/wdt:P279* wd:Q20974973 .
     
     ?parish wdt:P131 ?county .
     
   ?parish wdt:P625 ?coords.
  
   SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
   }
 }
LIMIT 15000
 """)

The same query, worldwide: Parishes worldwide, coloured by county.

wdq(width=1000,height=1000,query="""
#defaultView:Map{"layer":"?county"}

SELECT DISTINCT ?parish ?parishLabel ?coords ?county ?countyLabel WHERE {
     
     ?parish wdt:P31/wdt:P279* wd:Q4976993 .
     ?county wdt:P31/wdt:P279* wd:Q28575 .
     
     ?parish wdt:P131 ?county .
     
   ?parish wdt:P625 ?coords.
  
   SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
   }
 }
LIMIT 15000
 """)

Other stuff in NSW, coloured by "instance of". Notice that outliers are sometimes objects not entirely contained in one State.

wdq(width=1000,height=1000,query="""
#defaultView:Map{"layer":"?type"}

SELECT DISTINCT ?item ?itemLabel ?coords ?type ?typeLabel WHERE {
     
   ?item wdt:P131* wd:Q3224 .
   ?item wdt:P625 ?coords.
     
   ?item wdt:P31 ?type .
     
  
   SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
   }
 }
LIMIT 150000
 """)
wdq(width=1000,height=1000,query="""
#defaultView:BubbleChart

SELECT ?type ?typeLabel (count(*) AS ?count) WHERE {
  SELECT DISTINCT ?item ?coords ?type ?typeLabel WHERE {
     
   ?item wdt:P131* wd:Q3224 .
   ?item wdt:P625 ?coords.
     
   ?item wdt:P31 ?type .

    SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
  }
     
 }
 LIMIT 150000

} GROUP BY ?type ?typeLabel
ORDER BY DESC(?count)
 """)