8
$\begingroup$

I've tried this code, but I can't plot the coordinates in my country map.

Weather = {"Ulaanbaatar", "Erdenet"}  

stationtocoordinate = Map[# -> WeatherData[#, "Coordinates"] &, Weather]

allWeatherStations = WeatherData[]; fullformStations = FullForm /@ allWeatherStations; Tally[StringLength /@ fullformStations[[All, 1, 2]]] . This code not working. Why?

$\endgroup$
  • $\begingroup$ MongoliaCountryData["Mongolia", "Shape"] $\endgroup$ – teegii Apr 24 '15 at 6:44
  • 1
    $\begingroup$ Welcome to Mathematica Stack exchange! Use the up/down arrows to upvote an answer and the tick mark to accept an answer you deem correct. I've also edited your code - it was missing a definition for Weather and the Map was missing a ] at the end. Also note its good Mathematica practise NOT to use Capitalised variable names as you may inadvertently collide with a named Mathematica function. $\endgroup$ – Gordon Coale Apr 24 '15 at 9:37
14
$\begingroup$

There is an example of what I think you are trying to do at the end of WeatherData help page, but its a little hard to read. However - here's what I think you want.

(* Function to  Get a list consisting of {CityName, Temp, Co-ords} 
given a Countries weather station, note we get the 1st 
nearest weather station to the city *)

weatherdata[cityname_] := {cityname, WeatherData[#, "Temperature"], 
 WeatherData[#, "Coordinates"]} & /@ WeatherData[{cityname, 1}];

(* Get Names for all Cities *)

cities = CityData[#, "Name"] & /@ CityData[{All, "Mongolia"}];

(*  Get the weather and weather station co-ordinates for the list of 
cities  (the Drop is a kludge to remove the incorrect city "Moron") 
from the weather data *)

wdata = Drop[weatherdata[#] & /@ cities, 9];

(*  Plot the list of city weather stations on a map using GeoPosition to 
correctly plot the co-ordinates*)

GeoGraphics[{Point[GeoPosition[wdata[[All, 1, 3]]]], 
Polygon[Entity["Country", "Mongolia"]], GeoRange -> "Country"}]

enter image description here

I'll leave it as an exercise to change the points to something that changes depending on the temperature. i.e. a disc that changes colour/radius. There are some good examples in the GeoGraphics help.

$\endgroup$
9
$\begingroup$

WeatherData can be told to give you all the weather stations it knows about, but there's more than one type of weather station (and duplicates!):

allWeatherStations = WeatherData[];
fullformStations = FullForm /@ allWeatherStations;
Tally[StringLength /@ fullformStations[[All, 1, 2]]]
(*{{4, 6919}, {5, 10306}, {8, 4697}}*)

Looking at the documentation, I find the "WMO*" stations seem to be the interesting, and reliable ones. I extract these and find their corrdinates:

wmoWeatherStations = Cases[fullformStations[[All, 1, 2]], a_ /; StringLength[a] == 8];
wmoStationsPositions = 
  GeoPosition[WeatherData[#, "Coordinates"]] & /@ wmoWeatherStations;

Using GeoWithinQ I find those stations within Mongolia and then use Pick to include these in GeoGraphics

wmoMongolia = GeoWithinQ[Entity["Country", "Mongolia"], wmoStationsPositions];
GeoGraphics[GeoMarker[Pick[wmoStationsPositions, wmoMongolia]], 
 GeoRange -> Entity["Country", "Mongolia"]]

enter image description here

$\endgroup$
  • $\begingroup$ Nice, that usage of FullForm to get the entities doesn't appear to be documented. Does it work on all the curated data functions? $\endgroup$ – Gordon Coale Apr 24 '15 at 16:54
  • 2
    $\begingroup$ It's a cheat to easily get the name of the weather station without having to call a paclet for a property of the Entity. All Entities can be converted into this StandardForm representation of the Entity. $\endgroup$ – Martin John Hadley Apr 24 '15 at 17:00
  • $\begingroup$ I meant InputForm. $\endgroup$ – Martin John Hadley Apr 25 '15 at 8:46

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.