Search code examples
sparqlwikidata

Plot simple categorical data onto a map in Wikidata


I use the following Wikidat SPARQL query to get a list of places of birth and death of hairdressers (https://w.wiki/6Gsz):

  #defaultView:Map
SELECT ?pers ?pobC ?podC WHERE {
  ?pers wdt:P106 wd:Q55187 ;
          wdt:P19 ?pob ;
          wdt:P20 ?pod .
  ?pob wdt:P625 ?podC .
  ?pod wdt:P625 ?pobC .
  }

I would like to visually separate the places of birth from the places of death. The intended result would be: ?pobC dots in one color, ?podC dots in another.

The examples in the Wikidata SPARQL handbook (https://en.wikibooks.org/wiki/SPARQL/Views#Map) don't quite work for me as the color depends in my case on the variable name (pob vs. pod) and not its value and I cannot figure out how to translate this into SPARQL.

Help would be appreciated!


Solution

  • Developing on @UninformedUser's comment:

    You need to return only one coordinate per row, and use the ?layer special variable to split the colors.

    The minimal solution to that, based on the comment but without nesting and hints, is a query like:

    #defaultView:Map
    SELECT ?pers ?pobC ?podC ?layer WHERE {
      ?pers wdt:P106 wd:Q55187 ;
              wdt:P19 ?pob ;
              wdt:P20 ?pod .
      {
        ?pob wdt:P625 ?podC.
        BIND("birth" AS ?layer)
      }
      UNION
      {
        ?pod wdt:P625 ?pobC.
        BIND("death" AS ?layer)
      }  
     }
    

    https://w.wiki/6H59

    Note that in that case you are returning only one place per line, so each dot won't have all the birth and death information.