I'm having trouble extracting location attributes of company HQ's.

My query: finds all companies or sub-classes, and returns some basic properties such as ISIN and URL, and the Headquarter location.

I have tried to use this example to extend the Headquarter part of the query to return location information such as city, country, and coordinate latitude and longitude. However I am getting stuck on pulling the values or labels through.

Thank you

  ?item ?itemLabel ?web ?isin ?hq ?hqloc ?inception

# valueLabel is only useful for properties with item-datatype
  ?item p:P31/ps:P31/wdt:P279* wd:Q783794.

  OPTIONAL{?item wdt:P856 ?web.} # get item
  OPTIONAL{?item wdt:P946 ?isin.} # get item
  OPTIONAL{?item wdt:P571 ?inception.} # get item
  OPTIONAL{?item wdt:P159 ?hq.}  

  OPTIONAL{?item p:P159 ?hqItem. # get property
           ?hqItem ps:P159 wd:Q515. # get property-statement wikidata-entity
           ?hqItem pq:P17 ?hqloc. # get country of city

  ?article schema:about ?item .
  ?article schema:inLanguage "en" .
  ?article schema:isPartOf <https://en.wikipedia.org/>. 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.