Showing posts with label Constituencies. Show all posts
Showing posts with label Constituencies. 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

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...