Re: [VG-Discuss] looking for postal code:federal ridings

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: [VG-Discuss] looking for postal code:federal ridings

Michael Mulley
This one gets asked a lot, so here's a slightly lengthy answer.

As Henry posted, your best option is Cory Horner's howdtheyvote.ca
API. It has a simple postal-code-to-MP call. I and lots of other
people have been relying on the service for a while; it's incredibly
useful.

However, even this service -- which Cory bought data for out of his
own pocket! -- is imperfect because of how expensive much of our
public data is. The data it uses represents postal codes as
"centroids" -- a single representative point for a given postal code.
The consequence of this is that it'll occasionally give you the wrong
answer, for example when a postal code contains addresses in different
ridings (it does happen!).

If you're really worried about accuracy, you can pay several thousand
dollars to Statscan for their data. Or you can go through the
following laborious procedure for each postal code (this assumes
you're getting postal codes from users on an interactive website):

1) Use Daniel Haran's postal code webservice at
http://postal-code-to-edid-webservice.heroku.com/ to get the ID of the
riding. This is a web service interface to a caching scraper of the
Elections Canada site. For problematic postal codes which don't
resolve cleanly to a riding, it'll return an error code.

2) If you get an error code, get a street address from the user,
resolve that address to coordinates using a geocoder, and submit those
coordinates to the howdtheyvote.ca API. I wrote some sample code for
this at vote.ca/api/ (using an alternate API).

This is complicated and painful. People are surprised at how
complicated and painful it is for developers to answer a simple
question like "who's my MP?". It would be far less painful, of course,
if certain public data -- the statscan postal-code-to-riding file,
geospatial data on postal codes -- were publically available. This
used to be the case in the UK -- see http://www.freethepostcode.org/
-- but their data has now been freed. Here's hoping that happens here
too.


On Mon, Feb 14, 2011 at 10:38 AM,  <[hidden email]> wrote:

> That's something that rings a bell from the last round of the copyfight.
> Russell McOrmond worked on it -- check it out at
> http://www.digital-copyright.ca/edid
>
> -----Original Message-----
> From: [hidden email] on behalf of wfrisch
> Sent: Sat 2/12/2011 2:50 PM
> To: VisibleGovernment Discuss
> Subject: [VG-Discuss] looking for postal code:federal ridings
>
> Looking for data mapping postal code to federal ridings.
>
> We are building a petition site with PHP and mySql.
>
> Any suggestion greatly appreciated
>
> --
> You received this message because you are subscribed to the Google Groups
> "VisibleGovernment Discuss" group.
> To post to this group, send email to
> [hidden email].
> To unsubscribe from this group, send email to
> [hidden email].
> For more options, visit this group at
> http://groups.google.com/group/visiblegovernment-discuss?hl=en.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "VisibleGovernment Discuss" group.
> To post to this group, send email to
> [hidden email].
> To unsubscribe from this group, send email to
> [hidden email].
> For more options, visit this group at
> http://groups.google.com/group/visiblegovernment-discuss?hl=en.
>

Reply | Threaded
Open this post in threaded view
|

Re: [VG-Discuss] looking for postal code:federal ridings

Kent Mewhort
If you're looking for a PHP alternative to Daniel's ruby code, you could also adapt the code from a Drupal petition module that I put together a few months back.  It scrapes directly from parl.gc.ca using PHP/CURL -- checkout the campaign_mplookup() function in https://github.com/kmewhort/Canadian-MP-Letter-Campaign/blob/master/campaign.module.  It's nothing too fancy, but it gets the job done....

Or, considering your building a petition module, you might be interested in the whole module; there's a running example here: http://www.digitalagenda.ca/billc32.

Kent

On Mon, Feb 14, 2011 at 11:06 PM, Michael Mulley <[hidden email]> wrote:
This one gets asked a lot, so here's a slightly lengthy answer.

As Henry posted, your best option is Cory Horner's howdtheyvote.ca
API. It has a simple postal-code-to-MP call. I and lots of other
people have been relying on the service for a while; it's incredibly
useful.

However, even this service -- which Cory bought data for out of his
own pocket! -- is imperfect because of how expensive much of our
public data is. The data it uses represents postal codes as
"centroids" -- a single representative point for a given postal code.
The consequence of this is that it'll occasionally give you the wrong
answer, for example when a postal code contains addresses in different
ridings (it does happen!).

If you're really worried about accuracy, you can pay several thousand
dollars to Statscan for their data. Or you can go through the
following laborious procedure for each postal code (this assumes
you're getting postal codes from users on an interactive website):

1) Use Daniel Haran's postal code webservice at
http://postal-code-to-edid-webservice.heroku.com/ to get the ID of the
riding. This is a web service interface to a caching scraper of the
Elections Canada site. For problematic postal codes which don't
resolve cleanly to a riding, it'll return an error code.

2) If you get an error code, get a street address from the user,
resolve that address to coordinates using a geocoder, and submit those
coordinates to the howdtheyvote.ca API. I wrote some sample code for
this at vote.ca/api/ (using an alternate API).

This is complicated and painful. People are surprised at how
complicated and painful it is for developers to answer a simple
question like "who's my MP?". It would be far less painful, of course,
if certain public data -- the statscan postal-code-to-riding file,
geospatial data on postal codes -- were publically available. This
used to be the case in the UK -- see http://www.freethepostcode.org/
-- but their data has now been freed. Here's hoping that happens here
too.


On Mon, Feb 14, 2011 at 10:38 AM,  <[hidden email]> wrote:
> That's something that rings a bell from the last round of the copyfight.
> Russell McOrmond worked on it -- check it out at
> http://www.digital-copyright.ca/edid
>
> -----Original Message-----
> From: [hidden email] on behalf of wfrisch
> Sent: Sat 2/12/2011 2:50 PM
> To: VisibleGovernment Discuss
> Subject: [VG-Discuss] looking for postal code:federal ridings
>
> Looking for data mapping postal code to federal ridings.
>
> We are building a petition site with PHP and mySql.
>
> Any suggestion greatly appreciated
>
> --
> You received this message because you are subscribed to the Google Groups
> "VisibleGovernment Discuss" group.
> To post to this group, send email to
> [hidden email].
> To unsubscribe from this group, send email to
> [hidden email].
> For more options, visit this group at
> http://groups.google.com/group/visiblegovernment-discuss?hl=en.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "VisibleGovernment Discuss" group.
> To post to this group, send email to
> [hidden email].
> To unsubscribe from this group, send email to
> [hidden email].
> For more options, visit this group at
> http://groups.google.com/group/visiblegovernment-discuss?hl=en.
>
_______________________________________________
CivicAccess-discuss mailing list
[hidden email]
http://lists.pwd.ca/mailman/listinfo/civicaccess-discuss