Last active
January 30, 2024 11:00
-
-
Save grenade/c61d4891ee4c879d1d31 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections.Generic; | |
| using System.IO; | |
| using System.Linq; | |
| using System.Net; | |
| using Newtonsoft.Json; | |
| namespace metmon | |
| { | |
| class Program | |
| { | |
| private const string Api = "http://datapoint.metoffice.gov.uk/public/data/val/wxfcs/all/json"; | |
| private const string Key = "01234567-89ab-cdef-fedc-ba9876543210"; | |
| static void Main() | |
| { | |
| using (var wc = new WebClient()) | |
| { | |
| var sites = JsonConvert.DeserializeObject<dynamic>(wc.DownloadString(string.Format("{0}/sitelist?key={1}", Api, Key))); | |
| //var sites = JsonConvert.DeserializeObject<dynamic>(File.ReadAllText(@"c:\temp\metoffice.sitelist.json")); | |
| var features = new { | |
| type = "FeatureCollection", | |
| features = ((IEnumerable<dynamic>)sites.Locations.Location).Select(x => new | |
| { | |
| type = "Feature", | |
| geometry = new | |
| { | |
| type = "Point", | |
| coordinates = new double?[] | |
| { | |
| x.longitude, | |
| x.latitude, | |
| x.elevation | |
| } | |
| }, | |
| properties = new | |
| { | |
| x.id, | |
| x.name, | |
| x.region, | |
| x.unitaryAuthArea, | |
| nationalPark = x.GetType().GetProperty("nationalPark") != null ? x.nationalPark : null | |
| } | |
| })}; | |
| File.WriteAllText(@"c:\temp\metoffice.sitelist.geojson", JsonConvert.SerializeObject(features)); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment