Skip to content

Instantly share code, notes, and snippets.

@grenade
Last active January 30, 2024 11:00
Show Gist options
  • Save grenade/c61d4891ee4c879d1d31 to your computer and use it in GitHub Desktop.
Save grenade/c61d4891ee4c879d1d31 to your computer and use it in GitHub Desktop.
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));
}
}
}
}
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment