Wikidata:WikiProject Weather observations/en/SPARQL

From Wikidata
Jump to navigation Jump to search

en français

SPARQL queries related to the weather station (Q190107) of Meteorological Service of Canada (Q349450).

Every weather station in Wikidata

[edit]
# Every weather station in Wikidata
#defaultView:Map
SELECT ?item ?itemLabel ?coord WHERE {
  ?item (wdt:P31/wdt:P279*) wd:Q190107.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  OPTIONAL { ?item wdt:P625 ?coord. }
}
Try it!

Every MSC station

[edit]
# Every MSC station 
#defaultView:Map
SELECT ?item ?itemLabel ?coord WHERE {
  ?item (wdt:P31/wdt:P279*) wd:Q190107.
  ?item wdt:P127 wd:Q349450.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  OPTIONAL { ?item wdt:P625 ?coord. }

}
Try it!

Note: the following three stations are located at 0° longitude and latitude refleting what is indicated in MSC file:

still in use

[edit]
# Every MSC station still in use
#defaultView:Map
SELECT ?item ?itemLabel ?coord 
WHERE {
  ?item (wdt:P31/wdt:P279*) wd:Q190107.
  ?item wdt:P127 wd:Q349450.

  OPTIONAL { ?item wdt:P3999 ?closureDate }
  FILTER(# Closure date is not set
    !BOUND(?closureDate)    
  )
   
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  OPTIONAL { ?item wdt:P625 ?coord. }
}
Try it!

closed

[edit]
# Every closed MSC station 
#defaultView:Map
SELECT ?item ?itemLabel ?coord 
WHERE {
  ?item (wdt:P31/wdt:P279*) wd:Q190107.
  ?item wdt:P127 wd:Q349450.

  # Closure date exists and is before 2100
  ?item wdt:P3999 ?closureDate . 
  FILTER (?closureDate < "2100-01-01T00:00:00Z"^^xsd:dateTime) .
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  OPTIONAL { ?item wdt:P625 ?coord. }
}
Try it!

MSC stations, by altitude

[edit]

altitude by group of 500 m.

[edit]
# MSC stations by altitude of 500 m.
#defaultView:Map
SELECT ?item ?itemLabel ?coord ?altitude ?layer WHERE {
  ?item (wdt:P31/wdt:P279*) wd:Q190107 ; wdt:P127 wd:Q349450 ; wdt:P2044 ?altitude .
  BIND (FLOOR(?altitude/500) AS ?layer )
  ?item wdt:P625 ?coord.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Try it!

altitude > 1000 m

[edit]
# MSC stations altitude > 1000 m
#defaultView:Map
SELECT ?item ?itemLabel ?coord WHERE {
  ?item (wdt:P31/wdt:P279*) wd:Q190107.

  ?item wdt:P2044 ?altitude.
  FILTER (?altitude > 1000) .

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  OPTIONAL { ?item wdt:P625 ?coord. }
  ?item wdt:P127 wd:Q349450.
}
Try it!

MSC stations par of Distant Early Warning Line (latitude [64°57', 70°45'] N)

[edit]
# MSC stations between latitudes [66°34', 70°45'] N 
#defaultView:Map
SELECT ?item ?itemLabel ?coord WHERE {
  ?item (wdt:P31/wdt:P279*) wd:Q190107.
  ?item wdt:P127 wd:Q349450.
  
  ?item p:P625 ?coordinate .
  ?coordinate psv:P625 ?coordinate_node .
  ?coordinate_node wikibase:geoLatitude ?lat .
  ?coordinate_node wikibase:geoLongitude ?lon .

  FILTER (?lat > 66.56)
  FILTER (?lat < 70.45)
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  OPTIONAL { ?item wdt:P625 ?coord. }

}
Try it!

New Brunswick Stations

[edit]
# New Brunswick Stations
#defaultView:Map

# "CANADA": "Q16"
# "ALBERTA":"Q1951",
# "COLOMBIE-BRITANNIQUE":"Q1974",
# "ILE DU PRINCE-EDOUARD":"Q1979",
# "MANITOBA":"Q1948",
# "NOUVEAU-BRUNSWICK":"Q1965",
# "NOUVELLE-ECOSSE":"Q1952",
# "NUNAVUT":"Q2023",
# "ONTARIO":"Q1904",
# "QUEBEC":"Q176",
# "SASKATCHEWAN":"Q1989",
# "TERRE-NEUVE":"Q2003",
# "TERRITOIRES DU NORD-OUEST":"Q2007",
# "YUKON":"Q2009"

SELECT ?item ?itemLabel ?coord WHERE {
  ?item (wdt:P31/wdt:P279*) wd:Q190107.
  ?item wdt:P131 wd:Q1965 .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  OPTIONAL { ?item wdt:P625 ?coord. }

}
Try it!

NB stations ordered by service entry date

[edit]
# NB stations ordered by service entry date 
SELECT ?item ?itemLabel ?coord ?date_de_mise_en_service WHERE {
  ?item (wdt:P31/wdt:P279*) wd:Q190107.
  ?item wdt:P131 wd:Q1965.

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  OPTIONAL { ?item wdt:P625 ?coord. }
  OPTIONAL { ?item wdt:P729 ?date_de_mise_en_service. }
}
ORDER BY DESC(?date_de_mise_en_service)
Try it!

NB stations with hourly observations

[edit]
# NB stations with hourly observations
#defaultView:Map
SELECT ?item ?itemLabel ?coord WHERE {
  ?item (wdt:P31/wdt:P279*) wd:Q190107.
  ?item wdt:P131 wd:Q1965 .
  ?item wdt:P6339 wd:Q59657010 . # Hourly:Q59657010  Daily: Q59657036  Monthly: Q59657037
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  OPTIONAL { ?item wdt:P625 ?coord. }
}
Try it!

NB stations with hourly observation during [1975,2000]

[edit]
# NB stations with hourly observation during [1975,2000]
#defaultView:Map
SELECT ?item ?itemLabel ?coord ?starttime ?endtime WHERE {
  ?item (wdt:P31/wdt:P279*) wd:Q190107.
  ?item wdt:P131 wd:Q1965 .
  ?item wdt:P6339 wd:Q59657010 .
  ?item p:P6339 ?daily_obs .
  ?daily_obs pq:P580 ?starttime.
  ?daily_obs pq:P582 ?endtime.
  FILTER (?starttime < "1975-01-02T00:00:00Z"^^xsd:dateTime) .
  FILTER (?endtime > "2000-01-01T00:00:00Z"^^xsd:dateTime) .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  OPTIONAL { ?item wdt:P625 ?coord. }
}
Try it!

Québec stations created before 1920

[edit]
# Québec stations created before 1920
#defaultView:Map
SELECT ?item ?itemLabel ?coord WHERE {
  ?item (wdt:P31/wdt:P279*) wd:Q190107.
  ?item wdt:P131 wd:Q176 .
  ?item wdt:P729 ?service_entry . 
  FILTER (?service_entry < "1920-01-01T00:00:00Z"^^xsd:dateTime) .
   
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  OPTIONAL { ?item wdt:P625 ?coord. }
}
Try it!

Nova Scotia stations closed since 1980

[edit]
# Nova Scotia stations closed since 1980
#defaultView:Map
SELECT ?item ?itemLabel ?coord WHERE {
  ?item (wdt:P31/wdt:P279*) wd:Q190107.
  ?item wdt:P131 wd:Q1952 .
  ?item wdt:P3999 ?closureDate . 
  FILTER (?closureDate > "1980-01-01T00:00:00Z"^^xsd:dateTime) .
   
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  OPTIONAL { ?item wdt:P625 ?coord. }
}
Try it!

Ontario stations active in 1953

[edit]
# Ontario stations active in 1953 
#defaultView:Map
SELECT ?item ?itemLabel ?coord 
WHERE {
  ?item (wdt:P31/wdt:P279*) wd:Q190107.
  ?item wdt:P131 wd:Q1904 .

  ?item wdt:P729 ?service_entry . 
  # service entry is before 1953
  FILTER (?service_entry <= "1953-01-01T00:00:00Z"^^xsd:dateTime) .
  # and closure date not before 1953
  OPTIONAL { ?item wdt:P3999 ?closureDate }
  FILTER(
    # Closure date is not set
    ?closureDate > "1953-01-01T00:00:00Z"^^xsd:dateTime|| !BOUND(?closureDate)     # or closure date is after 1953
  )
 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  OPTIONAL { ?item wdt:P625 ?coord. }
Try it!

}

closed afterwards

[edit]
# Ontario stations active in 1953 and closed afterwards
#defaultView:Map
SELECT ?item ?itemLabel ?coord WHERE {
  ?item (wdt:P31/wdt:P279*) wd:Q190107.
  ?item wdt:P131 wd:Q1904 .

  ?item wdt:P729 ?service_entry . 
  FILTER (?service_entry <= "1953-01-01T00:00:00Z"^^xsd:dateTime) .

  ?item wdt:P3999 ?closureDate . 
  FILTER (?closureDate > "1953-01-01T00:00:00Z"^^xsd:dateTime) .
   
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  OPTIONAL { ?item wdt:P625 ?coord. }
}
Try it!

still in used

[edit]
# Ontario stations active in 1953 and still active
#defaultView:Map
SELECT ?item ?itemLabel ?coord 
WHERE {
  ?item (wdt:P31/wdt:P279*) wd:Q190107.
  ?item wdt:P131 wd:Q1904 .

  ?item wdt:P729 ?service_entry . 
  FILTER (?service_entry <= "1953-01-01T00:00:00Z"^^xsd:dateTime) .
  # ... but the statement has no P3999 (end date) qualifier
  FILTER NOT EXISTS { ?item wdt:P3999 ?x }  
   
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  OPTIONAL { ?item wdt:P625 ?coord. }
}
Try it!

Newfoundland and Labradar stations closed in 2017

[edit]
# Newfoundland and Labradar stations closed in 2017
#defaultView:Map
SELECT ?item ?itemLabel ?coord WHERE {
  ?item (wdt:P31/wdt:P279*) wd:Q190107.
  ?item wdt:P131 wd:Q2003 .
  ?item wdt:P3999 ?closureDate . 
  FILTER (?closureDate = "2017-01-01T00:00:00Z"^^xsd:dateTime) .
   
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  OPTIONAL { ?item wdt:P625 ?coord. }
}
Try it!

Canadian stations closed in 2017 and 2018

[edit]
# Canadian stations closed in 2017 and 2018
#defaultView:Map
SELECT ?item ?itemLabel ?coord WHERE {
  ?item (wdt:P31/wdt:P279*) wd:Q190107.
  ?item wdt:P127 wd:Q349450.
  ?item wdt:P3999 ?closureDate . 
  FILTER (?closureDate = "2017-01-01T00:00:00Z"^^xsd:dateTime ||
         ?closureDate = "2018-01-01T00:00:00Z"^^xsd:dateTime) .
   
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  OPTIONAL { ?item wdt:P625 ?coord. }
}
Try it!

Stations < 10km

[edit]

of a city in New Brunswick

[edit]
# Stations of New Brunswick < 10km of a city
#defaultView:Map
SELECT DISTINCT ?station ?coordonn_es_g_ographiques WHERE {
  {
    # City/town: Q7930989  Airport: Q1248784 Port: Q44782
    SELECT ?city WHERE { ?city (wdt:P31/wdt:P279*) wd:Q7930989. }
  }
  ?city wdt:P131* wd:Q1965. # In NB
   
  ?city wdt:P625 ?cityLoc # Cities location
  SERVICE wikibase:around {
    ?station wdt:P625 ?location .
    bd:serviceParam wikibase:center ?cityLoc .
    bd:serviceParam wikibase:radius "10" . # within 10 km radius
  } .
   # is close from a Wx station
  FILTER EXISTS { ?station wdt:P31/wdt:P279* wd:Q190107 } .
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  OPTIONAL { ?station wdt:P625 ?coordonn_es_g_ographiques. }
}
Try it!

of a Canadian port

[edit]
# Stations < 10km of a Canadian port
#defaultView:Map
SELECT DISTINCT ?station ?coordonn_es_g_ographiques WHERE {
  ?port wdt:P31 wd:Q44782.
  ?port wdt:P17 wd:Q16.
    
  ?port wdt:P625 ?portLoc # Port location
  SERVICE wikibase:around {
    ?station wdt:P625 ?location .
    bd:serviceParam wikibase:center ?portLoc .
    bd:serviceParam wikibase:radius "10" . # within 10 km radius
  } .
   # is close from a Wx station
  FILTER EXISTS { ?station wdt:P31/wdt:P279* wd:Q190107 } .
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  OPTIONAL { ?station wdt:P625 ?coordonn_es_g_ographiques. }
}
Try it!

from a Canadian airport

[edit]
# Stations < 10km from a Canadian airport (there's a lot of airports in Canada)
#defaultView:Map
SELECT DISTINCT ?station ?coordonn_es_g_ographiques WHERE {

  # City/town: Q7930989  Airport: Q1248784 Port: Q44782
  ?aeroport wdt:P31 wd:Q1248784.
  ?aeroport wdt:P17 wd:Q16.
    
  ?aeroport wdt:P625 ?aeroportLoc # Aeroport locations
  SERVICE wikibase:around {
    ?station wdt:P625 ?location .
    bd:serviceParam wikibase:center ?aeroportLoc .
    bd:serviceParam wikibase:radius "10" . # within 10 km radius
  } .
   # is close from a Wx station
  FILTER EXISTS { ?station wdt:P31/wdt:P279* wd:Q190107 } .
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  OPTIONAL { ?station wdt:P625 ?coordonn_es_g_ographiques. }
}
Try it!

from a flooding in Canada

[edit]
# Stations < 10km from a flooding in Canadda
#defaultView:Map
SELECT DISTINCT ?station ?coordonn_es_g_ographiques WHERE {
  ?inondation wdt:P31 wd:Q8068.
  ?inondation wdt:P17 wd:Q16.
    
  ?inondation wdt:P625 ?inonLoc # Inondation location
  SERVICE wikibase:around {
    ?station wdt:P625 ?location .
    bd:serviceParam wikibase:center ?inonLoc .
    bd:serviceParam wikibase:radius "10" . # within 10 km radius
  } .
   # is close from a Wx station
  FILTER EXISTS { ?station wdt:P31/wdt:P279* wd:Q190107 } .
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  OPTIONAL { ?station wdt:P625 ?coordonn_es_g_ographiques. }
}
Try it!

Stations in Ontario closer than 10 km from a city of more than 100 000 inhabitants

[edit]
# Stations in Ontario closer than 10 km from a city of more than 100 000 inhabitants
#defaultView:Map
SELECT DISTINCT ?city ?coordonn_es_g_ographiques WHERE {
  {
    # City/town: Q7930989  Airport: Q1248784 Port: Q44782
    SELECT ?city WHERE { ?city (wdt:P31/wdt:P279*) wd:Q7930989. }
  }
  ?city wdt:P131* wd:Q1904. # In Ontario
   
  # Filtering by population
  ?city wdt:P1082 ?population # Cities population
  FILTER (?population > 100000) .
  
  # Filtering by location
  ?city wdt:P625 ?cityLoc # Cities location
  SERVICE wikibase:around {
    ?station wdt:P625 ?location .
    bd:serviceParam wikibase:center ?cityLoc .
    bd:serviceParam wikibase:radius "10" . # within 10 km radius
  } .
   # is close from a Wx station
  FILTER EXISTS { ?station wdt:P31/wdt:P279* wd:Q190107 } .
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  OPTIONAL { ?city wdt:P625 ?coordonn_es_g_ographiques. }
}
Try it!

Stations in Québec closer than 1 km from a bridge of a length over 100 m

[edit]
# Stations in Québec closer than 1 km from a bridge of a length over 100 m 
#defaultView:Map
SELECT DISTINCT ?station ?coordonn_es_g_ographiques WHERE {
  
  # Bridges
  {
    SELECT ?bridge WHERE { ?bridge (wdt:P31/wdt:P279*) wd:Q12280. }
  }
  ?bridge wdt:P131* wd:Q176. # in QC
  
  # with a length < 100 m
  ?bridge wdt:P2043 ?length.
  FILTER(?length > 100)
          
  # Find station within 1km of these bridges 
  ?bridge wdt:P625 ?bridgeLoc 
  SERVICE wikibase:around {
    ?station wdt:P625 ?location .
    bd:serviceParam wikibase:center ?bridgeLoc .
    bd:serviceParam wikibase:radius "1" . # within 1 km radius
  } .
  # is close from a Wx station
  FILTER EXISTS { ?station wdt:P31/wdt:P279* wd:Q190107 } .
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  OPTIONAL { ?station wdt:P625 ?coordonn_es_g_ographiques. }
}
Try it!

Request for update

[edit]

Request to be used as argument with the script MSC Weather Stations to Wikidata to update the stations on Wikidata (export the result in CSV format).

PREFIX schema: <http://schema.org/>

# Information sur les stations météo du SMC
SELECT ?station ?label_en ?description_en ?label_fr ?description_fr ?instance_of ?coordinate_location ?province_label ?identifiant_WIGOS_de_station ?property_of ?start_date ?end_date ?msc_climate_id ?altitude ?data_interval ?hourly ?h_start ?h_end ?daily ?d_start ?d_end ?monthly ?m_start ?m_end WHERE {
  ?station (wdt:P31/wdt:P279*) wd:Q190107.
  ?station wdt:P17 wd:Q16.
  ?station wdt:P6242 ?MSCID

  # Data interval (HLY, DLY, MLY)
  OPTIONAL { ?station p:P6339 ?data_interval . }
  OPTIONAL { ?station p:P6339 ?d_interval .          # there is a P6339 property
             ?d_interval ps:P6339 wd:Q59657036 .  # and it's a daily
             ?d_interval ps:P6339 ?daily .        # and we get its value, in case there are no dates
             OPTIONAL { ?d_interval pq:P580 ?d_start .} # might be a start date
             OPTIONAL { ?d_interval pq:P582 ?d_end .}   # might be an end date
  }
  OPTIONAL { ?station p:P6339 ?m_interval .          # there is a P6339 property
             ?m_interval ps:P6339 wd:Q59657037 .  # and it's monthly
             ?m_interval ps:P6339 ?monthly .        # and we get its value, in case there are no dates
             OPTIONAL { ?m_interval pq:P580 ?m_start .} # might be a start date
             OPTIONAL { ?m_interval pq:P582 ?m_end .}   # might be an end date
  }
  OPTIONAL { ?station p:P6339 ?h_interval .          # there is a P6339 property
             ?h_interval ps:P6339 wd:Q59657010 .  # and it's hourly
             ?h_interval ps:P6339 ?hourly .        # and we get its value, in case there are no dates
             OPTIONAL { ?h_interval pq:P580 ?h_start .} # might be a start date
             OPTIONAL { ?h_interval pq:P582 ?h_end .}   # might be an end date
  }

  OPTIONAL { ?station wdt:P31 ?instance_of. }
  OPTIONAL { ?station wdt:P625 ?coordinate_location. }
  OPTIONAL { ?station wdt:P131 ?province_label. }
  OPTIONAL { ?station wdt:P4136 ?identifiant_WIGOS_de_station. }
  OPTIONAL { ?station wdt:P127 ?property_of. }
  OPTIONAL { ?station wdt:P729 ?start_date. }
  OPTIONAL { ?station wdt:P3999 ?end_date. }
  OPTIONAL { ?station wdt:P6242 ?msc_climate_id. }
  OPTIONAL { ?station wdt:P2044 ?altitude. }
  
  
  # FR/EN description
  OPTIONAL { ?station rdfs:label ?label_en. }
  OPTIONAL { ?station rdfs:label ?label_fr. }
  OPTIONAL { ?station schema:description ?description_en. }
  OPTIONAL { ?station schema:description ?description_fr. }
  FILTER((LANG(?label_en)) = "en")
  FILTER((LANG(?label_fr)) = "fr")
  FILTER((LANG(?description_en)) = "en")
  FILTER((LANG(?description_fr)) = "fr")

}
ORDER BY(?MSCID)
Try it!

Find station with the locations (constraint violation)

[edit]
SELECT DISTINCT ?item ?itemLabel WHERE {
	?statement wikibase:hasViolationForConstraint wds:P625-E8AD8423-E6C5-4AB0-A82E-916F4468CDFB .
    ?item (wdt:P31/wdt:P279*) wd:Q190107.
	?item ?p ?statement .
	FILTER( ?item NOT IN ( wd:Q4115189, wd:Q13406268, wd:Q15397819 ) ) .
	SERVICE wikibase:label { bd:serviceParam wikibase:language "fr,en" } .
}
Try it!