Showing posts with label UK. Show all posts
Showing posts with label UK. Show all posts

Tuesday, 9 March 2010

Find by Postcode: Some useful links

Whilst on my searches I found a heap of websites that allow you to use GIS/Geolocation/Gazetteer API with or without registration... and also some others:

http://www.nearby.org.uk/ - quite a lot of resources by Postcode... conversion to and between coordinates/coordinate systems ... downloadable bounding boxes that cover the World / UK and work in Google Earth...

http://openspace.ordnancesurvey.co.uk/openspace/ - "The OS OpenSpace API is free to access and lets developers create amazing web applications and online projects with Ordnance Survey maps." But it's not just for developers... visit and see what you can do...

http://en.wikipedia.org/wiki/Category:United_Kingdom_Parliamentary_constituencies - of course Wikipedia has so much information ... and helped sort the Wards between the Constituencies... and the Wards amongst the Local Authorities... There does not appear to be a relation between Constituency and Local Authority... except that a ward in a Constituency is in a local authority... but a ward in a neighbouring Local Authority might also be in that Constituency... the borders are set by theBoundary Commission for England (source Wikipedia).

http://www.election-maps.co.uk/index.jsp - This looks like the kind of website I should have looked at as I was starting... It allows you to search by postcode or by place / LA / Constituency... and shows the area covered on a map... you can highlight the boundaries on the map... get a lot of information by postcode... but it's not as open in terms of letting developers mash it up... There's a lot of information on each level of government and the different levels of constituency... under 'Useful Facts'

http://www.parliament.uk/ - This was referenced by the above under 'Useful Facts' ... this is one website that we had been using to find out information by postcode... this links us by postcode to the relevant Local Authority's website... Use the 'Find Your MP' search facility halfway down the page. I can email my MP from this page... or use a link on the left hand side to get a full list of MPs in their constituencies... very useful... (when it comes to filling out that part of the database...

http://mycouncil.direct.gov.uk/index.html - Connect to your Council ... Enter your postcode and select the service required...
Report Graffiti, report a pothole, find out about planning permission... and so on.

http://www.theyworkforyou.com/ - Keeping tabs on the UK's parliament and assemblies... Find out what the MPs are saying.... (some useful API here - requires registration and fair use)

http://www.direct.gov.uk/en/HomeAndCommunity/index.htm - The government's Home and Community website .. with links to masses of information and services ... Fire Safety, Housing, Buying Selling Renting a home, Getting Involved in Community, Planning Permission, reporting Flooding ... and more...

http://www.direct.gov.uk/en/index.htm - Find local services from this site - enter postcode on right hand side...

http://www.nhs.uk/servicedirectories/Pages/ServiceSearch.aspx - Find your local Health Services, Doctors Dentists and so on..

http://www.sitefinder.ofcom.org.uk/ - Find local Mobile phone masts by postcode or placename

http://www.environment-agency.gov.uk/homeandleisure/floods/31650.aspx - Check your risk of flooding ... enter your postcode on the right hand side....

http://directgov.transportdirect.info/Web2/Home.aspx - Travel between 2 points in the UK - by car / public transport / etc - calculate CO2 emissions for your journey.

Tuesday, 2 March 2010

UK Government ONS: NeSS Data Exchange (NDE)

Task 2: Fill in the Wards and Councils for the next Election (2010) into a Contact database - by each contact's postcode.

I've chosen to look at NeSS Data Exchange (NDE), a free web service with which you can run queries against the Neighbourhood Statistics from ONS.

With this service you can run queries from websites, Excel spreadsheets, databases, Ajax, Flex, Java, .NET applications... and there's a lot of statistics to discover. NDE2 can use both SOAP and REST (not strictly RESTful) protocols without authentication.

Example datasets:
  • "What are the child areas of Havant local authority?"
  • Search for Wards, Unitary Authorities by Postcode or AreaId
  • Get "Indexes of Deprivation" and filter by Unitary Authority
  • and various other indicators, statistics from local councils and UK government offices.
NDE2 no longer requires registration...

I found a good technical guide in PDF format. There are two service endpoints that you can visit and play with to discover what kind of information is available:

From the technical guide it appears that the datasets are split into Hierarchies and Level Types. For my purposes I need Level Types 13 (Electoral Ward) and 14 (Local Authority). I do not need to worry about Hierarchies... Out of interest tho .. running the Disco/GetHierarchies? command from the above Discovery endpoint returns:
2 NeSS Geography Hierarchy
15 2006 Health Hierarchy
4 2003 Administrative Hierarchy
8 2003 Health Hierarchy
11 2004 Administrative Hierarchy
16 2005 Administrative Hierarchy
18 2007 Administrative Hierarchy
3 1998 Administrative Hierarchy
7 2003 Electoral Hierarchy
12 New Deal for Communities (Best fit)
17 2006 Administrative Hierarchy
9 2003 Parish Hierarchy
14 Provisional Parliamentary Constituencies 2007
10 2003 Education Hierarchy
Disco/GetLevelTypes? returns (some removed):
164 COM Community
10 CTRY Country
180 EA Education Area
9 EW England and Wales
21 GAZ Gazetteer
8 GB Great Britain
11 GOR Government Office Region
19 HA Health Authority
13 LA Local Authority
141 LSOA Lower Layer Super Output Area
140 MSOA Middle Layer Super Output Area
201 NDC New Deal for Community
17 NP National Park
16 P Parish
20 PCO Primary Care Organisation
81 SHA Strategic Health Authority
144 SPR Scottish Parliamentary Region
153 USOA Upper Layer Super Output Area
14 WARD Ward
27 WPC Westminster Parliamentary Constituency (currently as they were in 2005)
Running Disco/SearchSByAByPostcode with a postcode and level type 13 or 14 returns the local authority (and ward). I.e.,
Returns: (Level Type) 13 (Hierarchy) 2 (AreaId) 276743 (Local Authority) City of London
Returns: (Level Type) 13 (Hierarchy) 2 (AreaId) 276743 (Local Authority) City of London
(Level Type) 14 (Hierarchy) 17 (AreaId) 6094725 (Ward) Aldersgate
I am able to run the response through ds.ReadXml ...
ds.ReadXml("http://neighbourhood.statistics.gov.uk/NDE2/Disco/SearchSByAByPostcode?LevelTypeId=14&Postcode=EC2Y8BP");
More than one table is created... Only one table has data and it is called Area... The number of rows depends on the LevelTypeId and LevelTypeId can be used as a row index to find the required data. (I discovered that Scottish Wards can't be found this way, only the Scottish Unitary Authorities (using LevelTypeId=13)... for that one needs to approach the equivalent Scottish Neighbourhood Statistics. That will have to be done at another stage.

Put that on a loop and now I have populated my contact database with the relevant Wards and Local Authorities...

There's plenty more to play with at the NeSS Data Exchange...

I'll follow this post with some useful links to postcode searches and Elections and government services etc...



Find by Postcode C#.NET: UK Parliamentary Constituencies

Task 1: Update a contact database and find the UK Parliamentary Constituencies (for the 2010 General Election) within which each contact's postcode falls.

This had been achieved before with a button on the form that opened a web page with the postcode in the URL... the user was expected to look for the information and then close the browser window and select the item from the list.

After some searching I found that the best API was from:

http://www.theyworkforyou.com/api/

You can register for an API Key from that address. This gives you access to a number of functions:

getConstituency: Searches for a Constituency by Postcode (current or future 2010)
getConsituencies: Returns a list of Constituencies
getPerson: Returns main details for a Person
getMP: Returns details for an MP
getMPInfo: Returns extra info on a person
getMPsInfo: Returns extra info on one or more people
getMPs: Returns a list of MPs (by postcode or constituency)
getLord: Returns main details for a Lord
getLords: Returns a list of Lords
getMLA: Returns main details for an MLA (Member of the Legislative Assembly (N Eire))
getMLAs: Returns a list of MLAs
getMSP: Returns main details for an MSP (Member of the Scottish Parliament)
getMSPs: Returns list of MSPs
getGeometry: Returns centre and bounding box of constituencies
getCommittee: Returns members of Select Committee
getDebates: Returns Debates (Commons, Westminster, Lords)
getWrans: Returns Written Answers
getWMS: Returns Written Ministerial Statements
getHansard: Returns any of the above
getComments: Returns comments

Here we need getConstituency only...

So I build a simple C#.NET program... add a datagrid... and show my data... to which i've added a new field to take the new constituency name. The following link is to the function's description page. The code is quick and dirty... GTD coding... a single pass, get what it can, and then it's done... you could put a Try..Catch around the ReadXML code... no errors occurred at all... so once the data's downloaded, on to the next phase.


private void goButton_Click(object sender, EventArgs e)
{
if (!(this.contactsDGView.CurrentRow == null))
{
string postcode =
this.contactsDGView.CurrentRow.Cells["Postcode"].Value.ToString();
postcode = postcode.Trim().Replace(" ", "+");
DataSet ds = new DataSet();
ds.ReadXml("http://www.theyworkforyou.com/api/getConstituency?" +
"key=<INSERT-API-KEY-HERE>&postcode=" + postcode +
"&future=1&output=xml");
if (ds.Tables[0].Columns.Contains("error")) { return; }
else
{
this.contactsDGView.CurrentRow.Cells["PConstituency"].Value =
ds.Tables[0].Rows[0]["name"].ToString();
}

}
}

[The update of the table in the DataGrid is done elsewhere.]

It took a few minutes to fill in all the constituencies... of course not all postcodes were valid... so they took a while to fix...

TheyWorkForYou.com have a fair-use policy... and the usage has to be declared when applying for an API... I have just discovered the UK eGov site for Office of National Statistics has a free data exchange program and I might be able to get this data from there instead...

I will have to go there for Wards and Councils...